matching with data in cell array
이전 댓글 표시
i want to match the output with data in cell array, i want to check whether the number(output) lies in cellarray or not?
댓글 수: 3
Andrei Bobrov
2017년 6월 1일
Please attach small example with your data as mat - file.
Jan
2017년 6월 1일
@Rya: Andrei asked for a small example. You have posted your complete code with images, documentation, logos, auto-save files, several fig and m-files. What do you expect? That we inspect all of this code only to answer this simple question? The screenshot of the GUI is not useful here also.
You asked for "number(output) lies in cellarray". Then please provide how the number is represented and the typical contents or the cell array. Any further information is a waste of time only.
Rya
2017년 6월 1일
답변 (2개)
ES
2017년 6월 1일
[truefalse, index] = ismember('abc', {'xyz', 'abc', 'def', 'abc'})
This one?
댓글 수: 12
Rya
2017년 6월 1일
편집: Walter Roberson
2017년 7월 10일
ES
2017년 6월 2일
just load your mat file.
load
Stephen23
2017년 6월 3일
It works for me, there should be no problem using this in an if statement:
>> load ANPR
>> ismember('EK94P8',ANPR(:,2))
ans =
1
Rya
2017년 6월 3일
@Rya: if you do not know what indexing is then you really really really need to do the introductory tutorials, which teach very basic and important MATLAB concepts (such as what indexing is):
Also this:
ANPR(:,2)
takes the second column of ANPR
Rya
2017년 6월 3일
Stephen23
2017년 6월 4일
nnz(ismember('EK94P8',ANPR(:,2)))
Rya
2017년 6월 4일
Walter Roberson
2017년 7월 10일
Note that you had
ANPR=['AED632' 'KPT295' 'AKH343' 'AFR420']; %cellarray
That does not create a cell array. You needed
ANPR={'AED632' 'KPT295' 'AKH343' 'AFR420'}; %cellarray
Walter Roberson
2017년 7월 10일
The suggested
nnz(ismember('EK94P8',ANPR(:,2)))
should be
nnz(ismember(ANPR(:,2), 'EK94P8'))
When you use ismember(A, B) then for each entry in A, a logical value (true or false) will be returned indicating whether that entry in A was found in B. So if you reverse the order like I show, then for each entry in your second column of ANPR, you are comparing it to the one value 'EK94P8', returning a logical value for each. The number of matches is the same as the number of places the logical value is true, which is the same as the number of places the logical value is non-zero. The number of places that a value is non-zero can be tested with nnz()
Jan
2017년 6월 1일
found = any(strcmp(TheNumber, TheListOfNumbers))
댓글 수: 5
Rya
2017년 6월 1일
@Rya: No, this is not a cell array. The comment is misleading:
ANPR=['AED632' 'KPT295' 'AKH343' 'AFR420']; %cellarray
You need curly braces instead of square brackets:
ANPR = {'AED632' 'KPT295' 'AKH343' 'AFR420'};
For searching a single string, strcmp is more efficient than ismember, which is thought to compare lists of strings.
Rya
2017년 6월 3일
Rya
2017년 6월 3일
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!