For Loop gets ignored

Hello,
I have this for loop. K is a table containing times in its first column and BC is a vector with zeros and ones.
I want a new Vector B1 to be created, every time that BC is one. In the vector, I want the corresponding value of the first column in K. I know something in my table must be missing, but I dont get an error message, my loop just gets ignored. Whats going on?
Thank you for your help!

4 comentarios

Dyuman Joshi
Dyuman Joshi el 4 de Nov. de 2021
There is a syntax error in your for loop definition. Why are you writing it as 24(K) or 1(K)?
Rik
Rik el 4 de Nov. de 2021
This looks like you would benefit from doing a basic Matlab tutorial, like the Onramp tutorial.
Noush
Noush el 4 de Nov. de 2021
@Dyuman Joshi because I would like to refer to my table, K. I have another loop that works like that:
Is there a better way to do that?
Rik
Rik el 4 de Nov. de 2021
I don't know why this even works, but this
for m=2:4(K)
is equivalent to this:
for m=2:4
(K)
So this is probably not doing what you think it's doing.
You are also ignoring all the mlint warnings. You should make sure there aren't any in your final code.
You are also using size without a second input argument, meaning it will return a vector. What do you think this line does?
for l=1:[5 3]
Are you sure without trying which values your variable l will have?

Iniciar sesión para comentar.

Respuestas (2)

Voss
Voss el 17 de Dic. de 2021

0 votos

Maybe this?
B1 = [];
for l = 1:size(K,1)
if BC(l) == 1
B1(end+1) = K{l,1};
end
end

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 4 de Nov. de 2021

Respondida:

el 17 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by