I have a 4x1 cell array containing string identifiers, and a 4x5 cell array containing 5 data points for each of these entities over time...
>> ids = { '1'; '2'; 'A'; '4' }
ids =
'1'
'2'
'A'
'4'
>> vals = { 11, 12, 13, 14, 15; 21, 22, 23, 24, 25; 31, 32, 33, 34, 35;, 41, 42, 43, 44, 45}
vals =
[11] [12] [13] [14] [15]
[21] [22] [23] [24] [25]
[31] [32] [33] [34] [35]
[41] [42] [43] [44] [45]
I want to convert IDs to numbers and strip out data in both cell arrays for non-numeric IDs, leaving:
ids =
[1]
[2]
[4]
vals =
[11] [12] [13] [14] [15]
[21] [22] [23] [24] [25]
[41] [42] [43] [44] [45]
I am wondering if the key to this is working out which indexes are empty and then addressing both cell arrays with these indexes, but I'm not sure where to go after this...
>> numericIds = cellfun(@str2num, ids, 'un', 0)
numericIds =
[1]
[2]
[]
[4]
>> emptyIdx = cellfun(@isempty, numericIds, 'un', 0)
emptyIdx =
[0]
[0]
[1]
[0]
>> ids(emptyIdx) = []
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
'uni' 0flag while gettingemptyIdx. I think your problem is thatemptyIdxis a cell array which is not going well with indexing.