필터 지우기
필터 지우기

How to store matrix whose dimension is changing in each iteration ?

조회 수: 1 (최근 30일)
Manoj Kumar
Manoj Kumar 2019년 5월 24일
편집: KALYAN ACHARJYA 2019년 5월 28일
hello all
How to store matrix whose dimension is changing in each iteration?
can anyone expalin with example?

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 24일
편집: KALYAN ACHARJYA 2019년 5월 24일
Cell array
result=cell(1,iter);
for i=1:iter
%say matrix1 have changes the dimention in each iteration
% do operation, say matrix1 is the result in this iteraion.
result{i}=matrix1
end
Exampele:
>> A=rand(2,4)
A =
0.9324 0.2304 0.8681 0.9226
0.2963 0.1660 0.2219 0.9020
>> B=magic(3)
B =
8 1 6
3 5 7
4 9 2
>> result={A,B}
result =
1×2 cell array
{2×4 double} {3×3 double}
>>
  댓글 수: 3
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 28일
편집: KALYAN ACHARJYA 2019년 5월 28일
Where is the issue, can you share?
As per your question>>
How to store matrix whose dimension is changing in each iteration ?
Best way Celll Array (Alreadt shown the example too)
>> A=rand(2,4)
A =
0.9324 0.2304 0.8681 0.9226
0.2963 0.1660 0.2219 0.9020
>> B=magic(3)
B =
8 1 6
3 5 7
4 9 2
>> result={A,B}
result =
1×2 cell array
{2×4 double} {3×3 double}
>>
Here we have saved the two matrix having sizes 2x4 and 3x3 in result cell array.

댓글을 달려면 로그인하십시오.


Raj
Raj 2019년 5월 24일
편집: Raj 2019년 5월 24일
Use cell array
for i = 1:10
A = rand(i,i) % A size is changing with every iteration
B{i} = A; % Store A as cell
end
Required_matrix=cell2mat(B(1,10)) % Suppose I want to extract the 10th iteration matrix
  댓글 수: 1
Manoj Kumar
Manoj Kumar 2019년 5월 28일
its working direcctly, but If we get A return from functioion then how wil to strore it.
e.g. [A, B] = function1(arg1, arg2).
Actually I trying to fix this issue.

댓글을 달려면 로그인하십시오.

카테고리

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