saving multiple output of each iteration of for loop

1 vue (au cours des 30 derniers jours)
Sara
Sara le 17 Juil 2018
Modifié(e) : Matt J le 17 Juil 2018
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

Réponse acceptée

Matt J
Matt J le 17 Juil 2018
Modifié(e) : Matt J le 17 Juil 2018
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
  2 commentaires
Dennis
Dennis le 17 Juil 2018
I like the solution, but i think it has a small typo:
for i= 1:N
Sara
Sara le 17 Juil 2018
Dear Matt,
Thanks for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by