MATLAB Answers

how to save result of for loop

조회 수: 5(최근 30일)
muhammad ismat
muhammad ismat 21 Apr 2016
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)

  댓글 수: 0

로그인 to comment.

답변 수 (1)

Wayne King
Wayne King 21 Apr 2016
Wayne King 님이 편집함. 21 Apr 2016
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

muhammad ismat
muhammad ismat 22 Apr 2016
[label,s] = LSC(data,k,opts)
n=size(data,1);
Smat = zeros(n,n,9);
for p =2:10;
r = 3;
.
.
[label,s] = kmedo(U',k);
Smat(:,:,p) = s;
end
end
i do previous code but it return one value for s(output)
Wayne King
Wayne King 22 Apr 2016
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 22 Apr 2016
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

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by