Problem with quiver plot function
3 次查看(过去 30 天)
显示 更早的评论
I am working on some code which I have been trying to tidy up into functions as I have several versions of it and it's quite repetitive. One of the tasks is a quiver plot, which I have written this function (Qplot) for:
function Qplot( space, lat, lon, u, v, size, thick )
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
hold on
r = 1:str2double(space):length(lat);
r1 = lat(r);
s = 1:str2double(space):length(lon);
s1 = lon(s);
us = u(r, s);
vs = v(r, s);
q = quiver(s1,r1,us,vs);
q.AutoScaleFactor = str2double(size);
q.LineWidth = str2double(thick);
q.Color = 'k';
hold off
end
This works fine on most versions of the code except one. I have had to take out the Qplot bit out (it's there commented out) and replace it with the content of the function in full, like this:
function pushbutton23_Callback(hObject, eventdata, handles) %#ok<*INUSL>
h = guidata(gcbo);
axes(handles.axes2)
% Qplot(handles.edit22.String, h.latf, h.lonf, h.uf. h.vf, handles.edit21.String, handles.edit23.String)
hold on
r = 1:str2double(handles.edit22.String):length(h.latf);
r1 = h.latf(r);
s = 1:str2double(handles.edit22.String):length(h.lonf);
s1 = h.lonf(s);
us = h.uf(r, s);
vs = h.vf(r, s);
q = quiver(s1,r1,us,vs);
q.AutoScaleFactor = str2double(handles.edit21.String);
q.LineWidth = str2double(handles.edit23.String);
q.Color = 'k';
hold off
If I use the Qplot function in that one version only, I get this error message, but in no others where I'm doing exactly the same thing:
Struct contents reference from a non-struct array object.
Error in guiglobal>pushbutton23_Callback (line 280)
Qplot(handles.edit22.String, h.latf, h.lonf, h.uf. h.vf, handles.edit21.String, handles.edit23.String)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in guiglobal (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)guiglobal('pushbutton23_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Any ideas?
10 个评论
Adam
2018-9-24
h = guidata(gcbo);
gives you the handles struct. The exact same one that you get passed into the function as 'handles'.
Generally code using
axes( obj.hAxes )
followed by a load of plot related instructions will work fine, but from time to time you will find a case where the 'current axes' changed without you realising between you calling axes and actually plotting data. I have had numerous occasions when I forgot to give explicit axes handles when I suddenly get an axes appearing in a figure I wasn't expecting it.
So sure, it may work in all cases you have had so far, but it is just good practice to give explicit handles to plot instructions rather than just hope that nothing unexpectedly changes the current axes before you plot (e.g. a user clicking on a different axes will change the current axes too).
采纳的回答
Dennis
2018-9-24
You got a typo:
Qplot(handles.edit22.String, h.latf, h.lonf, h.uf. h.vf, handles.edit21.String, handles.edit23.String)
^^ this should be a ,
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!