Effacer les filtres
Effacer les filtres

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

17 vues (au cours des 30 derniers jours)
% --- 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

Réponse acceptée

Adam Danz
Adam Danz le 16 Nov 2018
Modifié(e) : Adam Danz le 21 Nov 2018
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 commentaires
Adam Danz
Adam Danz le 16 Nov 2018
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 le 16 Nov 2018
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Identification dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by