Creating a polar plot in a Matlab GUI (using GUIDE)?

32 views (last 30 days)
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 Comments
Rik
Rik on 8 Jan 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
Steven Lord on 8 Jan 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.

Sign in to comment.

Answers (1)

Rik
Rik on 7 Jan 2019
Edited: Rik on 8 Jan 2019
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 Comments
sonR
sonR on 7 Jan 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
sonR on 8 Jan 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.

Sign in to comment.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!