problem is that it can not plot x and y,(

IN GUI,i define handles.matricdata.a=1 in pushbutton1 callback function.
then in pushbutton2 callback function i use
b=handles.matricdata.a;
if(b~=1)
x=[1 2 3 4 5];
y=[5 5 5 5 5]
plot(x,y);
end
then problem is that it can not plot x and y,(if pushbutton1 is not press,then x and y must be plot )

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 3 日

0 投票

You should write in opening function
handles.matricdata.a=0

5 件のコメント

vipul utsav
vipul utsav 2013 年 3 月 3 日
編集済み: vipul utsav 2013 年 3 月 3 日
in code y=y*5 should perform everytime b==1 or b==0;
function pushbutton1
handles.matricdata.a=1;
function pushbutton2
handles.matricdata.a=0;
b=handles.matricdata.a;
if(b~=1)
x=[1 2 3 4 5];
y=[5 5 5 5 5]
plot(x,y);
end
y=y*5;
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 3 日
編集済み: Azzi Abdelmalek 2013 年 3 月 3 日
Have you updated handles with guidata?
guidata(hObject,handles)
Also in function pushbutton2
handles.matricdata.a=0;
b=handles.matricdata.a;
b is always different from 1
vipul utsav
vipul utsav 2013 年 3 月 3 日
yes , i have updated handels with 'guidata(hObject,handles)'
function pushbutton1
handles.matricdata.a=1;
function pushbutton2
b=handles.matricdata.a;
if(b~=1)
x=[1 2 3 4 5];
y=[5 5 5 5 5]
plot(x,y);
end
y=y*5;
but when pushbutton1 is not pressed,it should plot x and y.
and when pushbutton1 is pressed,it should not plot x and y.
in above code these task is not perform.please correct it.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 3 日
In your yourfilename_OpeningFcn
handles.metricdata.a=0;
guidata(hObject,handles)
vipul utsav
vipul utsav 2013 年 3 月 3 日
thanks

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 3 月 3 日

0 投票

Now why would that not plot when you just set the value to 0 and you're checking if it's not equal to 1. It must go into the if statement. But this is bad code in several ways. What's the point of setting it to 1 in pushbutton1's callback? Why have an "if" in pushbutton2's callback when you directly assign it so you know what the state will be? The if is not necessary in that case. Why do you multiply y by 5? Think about it. If you don't enter the "if" then y will be undefined and it will throw an error. (Though I've already said that you will enter the if because of strange coding.) So in that case, just set y = [25 25 25 25 25] and be done with it.

1 件のコメント

vipul utsav
vipul utsav 2013 年 3 月 3 日
i post code just for examples but my main task of pushbuttton1 and pushbutton2 is different. i want that pushbutton2 is display the status of pushbutton1 that whether pushbutton1 is pressed or not? (i.e if pushbutton1 has been pressed and then after i press pushbutton2,it display message 'pb1 is press' using pushbutton2,
and if pushbutton1 has been not pressed and then after i press pushbutton2,it display message 'pb1 is not press' using pushbutton2, in gui)

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

カテゴリ

ヘルプ センター および File ExchangeGraphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by