# Sum 2 Matrices and take the average value of their summation and store them in another Matrix with the same dimension.

1 ビュー (過去 30 日間)
Matthew Worker 2021 年 12 月 15 日
コメント済み: Rena Berman 2021 年 12 月 16 日
% in this code, I import 2 text files, C_Total_1 and C_Total_2. I want to take the average of the sum of these two variables, then store the new value in C_Total_up. What I should change in this code.
clc;
clear;
N = (6:10).^2; %Number of Elements IRS
K = 6:10; %Number of Single Antennas UE
C_Total_1 = importdata('C_Total_1.txt') ; % Total Capacity
C_Total_2 = importdata('C_Total_2.txt') ; % Total Capacity
P = 'C:\Users\tripo\Documents\Total_Active_up_Capacity\ART';
Total_File = [1,2];
Total_Capacity_File = numel(Total_File);
C_Total = cell(1,Total_Capacity_File);
for i = 1:Total_Capacity_File
F_Total = sprintf('C_Total_%d.txt',Total_File(i));
C_Total{i} = importdata(fullfile(P,F_Total));
end
C_Total_up = vertcat(C_Total{:});
##### 2 件のコメント表示非表示 1 件の古いコメント
Rena Berman 2021 年 12 月 16 日

サインインしてコメントする。

### 採用された回答

Jan 2021 年 12 月 15 日

"I want to take the average of the sum of these two variables, then store the new value in C_Total_up"
C_Total_up = (C_Total_1 + C_Total_2) / 2
And if you have multiple data sets stored in a cell:
C_Total_up = sum(cat(3, C_Total{:}), 3) / numel(C_Total);
% Or:
C_Total_up = mean(cat(3, C_Total{:}), 3);

サインインしてコメントする。

### カテゴリ

Find more on Matrix Indexing in Help Center and File Exchange

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.50537884,"math_prob":0.9496525,"size":1533,"snap":"2023-14-2023-23","text_gpt3_token_len":523,"char_repetition_ratio":0.15892741,"word_repetition_ratio":0.14754099,"special_character_ratio":0.32681018,"punctuation_ratio":0.15737705,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9959763,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-20T13:21:33Z\",\"WARC-Record-ID\":\"<urn:uuid:c2c9bc58-a114-4573-a1d9-4e9355c6ea63>\",\"Content-Length\":\"138417\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b7cdd489-6cd0-4ca0-bd3e-205326c26799>\",\"WARC-Concurrent-To\":\"<urn:uuid:bf7f78f4-f45e-4acb-9f6c-a02496593d8b>\",\"WARC-IP-Address\":\"23.218.145.211\",\"WARC-Target-URI\":\"https://jp.mathworks.com/matlabcentral/answers/1611340-sum-2-matrices-and-take-the-average-value-of-their-summation-and-store-them-in-another-matrix-with-t\",\"WARC-Payload-Digest\":\"sha1:2WJRV53Q3S55QDF5I6BMLDLPXHPFVF2Y\",\"WARC-Block-Digest\":\"sha1:ZGYV6C3FNN72GSQGKJ2QEK4WY2HEW6HV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296943483.86_warc_CC-MAIN-20230320114206-20230320144206-00275.warc.gz\"}"}