Error after clicking in pushbutton "Parent must be a scalar graphics handle."

20 ビュー (過去 30 日間)
hawk5577
hawk5577 2018 年 11 月 16 日
編集済み: Adam Danz 2018 年 11 月 21 日
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%Jesli radio1 jest zaznaczone to obliczy deformacje pomiaru 0-N
%%Obliczanie Obniżeń
[num,txt]=xlsread('dane0.xlsx');
num(isnan(num))=00;
x=num
set(handles.tabela0,'data',x);
x=get(handles.tabela0,'data');
w=x(:,3)-x(:,2);
wpoz=x(1:end,1);
calosc=[wpoz w]
set(handles.tabelaw,'data',calosc);
x=get(handles.tabela0,'data');
wykresww = findobj('Tag', 'axes1');
plot(wykresww,calosc(1:2:end,1),calosc(1:2:end,2));
After clicking Run, and click in pushbutton2 I have results but If I click again in pushbutton2 I have error:
ccc.png

採用された回答

Adam Danz
Adam Danz 2018 年 11 月 16 日
編集済み: Adam Danz 2018 年 11 月 21 日
Whenever you're troubleshooting an error in this forum, include the entire error message and indicate what line is causing the error. I have a pretty good guess at the source of the error but I'm not certain without having that information.
Possible source
I think the first line below returns an empty value in wykresww or it returns more than one handle.
wykresww = findobj('Tag', 'axes1');
plot(wykresww,calosc(1:2:end,1),calosc(1:2:end,2));
If it's empty, that means you don't have an object with the tag 'axes1'. If it has more than one handle, that means you have multiple objects with the tag 'axes1'.
Solution
Rather than searching for your axis, why not grab its handle directly from the 'handles' variable? For example, if the handle to your axis is handles.axis1,
plot(handles.axis1, calosc(1:2:end,1), calosc(1:2:end,2));
If you must use findobj() (which you shouldn't) you need to make sure it's finding the correct object.
  3 件のコメント
Adam Danz
Adam Danz 2018 年 11 月 16 日
findobj() will identify those axes only if they have the tag "axes1" which might be the case. The same error would occur if findobj() returns an empty output after finding no objects with the tag "axes1".
Steven Lord
Steven Lord 2018 年 11 月 16 日
You are correct. I read too quickly and assumed the findobj call was looking for 'Type', 'axes'.
Given that, you're right that it's probably empty. Calling plot (as MATLAB did the first time it ran the callback, when the user pressed the button the first time) cleared the Tag property.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by