MATLAB: Need help related to if condition for character cell data.

character cellif statement

hi i need to do this for a cell of 1*1. when label has 'R' it gives a=1 but when label='N' it gives error like this Cell contents reference from a non-cell array object. please help
if strcmp(label{1},'R')
a=1;
elseif strcmp(label{1},'N')
b=1;
else
c=1;
end

Best Answer

If "label='N'" then you don't need cell array indexing:

strcmp(label,'R')

You should revise the basic data types in MATLAB (e.g. cell array, char arrays):

https://www.mathworks.com/help/matlab/data-types_data-types.html