필터 지우기
필터 지우기

Saving and manipulating iterating matrices.

조회 수: 2 (최근 30일)
Zaharaddeen Hussaini
Zaharaddeen Hussaini 2018년 7월 15일
답변: Zaharaddeen Hussaini 2018년 7월 15일
Hello,
I am trying to store varying matrices in a variable.
I understand I can use cell array to store but cell array manipulations are not so straight forward and I have a lot manipulations that need to be done on the save x nested variable.For example:
count = 0
for i = 1:5
for j = 1:3
for k = 1:2
A = rand(5:5);
count = count+1;
B{count} = A;
s{count} = sum(sum(B{count}));
end
end
end
%
% if s{:} >10
% fprintf('Hello');
% end
So basically I know the commented section would not run. is there a way deconstruct the cell arrays and use all the contents as matrix?
Also, if use
...B(i,j) = A;
I can eliminate the problem. But I am trying to avoid that as well as I have a lot of nested loops involved. If I choose to use B(i,j..), the any suggestions on how deal with it more efficiently?
Thanks. Apologies if it is not clear. copying excerpts from the main code would be difficult as many functions and loops are there hence the example.

채택된 답변

Stephen23
Stephen23 2018년 7월 15일
편집: Stephen23 2018년 7월 15일
You either need to use a loop (explicitly or implicitly using cellfun) or covert the cell array to a numerc array (which is easy using a comma-separated list), e.g. something like this:
if any([s{:}]>10)

추가 답변 (1개)

Zaharaddeen Hussaini
Zaharaddeen Hussaini 2018년 7월 15일
Thanks will try that right away!

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by