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?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일
편집: Azzi Abdelmalek 2016년 5월 6일

0 개 추천

s={1 'rt';2 'er';3 'tr';4 5 ;8 'zz';9 1}
a=s(:,2)
idx=cellfun(@(x) isequal(1,x),a)

댓글 수: 5

hiva
hiva 2016년 5월 6일
it creates a char array of my cell array.and the error that appears is the same as before.
if your data are char, then use
fastaStrs(:,2)
Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 6일
편집: Azzi Abdelmalek 2016년 5월 6일
Look at edited answer
hiva
hiva 2016년 5월 6일
thanks, it worked. really thanks..
CS Researcher
CS Researcher 2016년 5월 6일
If it helped, please accept his answer. It will help others too!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

CS Researcher
CS Researcher 2016년 5월 6일

0 개 추천

How about this:
a = cell2mat(fastaStrs);
b = a(:,2);

댓글 수: 3

hiva
hiva 2016년 5월 6일
the error after using your solution: "All contents of the input cell array must be of the same data type."
CS Researcher
CS Researcher 2016년 5월 6일
Oh I assumed the entire cell array is of the same type. Can you share the cellarray?
hiva
hiva 2016년 5월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2016년 5월 6일

댓글:

2016년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by