0

I have bellow output of my cellarray.

 a = {'100.000000', '23.860477', '23.924062', '41.759920', '46.911883', '48.074160'};

I want to filter this array using cellfun function with condition if value is greater then 75 will stay and rest will stripped

sco1
  • 12,154
  • 5
  • 26
  • 48
AmitTank
  • 115
  • 1
  • 1
  • 8
  • Have you tried anything? If so please show us so we can help you better than by giving you the code. thanks! – Benoit_11 Dec 01 '15 at 12:09
  • Yes I tried below code: a= cellfun(@(x)(x>=75),a); but following array occured Error using cellfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false. I have also check classtype of my a varialble and its says 'cell' – AmitTank Dec 01 '15 at 12:21
  • Do you need the contents of your cell to remain strings or can they be converted to a numeric data type? – sco1 Dec 01 '15 at 12:27
  • Yes no need its remain strings.... can be converted to numeric data type... – AmitTank Dec 01 '15 at 12:38
  • 1
    I would recommend using [`str2double`](http://www.mathworks.com/help/matlab/ref/str2double.html) and then using [Amro's answer to this similar question](http://stackoverflow.com/a/21126338/2748311) – sco1 Dec 01 '15 at 12:55

1 Answers1

2

This is really quite trivial, but I did not find duplicate that gives a really strait-forward answer, so I might just write it here.

Indexes = find(arrayfun(@(idx) str2double(YourCell{idx}) > 75, 1:size(YourCell,2)));

Or I think it might be easier + faster to do:

T = str2double(YourCell);
Indexes = find(T > 75);

The Indexes should allow you to create a matrix or cell using the vertcat or horzcat to create the new cell/matrix you want.

YourCell = {'1' '2' '3' '56' '76' '87'}

Indexes =

 5     6
GameOfThrows
  • 4,510
  • 2
  • 27
  • 44
  • @excaza True, I made a mistake as I did not have Matlab application by my side, I just answered and forgot. There was another error with size(YourCell,1) which I have fixed. – GameOfThrows Dec 01 '15 at 13:44