Is it possible in matlab to check if a value is empty and if it is empty assign a value, else (if it is not empty) increment the value during an assignment ?
For example:
In this code I increment majorityList{l}, though at the start this cell is empty (not 0), therefore i can’t increment it. This means I need to check this first before I can increment it. Can this be done during the assignment itself ?
majorityList{l,2} = 'test';
majorityList{l}= majorityList{l}+1;
A solution I wrote is:
if length(majorityList{l})==0
majorityList{l} = 0;
majorityList{l} = majorityList{l} +1;
else
majorityList{l} = majorityList{l} +1;
end
though this looks rather ugly for something so easy…
Use
isemptyfor thatIf on the other hand you do not know, if the variable exists at all, use
exist.