how to save result of for loop

조회 수: 1 (최근 30일)
muhammad ismat
muhammad ismat 2016년 4월 21일
댓글: muhammad ismat 2016년 4월 22일
if i have the function
[label,s] = LSC(data,k,opts)
for p =1:100;
r = 3;
.
.
[label,s] = kmedo(U',k);
end
end
if the output s is a matrix n x n every time (where n is the size of data) so how to save all results(s)

답변 (1개)

Wayne King
Wayne King 2016년 4월 21일
편집: Wayne King 2016년 4월 21일
Outside the loop allocate a 3D matrix of zeros
Smat = zeros(n,n,p); % p here is the upper bound on the for loop
Then inside the loop assign
Smat(:,:,p) = s;
have your function return Smat.
  댓글 수: 3
Wayne King
Wayne King 2016년 4월 22일
because your function is returning, s, look at your function definition
[label,s] = LSC(...)
In my original answer, I stated "have your function return Smat"
muhammad ismat
muhammad ismat 2016년 4월 22일
what is the meaning of 77 x 77 x 10 (n x n x p) and if i want to use s (77 x 77 ) only without 10 to able to run my code of another function

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by