how to retrieve array data with the help of index in matlab uiTable
1 次查看(过去 30 天)
显示 更早的评论
I want to access array data in Matlab GUI, i want to search the record from array on the basis of an index
load ANPR
if ismember(noPlate,ANPR(:,2))
msgbox( 'The number is Registered in database');
else
msgbox( 'The number is not Registered in database');
Info of all plate lies in VehicleDes.mat, the number is stored in noPlate after matching noPlate in array ANPR.mat i also want to show the detail information of that noPLate that lies in array VehicleDes,it might shown after clicking on ok button of msgbox or another option is to show data in uitable plz suggest how to do that
4 个评论
Walter Roberson
2017-6-5
Could you give a small example? I can see several possible meanings for your question?
采纳的回答
Walter Roberson
2017-6-5
[tf, idx] = ismember(ThisPlateString, CellArrayOfPlateStrings);
if ~tf
msgbox('No match')
else
Information_About_This_Plate = Information_About_All_Plates(idx, :);
end
35 个评论
Rya
2017-6-5
load ANPR
if ismember(noPlate,ANPR(:,2))
msgbox( 'The number is Registered in database');
else
msgbox( 'The number is not Registered in database');
Info of all plate lies in VehicleDes.mat, the number is stored in noPlate after matching noPlate in array ANPR.mat i also want to show the detail information of that noPLate that lies in array VehicleDes,it might shown after clicking on ok button of msgbox or another option is to show data in uitable plz suggest how to do that
Walter Roberson
2017-6-5
[tf, idx] = ismember(noPlate, ANPR(:,2));
if ~tf
msgbox( 'The number is not Registered in database');
Information_About_This_Plate = {};
else
index_in_database = ANPR{idx, 1};
Information_About_This_Plate = VehicleDes(index_in_database, :);
msgbox( ['The number is Registered to', Information_About_This_Plate{2}] );
end
However, in the data you posted for ANPR,
[2] 'KPT295'
implies that plate KPT295 should be the second plate in VehicleDes, but it is the first (and only) plate instead. Should we be ignoring the information in the first column of ANPR ?
Walter Roberson
2017-6-6
You can create a figure() and put uicontrol('style', 'text') fields up with different background colors. The easiest way to display an image is to put an axes in and display the image on the axes with image() (I would not recommend imshow() for this purpose.)
Walter Roberson
2017-6-7
What do you mean for all of the plates? Your noPlate variable is a single character vector indicating one plate to look up.
Instead of msgbox you can set(( ) the String field of a uicontrol 'style', 'text'
Rya
2017-6-7
yes i got it but this code works in command prompt but it doesn't work in m file, why??
Walter Roberson
2017-6-7
编辑:Walter Roberson
2017-6-7
Post your current code. And the complete error message
Walter Roberson
2017-6-7
bgcol = [.6 .58 .63];
datacol = [.8 .8 .8];
fig = figure('color', bgcol, 'Units', 'pixels', 'Position', SOMETHING0);
L1 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING1, 'background', bgcol, 'string', 'Make:');
L2 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING2, 'background', bgcol, 'string', 'Model:');
L3 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING3, 'background', bgcol, 'string', 'Year:');
L4 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING4, 'background', bgcol, 'string', 'Doors:');
D1 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING5, 'background', datacol, 'string', car_make);
D2 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING6, 'background', datacol, 'string', car_model);
D3 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING7, 'background', datacol, 'string', car_year);
D4 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'Position', SOMETHING8, 'background', datacol, 'string', car_doors);
ax = axes(fig, 'Units', 'pixels', 'Position', SOMETHING9, 'color', bgcol)
imh = image(ax, car_image);
axes(ax, 'image', 'off');
Rya
2017-6-8
But I'm unable to show image plz tell me where I m wrong!
ax = axes(fig, 'Units', 'pixels', 'Position', [400 150 150 40], 'color', bgcol)
imh = image(ax, Information_About_This_Plate{7});
axes(ax, 'image', 'off');
Jan
2017-6-8
"Unable" does not explain what happens. Do you get an error message? Note that axes does not accept the shown arguments, but axis (with i) would.
Rya
2017-6-8
i asked for error in code as I'm sure i did somewhere wrong in code. so here is a Error message
Error using axes
Too many input arguments.
Error in Main>Untitled_1_Callback (line 349)
ax = axes(fig, 'Units', 'pixels', 'Position', [400 150 150 40])
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Main (line 45)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Main('Untitled_1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uimenu Callback
Walter Roberson
2017-6-8
Change
ax = axes(fig, 'Units', 'pixels', 'Position', SOMETHING9, 'color', bgcol)
to
ax = axes('Parent', fig, 'Units', 'pixels', 'Position', SOMETHING9, 'color', bgcol)
if you are using R2015b or older.
Walter Roberson
2017-6-9
If you are using a really old version of MATLAB, then you might need
image(Information_About_This_Plate{7}, 'Parent', ax);
However, is it possible that Information_About_This_Plate{7} is empty? That would lead to that error being generated.
Rya
2017-6-11
did u find any solution ?? I have tried so many solutions but google search suck so bad now.
Rya
2017-6-11
still error
Error using axis>LocSetLimits (line 227)
Vector must have 4, 6, or 8 elements.
Error in axis (line 93)
LocSetLimits(ax(j),cur_arg);
Error in Main>Untitled_1_Callback (line 360)
axis(ax, image, 'off');
Walter Roberson
2017-6-11
Not
axis(ax, image, 'off')
The 'image' part needs to be quoted, axis(ax, 'image', 'off')
Rya
2017-6-11
编辑:Rya
2017-6-11
[tf, idx] = ismember(noPlate, NPR(:,2));
if ~tf
msgbox( 'The number is not Registered in database');
Information_About_This_Plate = {};
else
index_in_database = NPR{idx, 1};
Information_About_This_Plate = DB(index_in_database, :);
bgcol = [.83 .82 .78];
datacol = [1 1 1];
label=[.93 .93 .93];
fig = figure('color', bgcol, 'Units', 'pixels','Position', [10, 50, 669, 420],'Name','Vehicle Description Panel');
L0 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 10,'Position', [0 370 50 30], 'background', bgcol, 'string', 'VPN:');
L1 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 15,'Position', [10 330 150 40], 'background', bgcol, 'string', 'Owner:');
L2 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 15, 'Position',[10 270 150 40], 'background', bgcol, 'string', 'Vehicle Type:');
L3 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 15, 'FontSize', 15,'Position',[10 220 150 40], 'background', bgcol, 'string', 'Color:');
L4 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'FontSize', 15,'Position',[10 170 150 40], 'background', bgcol, 'string', 'Make:');
L6 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 15,'Position', [10 120 150 40], 'background', bgcol, 'string', 'Model:');
L7 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 15, 'Position',[10 70 150 40], 'background', bgcol, 'string', 'Year:');
D0 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'FontSize', 10,'Position',[50 370 50 30], 'background',bgcol, 'string', Information_About_This_Plate{1});
D1 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'FontSize', 10,'Position',[170 330 150 40], 'background',datacol, 'string',(Information_About_This_Plate{2}));
D2 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'FontSize', 10,'Position',[170 270 150 40], 'background', datacol, 'string', Information_About_This_Plate{3});
D3 = uicontrol(fig, 'style', 'text', 'units', 'pixels', 'FontSize', 10,'Position', [170 220 150 40], 'background', datacol, 'string', Information_About_This_Plate{4});
D4 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 10, 'Position', [170 170 150 40], 'background', datacol, 'string', Information_About_This_Plate{5});
D5 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 10, 'Position',[170 120 150 40], 'background',datacol, 'string', Information_About_This_Plate{6});
D6 = uicontrol(fig, 'style', 'text', 'units', 'pixels','FontSize', 10, 'Position',[170 70 150 40], 'background', datacol, 'string', Information_About_This_Plate{7});
ax = axis('Parent', fig, 'Units', 'pixels', 'Position', [100 210 380 150])
% ax = axis(fig, 'Units', 'pixels', 'Position', [400 30 20 50])
ax=image(Information_About_This_Plate{8}, 'Parent', ax);
axis(ax, 'image', 'off');
end
Walter Roberson
2017-7-10
You have
ax=image(Information_About_This_Plate{8}, 'Parent', ax);
axis(ax, 'image', 'off');
The first of those two lines overwrites ax with the handle to an image. You need to use a different output variable name.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)