Info

此问题已关闭。 请重新打开它进行编辑或回答。

i am trying to build a gui in which first popupmenu1 having code which gives results as 'rs' and i want to pass that result to next popupmenu2 i have used guidata to do so but i am getting error " reference to non existance field "

1 次查看(过去 30 天)
code is
function popupmenu1_Callback(hObject, eventdata, handles)
switch get(handles.category,'string')
case 'Tomato' % User selects Peaks.
a=imread('picview_tmpEnvironmental214.jpg');
b=a;
a=rgb2gray(a);
a=im2bw(a,.5);
[m,n]=size(a);
a=~a;
figure,
imshow(a);
count=0;
for i=1:m
for j=1:n
if(a(i,j)==1)
count=count+1;
end
end
end
a=b;
[rows cols plane] = size(a);
rplane = a( : , : ,1);
gplane = a( : , : ,2);
bplane = a( : , : ,3);
flag=0;
for x=1:1:rows;
for y=1:1:cols
if ((128 < rplane(x,y) & rplane(x,y) <= 255) & (0 < gplane(x,y) & gplane(x,y) <= 128) & (0 < bplane(x,y)
& bplane(x,y) <= 128))
flag=1+flag;
end
end
end
K=count;
%K=rows*cols-%no of white or black pixels(that meance pixels other than fruit pixels);
rs = (flag/K)*100;
_ *handles.rs=rs;
guidata(hObject,handles)*_
case 'Mango'
case 'Apple ju ju be'
case 'Orange'
otherwise;
end
function popupmenu2_Callback(hObject, eventdata, handles)
rs3=handles.rs;
  1 个评论
Adam
Adam 2016-3-15
It depends what happens in the rest of your code and what you are doing as a user. In the code you have shown us the field 'rs' will only exist on handles if the user selects 'tomato' from the first popup list. If they don't click anything or they click one of the other options then 'rs' may well not exist, depending on what the rest of your code does.
When I am adding fields to handles I always tend to initialise them in the OpeningFcn rather than just randomly introduce them in some code path of some callback somewhere in the GUI.

回答(0 个)

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by