saving multiple output of each iteration of for loop
조회 수: 6 (최근 30일)
이전 댓글 표시
I am writing a for loop and each iteration has one column and lets say m rows. How to save the output of all iterations in a single column vector.
Thanks for your help.
my code is something like that:
a = 1000*4 double
b = 1500*1
for i = size(b)
x = find(a(:,4))==b(i)
end
댓글 수: 0
채택된 답변
Matt J
2018년 7월 17일
편집: Matt J
2018년 7월 17일
You wouldn't want x to be a (numeric) column vector, because find() may not return a scalar. A numeric vector x can only put scalars into each x(i). However, a cell array is a possibility:
N=numel(b);
x=cell(N,1);
for i = 1:N %Edited typo
x{i} = find( a(:,4) == b(i) );
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!