How can I use squeeze to extract a 2D matrix with each point (x,y) having 3 items a,b,c?

1 回表示 (過去 30 日間)
Hello everyone, I need your assistance regard using squeeze to extract 2D matrix data. I will like to extract individually the value of w=1,2,3 OR at least all w together. Will really appreciate your assistance. Something like:
for v = 1:v_final
for m = 1:m_final
for k = 1:3
w1=myval{v,m}(:,:,1);
w2=myval{v,m}(:,:,2);
w3=myval{v,m}(:,:,3);
end
end
end

採用された回答

Matt J
Matt J 2016 年 4 月 24 日
編集済み: Matt J 2016 年 4 月 24 日
I'm not sure why squeeze() would be involved and, since you already have a posted solution, I'm not sure what's different between that and what you're actually looking for. However, if all arrays myval{v,m} are the same size MxNx3, I would consolidate them into a 5-D array.
W=cat(4, myval{:});
W=reshape(W,[M,N,3, v_final, m_final];
W=permute(W,[4,5,3,1,2]);
In this form, one can lookup complete arrays of size v_final x m_final or of size v_final x m_final x 3 by doing things like;
w1=W(:,:,1,x,y);
w2=W(:,:,2,x,y);
w3=W(:,:,3,x,y);
wij=W(:,:,1:3,x,y);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by