how to have a loop if for a column in a table
Show older comments
I have a table with many columns... I want to iterate into one column, that have many numbers valores. is there someone that can help me?
the pseudocode is
if table.column > number
table.new_column= 'Ok'
else
table.this_new column='nok'
finally i wil have a new columns with ok and nok depending of the valor of the column
Accepted Answer
More Answers (1)
Peter Perkins
on 14 May 2018
Ameer's solution works, but arrayfun is really not needed:
words = {'nok', 'ok'};
table.newColumn = words(table.column>number)+1);
But also, a cell array of 'ok' and 'nok' is likely not all the helpful. I'd suggest making a categorical variable:
table.newColumn = categorical(table.column>number,[false,true],{'nok' 'ok});
Like Ameer, I'm not able to fully understand the followup question.
2 Comments
Jessica Blasco
on 15 May 2018
Peter Perkins
on 17 May 2018
I can't follow this. I suggest you open a new thread, with a short, clear example of what you have and what you want.
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!