Borrar filtros
Borrar filtros

Creating a new variable in a Table with classifiers of 1 or 0

16 visualizaciones (últimos 30 días)
Isabelle Museck
Isabelle Museck el 2 de Abr. de 2024 a las 0:26
Respondida: Cris LaPierre el 2 de Abr. de 2024 a las 0:36
Hi there I am trying to add a new variable in a table that classifies each row with a 0 or a 1 based on the if the another one of the variables (velocity) is zero. Here is what I have so far but its not working correcly and does not ass a new row to the table.
for n =1:height(Table)
if Table(n,velocity)>0.1
Table(n,velocity) = 1
else
Table(n,velocity) = 0
end
end

Respuestas (1)

Cris LaPierre
Cris LaPierre el 2 de Abr. de 2024 a las 0:36
My answer assumes Table is the name of your table variable.
Currenlty, your code is assigning the value to the velocity variable, not a new variable. Since you haven't specifed what the new variable name should be, I'm using 'moving'.
I'd do this all at once using a logical operation.
Table.moving = Table.velocity>0.1

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by