Creating a polar plot in a Matlab GUI (using GUIDE)?
Mostrar comentarios más antiguos
I am creating a GUI to control a robot and plot points that are received that correspond to object locations in polar (an angle and radius). I tried creating a set of normal axes in GUIDE and testing by calling
polarplot(axesHandle, [0 90 180], [10, 10, 10])
However, I get the error "Parent input must be a polaraxes object". How do I change the regular axes to a polar one?
6 comentarios
sonR
el 7 de En. de 2019
I too have this problem. "Parent input must be a polaraxes object".
I am trying to use GUIDE to plot 4 separate polar plots on the same figure (you know... a quad qraph) but I get the same error. It works for only one polarplot but we don't have to use the handles or they are applied differently.
For me, and for a single polarplot I am using handles.pol = polarplot(handles.thetarad,rho,'b');
but this does not reference a specific plot in the GUIDE gui i.e. display 1 or display 2.
Right now I'm playing pinata with this as swinging blindfolded until I hit something...and matlab candy comes out.
sonR
el 8 de En. de 2019
The matlab documentation states that the polarplot is not supported in App Designer.
How do we create four separate polarplots on a GUI using guide? If you layout four separate axes (i.e. display1, display2, display3, display4) how do you reference display1 with polarplot data 1and each subsequent plot with its own data? In the two_axes.m example each plot references the handle to the appropriate axis ... plot(handles.frequency_axes,f,m) for the frequency plot and plot(handles.time_axes,t,m) but for polarplot there is no capability to input the handles to the guide axes individually such as polarplot(handles.display1,angledata,rhodata) then polarplot(handles.display2.angledata,rhodata).
It seems that I can overlay polarplots because it is referencing the only display on the gui but four separate gui's ??
Rik
el 8 de En. de 2019
I have no clue what you mean with your final question. If you want to use polarplot in a GUI, you should use explicit handles. This is shown in the doc:
polarplot(pax,___) uses the PolarAxes object specified by pax, instead of the current axes.
So once you have create a PolarAxes object (and stored the handle), you can use the handle to that object to make sure the plot goes into the axes you mean. You should not be using the axes function, or subplot function.
The variable name you are using for each PolarAxes object is of course up to you, but using display1 and display2 seems confusing to me.
sonR
el 8 de En. de 2019
Refer to the GUIDE example for two_axes.m and substitute polarplot for plot. (search help documentation for "Guide App With Parameters for Displaying Plots". How could I change the plots to polarplots using theta and rho data of course.
I'm repeating the same question because the documentation is not clear for polarplot objects in GUIDE.
If you use GUIDE and lay out 4 plots (aka 'axes') then each axes has a unique handle...i.e. handles.axes1, handles.axes2, handles.axes3, handles.axes4. I renamed my axes to display1, display2, display3, display4 in the inspector window.
To plot a rectangular plot you can use the handle to the axes you want to plot to so I would use plot(handles.axes1,x1,y1)..plot(handles.axes2,x2,y2) ....plot(handles.axes3, x3, y3) etc. this is evident in the matlab example two_axes.m(and fig) which uses guide.
However, if you use polarplot(handles.axes1,theta1, rho1)...polarplot(handles.axes2, theta2, rho2) it
I used the slider example in GUIDE and substituted my single polar plot and it worked but not for 4 separate polarplots. The error is "Parent input must be a polaraxes object" and I don't know what to do with that. I don't know how to lay out 4 separate polar plots in GUIDE and update each plot separately and use polaraxes to plot my polar graph on its unique axes in GUIDE.
Rik
el 8 de En. de 2019
I suspect you are misunderstanding this point: an axes object is something totally different from a polaraxes object, just as a line plot and a bar plot are different. You can't use axes object to plot polarplots, so you need to remove the axes object and put in a polaraxes instead.
I can't find the example that you are referring to with a quick google search, so you'll have to give me an explicit link if you want specific guidance.
I have a dislike for GUIDE, because it doesn't really help you much when making a GUI, hence my small guide to avoid GUIDE.
I will edit my answer below to include a small example about how you can create a small GUI with multiple polaraxes objects.
Steven Lord
el 8 de En. de 2019
The matlab documentation states that the polarplot is not supported in App Designer.
Which release are you using? According to the online documentation (which is for the most recent release, currently release R2018b) in order to use a polarplot in App Designer you need to create the polaraxes using the handle to the parent container as the first input then pass the polaraxes handle into the polarplot call as the first input. Looking at the Release Notes it appears this support is new in release R2018b.
Respuestas (1)
You can create a polaraxes object (take care to specify appropriate position parameters), and use the handle to that polaraxes object in your polarplot call. As far as I am aware, you can't change a normal axex object to polaraxes.
It is a very bad idea to not use explicit handles in a GUI, as you cannot be sure the user will not bring focus to another axes or figure. That is indeed swinging blindly.
I wouldn't swing at a piñata with GUIDE, but instead build your GUI with the normal Matlab tools, or switch to the AppDesigner in the first place.
My small guide to avoid GUIDE:
- Make a figure (with f=figure;) and look into the doc for figure which properties you want to turn off (you probably want to set Menu and Toolbar to 'none')
- Create buttons and axes and everything you need with functions like uicontrol and axes. Save the handles to each element to fields of a struct (like handles.mybutton=uicontrol(___);)
- When you've finished loading all data (and saving it to fields of your handles struct), and creating all the buttons, save your handles struct to the guidata of your figure like this guidata(handles.f,handles);. (You can also use getappdata and setappdata)
- You can set the Callback property of many objects. If you do, use a function name with an @ in front, or a char array that can be evaluated to valid code. (like @MyFunction or 'disp(''you pushed the button'')')
- Callback functions will be called with two arguments: the first is a handle to the callback object, the second is eventdata that may contain special information. To get access to your data, just use handles=guidata(gcbo);. You can replace the gcbo function with the name of the first input to your callback function if you prefer.
- More information about callbacks can be found in multiple places in the doc, for example here.
A small example with 4 polaraxes object and a button that generate a random plot in each:
function SomeSmallGUI
%clear struct and prepare blank figure
h=struct;h.f=figure(1);clf(h.f)
%create polaraxes objects and store handles
pos_vec={[0.1 0.1 0.3 0.3],...
[0.6 0.1 0.3 0.3],...
[0.1 0.6 0.3 0.3],...
[0.6 0.6 0.3 0.3]};
for n=1:numel(pos_vec)
h.pAxis{n}=polaraxes(...
'Parent',h.f,...
'Units','Normalized',...
'Position',pos_vec{n});
end
%create a button that plots random data
h.runbutton=uicontrol(...
'Parent',h.f,...
'Units','Normalized',...
'Position',[0 0 1 0.05],...
'String','Click me!',...
'Callback',@PlotSomeStuff);
guidata(h.f,h)
end
function PlotSomeStuff(hObject,eventdata)
%plot random data in each polaraxes
h=guidata(hObject);
for n=1:numel(h.pAxis)
rho=rand(1,20);
theta_noise=(rand(size(rho))-0.5)/10;
theta=linspace(0,2*pi,numel(rho))+theta_noise;
polarplot(h.pAxis{n},theta,rho)
end
end
4 comentarios
sonR
el 7 de En. de 2019
Thank you so much Rik. I really appreciate the help. I keep getting little shoves here and there to not use GUIDE and to build gui's programmatically or with the new App builder.
I have an example that does not use guide that seems to work a bit better and I will migrate over to the newer apps.
Again. Thank you so much.
sonR
el 7 de En. de 2019
Rik, it states in the help files for the App Designer that polarplot is not supported? I will try the programmatic method though to simplify it.
sonR
el 8 de En. de 2019
After using the Pinata method and your advice I am now understanding what you are talking about. Thank you again.
I ended up doing just what you said by removing the axes graphs from my GUIDE gui and creating the individual polarplot objects and their positions on the main figure
You're the best Rik.
Categorías
Más información sobre Polar Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!