s is a cell matrix (178000x9) I want to find the unique values of s in the first column. ID=unique(s(:,1));
I received the following error. Error using cell/unique (line 95) Input A must be a cell array of string
what could be the reason?

댓글 수: 1

If the first column is all non-numeric it would not be throwing that error. What is returned from:
iscellstr(s(:,1))

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

 채택된 답변

Mike Hosea
Mike Hosea 2012년 7월 26일
편집: Mike Hosea 2012년 7월 26일

0 개 추천

What type of data is in the cell array? When you use UNIQUE on a cell array, the only case that's supported is when the elements of the cell array are strings. Is that case not working for you?
>> c = {'abc','abc','def','defg'}';
>> unique(c(:,1))
ans =
'abc'
'def'
'defg'

댓글 수: 7

Danielle Leblanc
Danielle Leblanc 2012년 7월 26일
no . I am receiving an error Error using cell/unique (line 95) Input A must be a cell array of string
Mike Hosea
Mike Hosea 2012년 7월 26일
Do you have [] entries? Make sure that any empty entries are '', not [].
Danielle Leblanc
Danielle Leblanc 2012년 7월 26일
how can I tell if I have []. visually I can't because it take too long to load and I have too many observations
Sean de Wolski
Sean de Wolski 2012년 7월 26일
You can use iscellstr as I did above.
Danielle Leblanc
Danielle Leblanc 2012년 7월 26일
편집: Danielle Leblanc 2012년 7월 26일
iscellstr(s(:,1))
ans =
0
Yes, this is what we expected. You do not have a cell array of only strings. You can find the non-strings with
find(cellfun(@(x)~ischar(x),s))
You do not mention where this data came from. If it began as a
s = cell(m,n);
and was later partially populated, then you might resolve the problem by changing that to
s = repmat({''},m,n);
Danielle Leblanc
Danielle Leblanc 2012년 7월 26일
Thanks this solved the problem

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

추가 답변 (1개)

Wayne King
Wayne King 2012년 7월 26일
편집: Wayne King 2012년 7월 26일

1 개 추천

Is it a cell array of numeric values?
You can use cell2mat()
A = {1 5 9 ; 2 3 4; 2 4 5};
B = unique(cell2mat(A(:,1)));

댓글 수: 1

Danielle Leblanc
Danielle Leblanc 2012년 7월 26일
column 1 contains names . it is non-numeric

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

카테고리

도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by