If I have a matrix that is 27 by 12, there are some elements that are empty. like so, [ ]
I am trying to replace whatever elements are [ ] to -1.
What is the best way to do this?
If I have a matrix that is 27 by 12, there are some elements that are empty. like so, [ ]
I am trying to replace whatever elements are [ ] to -1.
What is the best way to do this?
I assume that you are talking about a cell array.
In this case, the easiest would be:
%# create some sample data
C = {1,2,[];3,[],99};
%# replace empty elements with -1
[C{cellfun(@isempty,C)}] = deal(-1);
%# or, simpler (thanks @EitanT)
C(cellfun(@isempty,C)) = {-1};
%# just in case you want to turn C into a numeric array
numericC = cell2mat(C);