I need a loop which puts every (j,k) element of every matrix in different columns.

2 ビュー (過去 30 日間)
Sain Cloud
Sain Cloud 2019 年 4 月 10 日
コメント済み: Sain Cloud 2019 年 4 月 10 日
a = [1 2 ;3 4]; % This are my matrices
b = [5 6 ;7 8]
% I need a loop which puts every (j,k) element-
% of every matrix in different columns. It means i have 4 colums-
% and each have 2 rows . Finaly it should look
% like this:
[1;5] ,[3;7], [2;6], [4;8]
PS. : It has to be an loop.
Thanks very much!
  3 件のコメント
Rik
Rik 2019 年 4 月 10 日
Why does it have to be a loop? Is this homework?
Sain Cloud
Sain Cloud 2019 年 4 月 10 日
編集済み: dpb 2019 年 4 月 10 日
Yeah it's one of my university projects...
I've simplified the Problem.. There are actually much more matrices and each matrix represents an image with pixels.
and this ist what i tried so far:
a = [1 2 ;3 4];
b = [5 6 ;7 8];
v=zeros(2,4);
o = {a,b}
for i= 1:2
for j=1:2
for k=1:2
v(j,k) = o{1,i}(j,k) % I thing the problem is here..
end
end
end

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

採用された回答

Jan
Jan 2019 年 4 月 10 日
What about:
d = cat(3, O{:});
d = permute(d, [3,1,2])
Now you have the wanted columns as first index.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by