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
Andrei Bobrov 2017 年 6 月 1 日
Please attach small example with your data as mat - file.
Jan
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
Rya 2017 年 6 月 1 日
the number is stored in variable (noPlate) and output shows in editbox
set(handles.edit1,'string',noPlate);
here is a cell array ('ANPR.mat')
now how to check whether the output no lies in cell array or not

サインインしてコメントする。

回答 (2 件)

ES
ES 2017 年 6 月 1 日

2 投票

[truefalse, index] = ismember('abc', {'xyz', 'abc', 'def', 'abc'})
This one?

12 件のコメント

Rya
Rya 2017 年 6 月 1 日
編集済み: Walter Roberson 2017 年 7 月 10 日
I used this code
ANPR=['AED632' 'KPT295' 'AKH343' 'AFR420']; %cellarray
if ismember(noPlate,ANPR)
msgbox( 'The number is Registered in database','success');
else
errordlg( 'The number is not Registered in database','error');
end
here in this code i defined cell array, but in my case i want to load a cell array which is my database file('ANPR.mat') so please help me how to use database file in above case
ES
ES 2017 年 6 月 2 日
just load your mat file.
load
Rya
Rya 2017 年 6 月 3 日
編集済み: Rya 2017 年 6 月 3 日
i used this but it gives error, i m wrong somewhere
load ANPR
if ismember(noPlate,ANPR)
and what does this error means: Error while evaluating uicontrol Callback
Stephen23
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
Rya 2017 年 6 月 3 日
what is (:,2)
Stephen23
Stephen23 2017 年 6 月 3 日
編集済み: Stephen23 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
Rya 2017 年 6 月 3 日
編集済み: Rya 2017 年 6 月 3 日
I will, and this works thank you so very very much where should i vote u now??
Rya
Rya 2017 年 6 月 3 日
Another query...
I want to find that how many times a specific number is being searched in cell array(ANPR) just to keep record that how many times a vehicle go through a system
load ANPR
>> ismember('EK94P8',ANPR(:,2))
Stephen23
Stephen23 2017 年 6 月 4 日
nnz(ismember('EK94P8',ANPR(:,2)))
Rya
Rya 2017 年 6 月 4 日
nnz(X) returns the number of nonzero elements in matrix X. how does sit works?
Walter Roberson
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
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
Jan 2017 年 6 月 1 日

0 投票

found = any(strcmp(TheNumber, TheListOfNumbers))

5 件のコメント

Rya
Rya 2017 年 6 月 1 日
I used this code
ANPR=['AED632' 'KPT295' 'AKH343' 'AFR420']; %cellarray
if ismember(noPlate,ANPR)
msgbox( 'The number is Registered in database','success');
else
errordlg( 'The number is not Registered in database','error');
end
here in this code i defined cell array, but in my case i want to load a cell array which is my database file('ANPR.mat') so please help me how to use database file in above case
Jan
Jan 2017 年 6 月 2 日
編集済み: Jan 2017 年 6 月 2 日
@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
Rya 2017 年 6 月 3 日
編集済み: Rya 2017 年 6 月 3 日
i used this now, still it gives error
load ANPR
%found = any(strcmp(noPlate, ANPR))
if (strcmp(noPlate, ANPR) )
msgbox( 'The number is Registered in database','success','help');
else
errordlg( 'The number is not Registered in database','Error','modal');
end
error: Default string does not match any button string name
Rya
Rya 2017 年 6 月 3 日
where is this button string name comes from i want to find a string is cell array (mat-file)
Rya
Rya 2017 年 6 月 3 日
I m clear now @jan Thanq , will come up with new question :)

サインインしてコメントする。

カテゴリ

タグ

質問済み:

Rya
2017 年 6 月 1 日

コメント済み:

2017 年 7 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by