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!