addressing a cell array

3 vues (au cours des 30 derniers jours)
hiva
hiva le 6 Mai 2016
Commenté : hiva le 6 Mai 2016
i have a cell array like this: < 328,2 > cell named : fastaStrs all i want is to access all rows of the second column of this array. when i type "fastaStrs{:,2}" in command window, each row of the second column of my array is returned seperately. like this: ans: first row of the second column ans: second row of the second column... and so forth. but when i try to use the same syntax in my code,( i am trying to extract the cells containing numeric data from the second column) it doesn't work. ind = find(cellfun(@isnumeric,fastaStrs{:,2}) == 1); returns me this error: cellfun Input #2 expected to be a cell array, was char instead.
any body knows what i am doing wrong?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 6 Mai 2016
Modifié(e) : Azzi Abdelmalek le 6 Mai 2016
s={1 'rt';2 'er';3 'tr';4 5 ;8 'zz';9 1}
a=s(:,2)
idx=cellfun(@(x) isequal(1,x),a)
  5 commentaires
hiva
hiva le 6 Mai 2016
thanks, it worked. really thanks..
CS Researcher
CS Researcher le 6 Mai 2016
If it helped, please accept his answer. It will help others too!

Connectez-vous pour commenter.

Plus de réponses (1)

CS Researcher
CS Researcher le 6 Mai 2016
How about this:
a = cell2mat(fastaStrs);
b = a(:,2);
  3 commentaires
CS Researcher
CS Researcher le 6 Mai 2016
Oh I assumed the entire cell array is of the same type. Can you share the cellarray?
hiva
hiva le 6 Mai 2016
no it is a mixture of double and char types. but it is solved by Mr Azzi's solution: fastaStrs(:,2) thanks a lot for your caring.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by