I want to add this cell variable 'condition_col' to existing matrix 'data' if certain conditions are met, following code doesn't work, any help?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Bubblesjinx
el 4 de Ag. de 2019
Comentada: Guillaume
el 5 de Ag. de 2019
condition_col = 'codition1'
condition_col = cellstr(condition_col);
data = num2cell(data);
for i = 1:length(data)
if strcmpi(data(i,5),1) && data(i,6)> 5 && strcmpi(data(i,5), 2) && data(i,6) < 5
data{i} = [data, condition_col];
end
end
3 comentarios
Guillaume
el 4 de Ag. de 2019
following code doesn't work, any help
The code makes no sense at all and there's no comment explaining what it's meant to do.
Can you explain with examples using valid matlab syntax what it is you want to do?
Respuesta aceptada
newbie9
el 4 de Ag. de 2019
See if this helps to get you on the right track:
% set up dummy data to work with
data = rand(20,1);
data = array2table(data);
data.Properties.VariableNames = {'MyColumnName'};
for ii = 1 : height(data)
% example condition, use your condition instead
if data.MyColumnName(ii) < 0.5
data.codition1{ii} = 'Condition Met';
else
data.codition1{ii} = '';
end
end
4 comentarios
newbie9
el 5 de Ag. de 2019
Thanks Guillaume, that is a much better approach. Maybe you should write it up as a separate answer so the OP can accept it as the correct answer.
Guillaume
el 5 de Ag. de 2019
I'm fine with you getting the credit. You understood what the OP was asking for and got him in the right direction.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!