I created a graph in my function:
P = plot( graph(names,names),'LineStyle','none','Marker','x','MarkerSize',8,'NodeColor','red','XData',xi,'YData',yi);
highlight(P,n,'NodeColor','green');
How to save/copy this graph and put it in just created UIAxes in App Designer (using callbackf button)?
Or how to plot the same graph directly from App Designer?
Using this button is also called the function where the graph is created.
Thank you all for your guidance and help.
I tried:
plotData = plot( graph(names,names),'LineStyle','none','Marker','x','MarkerSize',8,'NodeColor','red','XData',xi,'YData',yi);
and then in UIAxes:
plot( app.UIAxesTeziste,P) or plot(app.UIAxesTeziste, plotData.XData, plotData.YDate). For the second try a data were visible but in different way (I would like to have that graph visualized in same way).
To copy the plot from a function to a UIAxes in App Designer, you can modify the function to return the plot handle as an output. Then, in your button callback function in App Designer, you can pass this plot handle to the UIAxes using the "copyobj" function.
function P = plotFunction(names, xi, yi)
P = plot(graph(names,names),'LineStyle','none','Marker','x','MarkerSize',8,'NodeColor','red','XData',xi,'YData',yi);
highlight(P,n,'NodeColor','green');
end
In the button callback function in App Designer:
function pushbuttonCallck(app, event)
P = plotFunction(names, xi, yi);
copyobj(P, app.UIAxesTeziste);
end
Alternatively, if you want to plot the same graph directly from App Designer, you can modify the button callback function to create the plot directly in the UIAxes.
function pushbuttonCallck(app, event)
P = plot(app.UIAxesTeziste, graph(names,names),'LineStyle','none','Marker','x','MarkerSize',8,'NodeColor','red','XData',xi,'YData',yi);
highlight(P,n,'NodeColor','green');
end
Related
I am creating a UI on app designer and I want to plot a bode in my UI.axes.
This figure contains two plots (magnitude, phase) and what I want to do is to plot each plot in different ui.axes.
I've managed to plot only the magnitude bode and the phase bode using the following code :
clc;
clear all;
num = [2];
den = [conv([1 1], conv([1 1], [1 1]))];
sys = tf(num, den);
[mag, phase, freq] = bode(sys, {0.1, 100});
bodemag(sys, freq)
h = bodeplot(sys, freq);
setoptions(h,'MagVisible','off');
This code gives me these two seperate plots :
I am trying to insert these plots in two different ui axes in my app.
Does any one have an idea or another approach on how to insert the plots ?
NB : I've tried the following :-
Writing the code direcly into the app designer but it creates a pop up instead
Using the plot(app.UiAxes, ...., ....) function but I can't seem to make it work
Can you show your code from appdesigner with the app.UIAxes.
Which Matlab realease do you use ?
As i know subplots are not supported in a UIAxes in older versions. So you have to make two UIAxes or use newer version.
If you write your code directly to appdesigner you are creating an Axes. There is an difference between UIAxes and Axes object. If you want to use Axes you have to set more properties to make it display inside your UIFigure of your App.
You tried this ?
I don't know if the UIAxes supports bodemag function. This could make sense, if it doesn't work with UIAxes.
bode = bodemag(app.UIAxes,sys, freq);
If UIAxes doesn't support bodemag then you have to do it with normal axes and code the positioning of this axes.
This is a good example how to do it.: https://de.mathworks.com/help/matlab/creating_guis/polar-plotting-app-gui-in-app-designer.html
And this is the part that is required additional.
% Create polar axes and position it in pixels
app.Pax = polaraxes(app.UIFigure);
app.Pax.Units = 'pixels';
app.Pax.Position = [260 55 230 230];
I generate a graph inside a function and I want to call that graph inside my gui but I don't get how can I do it.
I'm trying to do something like this
function [h1,h2] = namefuction(input)
%stuff
h1 = plot(x1,y1);
h2 = plot(x2,y2)
Then I call this function inside my .fig file and I get in the workspace a line variable for my two plots, then I try to plot them into two separate axes but I fail in this.
For now I'm doing something in order to have the plot code inside the .fig file and before i call plot(x,y) I use axes(handles.axes1); and it works, but I don't like this solution.
Does exist a solution for this?
If I want to read location of the mose click on some image I can do it using callback action.
function[]=FooBar
Img=imshow(FooMatrix,'callback',#(s,e)ImageClickCallback());
function ImageClickCallback(objectHandle,~)
axesHandle = get(objectHandle,'Parent');
coordinates = get(axesHandle,'CurrentPoint');
coordinates = round(coordinates(1,1:2))
end
end
It works well for images but now I have axes with lines only. I tried to set the callback routine to the appropriate axes or the line but I got the error message
Error while evaluating uicontrol Callback
Error using hg.figure/set
The name 'callback' is not an accessible property for an instance of class
'figure'.
Background:
I am trying to create GUI with line plot, say y=f(x) enabling user to select points on the line. Idea is to read the [x,y] coordinates of the mouse click and highlight the point [f'(y),y] or [x,f(x)], where f' is inverse function to f. Something like Data Cursor function does.
callback isn't a valid property of a line object. You'll want to set the ButtonDownFcn property of the line object.
h = plot(1:3, 'ButtonDownFcn', #(s,e)ImageClickCallback()
The ButtonDownFcn property is also available for most of UI elements (including axes)
set(gca, 'ButtonDownFcn', #mycallback)
I have formed a 2D matrix of 180X360. In fact, it is a LatXLong grid of 1°X1°. Each grid point has a value calculated according to my algorithm.
If I want to plot this LatXLong grid using any contour function, it is easy to do.
Now, what I need to do is to make this grid a clickable/ interactive contour plot in a way that when the user clicks anywhere on my grid plot, he gets an onscreen information or a further plot to be displayed specifically related to that grid point.
In short, I want to make a grid/contour plot in which all grid points are hyperlinks and linked to further background information.
check this answer:
if you don't want to have the variable as title of the plot, you can modify the code as:
function mouseExample()
h = plot(rand(10,1), 'o-');
set(h, 'ButtonDownFcn',#buttonDownCallback)
function out = buttonDownCallback(o,e)
p = get(gca,'CurrentPoint');
out = p(1,1:2);
% title( sprintf('(%g,%g)',p) ) % --> no need this line anymore
end
end
the information is saved in the P variable that you can use later.
To get started, look into ginput and text. ginput will let you click on points in your plot and return the coordinates to some function that can generate information to be displayed in the current plot using text of by opening another figure.
You can use ginput in a loop to display multiple data points as you go:
for t = 1:10
[x,y] = ginput(1);
text(x,y,'some info');
end
I don't know of a way to remove the gird lines. NKN's solution might do that for you.
I need a help with MatLab GUI .
I have a GUI with an axes on it,
and a function plotData(axes,data) which has axes as parameter.
The GUI has a button "plot Data".
How can I do the following:
When the button is clicked, call the function plotData with the parameter axes1 and the data that I want to plot?
I want the plot to be directed to axes1 which exists in the GUI.
It's suppose to be simple, but when I send the axes as parameter it doesn't plot on the GUI, or maybe it does but I cant see it.
It works fine for me without the function: just to plot the data. but to plot the data it's not 1 row :).
i tried calling ax which storing the GUI's axes handle on different M file, but since i call it as a function from different M file nothing happens with the GUI axes handle but it also not returning any error.
Side remark: Your question is a bit unclear: if you added small code snippet to illustrate what you have tried, better answers could be provided.
To the question at hand:
Have you tried directing the plot to axis1 in plotData?
function [] = plotData( ax, data )
% make ax the current axes for plot
axes( ax );
% continue with plotting the data
% ...
You can achieve the effect of axes( ax ); in a more efficient way through the specific plot commands you are using.
For example, if you are using simple plot
plot( ax, data ); % plots data to axes ax
check the documentation of the specific plot command you are using for the axes argument.