I am using ezpolar to draw an arc on a compass plot. It's super easy,
ezpolar('1', [TH1, TH2])
to plot a circular arc with a radius 1 over the range [TH1, TH2]. However the function itself "r=1" gets displayed on the plot, which I do not want. I can't find and references to how this can be suppressed with an extra parameter or something.
I realise I could plot the arc other ways, but this is a cool function and super-compact, so I'd like to use it here and in the future.
Anyone know how to suppress the displaying of the function on the plot?
Thanks in advance
Tricky!
It looks like ezpolar is one of those MATLAB plots where a lot of things happen but nothing gets returned to the user. However I found the way using findobj.
Fiddling with the plot I realized that it is a 'Text' object what MATLAB puts in the plot, so we can try to find it with
h = findobj(gca,'Type','Text')
and then delete the text, for example with:
h.String='';
Tada!
Related
I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.
I have a plotting function inside imshow() command.
The plot and the image should be in separate figures.
At the return from the inside function the current figure is of the plot thus imshow() puts the image onto the same figure of the plot and kills the plot.
What can be done to make imshow() open or get to an existing its own figure, while keeping such manner of nested function calling?
Well, apparently, I've found an answer by the time I was done with the question, but because I find it interesting enough and find nothing answering it I'm writing the answer as well.
The algo is like this:
open a figure before imshow(nested_function());
upon starting the nested_function() save the handle to the
previous figure like fh_prev = gcf; for example
do any plots along the nested_function()
before return from the nested_function() activate the previous
figure with the command figure(fh_prev);
I am workin on a some sort of System test wherein i have a set of readings in the form of a .mat file.
It has a structure in the .mat file with one field as Measurement. It has several Arrays(e.g air mass flow, velocity, carbon content) which further have fields like time and value.
From these, I Need to plot the velocity and the air mass flow against time. For that i wrote the following command which gave me the corresponding plots:
plot(Measurement.(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
plot(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
Now i Need to create a script in matlab wherein i can get both the curves one under the other i.e. on the same page. Can anyone help in the Approach i should procede with ?
ok now i will further extend my question.
I have two fields as velocity and acceleration. I Need to plot it on the same curve with grids on for the comparison. But the y axis for both are different.
the velocity y-axis is: (0:20:120), which should be displayed on the left side and the acceleration y-axis is: (0:2:12) which should be displayed on the right side.
i wrote the following code for this:
plot(Measurement.(Measurement.VehV_v.time),Measurement.VehV_v.value)
grid on
set(gca,'xtick',[0:500:2000])
set(gca,'ytick',[0:20:120])
hold on
plot(Measurement.(Measurement.accel_w.time),Measurement.accel_w.value)
grid on
set(gca,'xtick',[0:500:2000])
set(gca,'ytick',[0:2:12])
Do i Need to write a function for that as i am directly reading the values from the structure.
plotyy() also doesnt seem to work
But the axis are not matching and the graph for acceleration is very small. Could anyone help me out with this ?
I also want to add a Picture of the Graphs here but unfortunately there is some error here. I hope the question is clear without the Picture.
Yes you can use the subplot command, e.g.:
figure
subplot(1,2,1)
plot(Measurement(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
subplot(1,2,2)
plot(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
You can use help subplot on Matlab for further details or have a look at this:
https://www.dartmouth.edu/~rc/classes/matlab_graphics/Matlab-subplots.html
I am making a quiver plot :
[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
figure
quiver(x,y,u,v)
I want the arrow heads to be filled (i.e and not )
From the documentation, it should be pretty straightforward by using
quiver(...,LineSpec,'filled')
However, I still couldn't figure out the right syntax - these do not work :
quiver(x,y,u,v,'LineWidth','filled');
quiver(x,y,u,v,'LineWidth',1,'filled');
Thanks for your help!
edit : Using line specifiers does the following:
quiver(x,y,u,v) %Original
quiver(x,y,u,v,'-sk','filled') %With line specifiers
I am not a MATLAB professional, so please excuse if my answer is clunky. I am sure there are more elegant ways to solve this - the following is the one I found.
I decided to solve this retrieving the positions of the arrow tips, deleting them and repaint them with fill (like Deve suggested). I noticed that I can tell fill that one polygon ends and the next begins through inserting NaN values (thats also the way the original arrow tips are drawn, as you can see inspecting the original XData). Doing so I lost the possibility to influence the color of the objects and they didn´t get filled. As a work-around I painted the new arrow-tips in a loop - I know there might be a better way to do it, so I am happy about any addition.
I used the example you gave, only replacing the last line by
HANDLE = quiver(x,y,u,v); to get the handle to the plot. From there on:
children=get(handle,'children'); % retrieve the plot-children -
% second element are the arrow tips
XData=get(children(2),'XData'); % retrieve the coordinates of the tips
YData=get(children(2),'YData');
hold on
delete(children(2)) % delete old arrow tips
for l=1:4:length(XData)-3 % paint new arrow tips, skipping the NaN-values
ArrowTips((l-1)/4+1)=fill(XData(l:l+2),YData(l:l+2),'r');
end
You can then find the handles to the arrow-tips in the ArrowTips-variable. Feel free to specify the Edge- and Facecolor in the call to fill, here being black and red respectively.
This code in an answer to a similar question works quite well, actually. It uses annotations.
In Matlab how do I change the arrow head style in quiver plot?
I would like to plot a vertical line (I'd prefer any orientation, but I'd be happy with just vertical right now) with two-color dashes, say red-blue-red-blue-...
I know I could do it like this:
plot([1,1],[0,1],'r'),
hold on,
plot([1,1],[0,1],'--b')
However, since I need to be able to move the line, among others, it should only have a single handle. How could I do this?
EDIT
Thank you for your answers. I guess I should indeed give some more information.
I have some data that is classified into different parts. I want to be able to manually adjust the boundaries between classes. For this, I'm drawing vertical lines at the classification boundaries and use draggable to allow moving the lines.
For the boundary between the red and the blue class, I'd like to have a red/blue line.
plot(ones(10,1),linspace(0,1,10),'-bs','MarkerFaceColor','r','MarkerEdgeColor','none','linewidth',6)
is what I'm actually using at the moment. However, it's not so pretty (if I want equal spacing, it becomes a real pain, and I want to give both colors the same weight), and I would like to have the possibility to use three colors (and not with marker edge and face being different, because it makes my eyes bleed).
Unfortunately, draggable does not allow me to use multiple handles, and grouping the lines with hggroup does not seem to create a draggable object.
cline looks like a promising approach, but rainbow colors won't work for my application.
You can use the code you have, and just concatenate the handles from each line into a vector of handles. When you want to change the properties of both lines simultaneously, the SET function is able to accept the vector of handles as an argument. From the documentation for SET:
set(H,'PropertyName',PropertyValue,...)
sets the named properties to the
specified values on the object(s)
identified by H. H can be a vector of
handles, in which case set sets the
properties' values for all the
objects.
Here's an example:
h1 = plot([1 1],[0 1],'r'); %# Plot line 1
hold on;
h2 = plot([1 1],[0 1],'--b'); %# Plot line 2
hVector = [h1 h2]; %# Vector of handles
set(hVector,'XData',[2 3]); %# Shifts the x data points for both lines
UPDATE: Since you mention you are using draggable from the MathWorks File Exchange, here's an alternate solution. From the description of draggable:
A function which is called when the
object is moved can be provided as an
optional argument, so that the
movement triggers further actions.
You could then try the following solution:
Plot your two lines, saving the handle for each (i.e. h1 and h2).
Put the handle for each in the 'UserData' property of the other:
set(h1,'UserData',h2);
set(h2,'UserData',h1);
Create the following function:
function motionFcn(hMoving) %# Currently moving handle is passed in
hOther = get(hMoving,'UserData'); %# Get the other plot handle
set(hOther,'XData',get(hMoving,'XData'),... %# Update the x data
'YData',get(hMoving,'YData')); %# Update the y data
end
Turn on draggable for both lines, using the above function as the one called when either object is moved:
draggable(h1,#motionFcn);
draggable(h2,#motionFcn);
I've never used it, but there's a submission by Sebastian Hölz called CLINE on the Mathworks File Exchange that seems related.
I don't know how to do exactly what you want, but presumably the reason you want to do this is to have some way of distinguishing this line from other lines. Along those lines, take a look at MathWorks' documentation on 2-D line plots. Specifically, this example:
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
should give you plenty of ideas for variation. If you really need the two-color dashes, it might help to specify why. That way, even if we can't answer the question, perhaps we can convince you that you don't really need the two-color dashes. Since you've already ruled out the over-lapping solution, I'm fairly certain there's no solution that answers all of your needs. I'm assuming the two-colorness is the most fluid of those needs.