Adding columns in a cell

2 ビュー (過去 30 日間)
KK14
KK14 2019 年 6 月 10 日
編集済み: Adam Danz 2019 年 6 月 12 日
I have a cell which is 100*4100. I need to take first 100 columns as a matrix and the next 100 columns as the 2nd matrix and find average between them. Please help me out.
Thank you
  1 件のコメント
madhan ravi
madhan ravi 2019 年 6 月 10 日
"... find average between them"
What do you mean by that?

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

採用された回答

James Browne
James Browne 2019 年 6 月 12 日
Greetings,
I believe I understand what you are looking for so I wrote a script which I think will solve your problem. All you should need to do is put your data object in the variable A, instead of the matrix of all 1s that I used to test out the script while I was writing it.
%Sreate sample data matrix of all ones
A = ones(100,4100);
%Create matrices of 100 columns from sample data
B = A(:,1:100);
C = A(:,101:200);
%Preallocate memory for storing the averaged results
D = zeros(100,100);
for i = 1:100
for j = 1:100
D(i,j) = (B(i,j) + C(i,j))/2;
end
end
  2 件のコメント
madhan ravi
madhan ravi 2019 年 6 月 12 日
編集済み: madhan ravi 2019 年 6 月 12 日
Why do you need a loop? It’s simply:
(B + C) / 2
Adam Danz
Adam Danz 2019 年 6 月 12 日
編集済み: Adam Danz 2019 年 6 月 12 日
If this is the correct interpretation of the question (which seems likely), you'll need to extract the matrices from the cell array first.
c = num2cell(rand(100,4100)); %fake data that fits OP's description
D = (cell2mat(c(:,1:100)) + cell2mat(c(:,101:200))) ./2;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by