I have a cell array in MATLAB that's behaving quite strangely. I have 104 single row vectors I've stored as cells, ranging from 80 to 344 elements. As a result, I have a 104 x 344 cell array, called z. Each element has a single numeric value in it. I'm trying to find the position of all the cells in this array which lie between certain values, say 524 and 528. To do this, I've used the following;
index = find([z{:}] >= 524 & [zp{:}] <= 528 )
This returns a list of index positions, which initially seems reasonable, but curiously, when I evaluate them I get some very odd behaviour; I try
z{index}
and it spits out a number of values at these positions - but not all of them are between 524 and 528; some are significantly above or below these values. Others still return [], the 0 x 0 array. Perhaps I'm using find wrong for such a tricky cell array, but the behaviour certainly isn't what I expected. Any ideas?
You cannot use indices computed from the array [z{:}] on z if it contains empty values. When you do [z{:}] empty values are removed. You need to save [z{:}] in another variable and index into it.
y = [z{:}];
index = find(y >= 524 & y <= 528 )
y(index)