I would like to create the nearest closed contour right now when I do contour its broken in chunks. Here is the picture of contour:
I wanted a closed contour around the center.
I need something like this
axes(handles.axes1);
cla(handles.axes1);
hold on;
pcolor(xC,yC,z_Diff); shading flat
colormap(handles.axes1, 'jet');
freezeColors(handles.axes1)
[C,hfigc] = contour(xC,yC,z_Diff,[thresh_crater thresh_crater]);
set(hfigc, ...
'LineWidth',1.0, ...
'Color', [1 0 0]);
hold off;
I am trying enclose a box around the crater area which include the hole and outer piled stuff:
I am getting the results below based on largest contour area:
Here is the image I want it to be like this:
This will be problem if i have more than 1 crater and i want to box them.
Related
This question already has answers here:
Show two different plots in one plot
(2 answers)
MATLAB - Plot multiple data sets on a scatter plot
(3 answers)
Closed 3 years ago.
I have a heat map of values generated by "pcolor" in MATLAB. I would like to plot a line plot on top of that.
I haven't found a proper solution in any measure yet.
The following code generates a "heat map" sort of output
hc = pcolor(middle_long, middle_height, middle_no2);
set(hc, 'Edgecolor', 'none');
c = colorbar;
caxis([0 0.015]);
axis([min(middle_long(:,1)) max(middle_long(:,1)) 0 1000])
The following code generates a line plot
plot(longflag, hflag)
The following are figures of the individual plot types that I would like to join, with an "example" of the final product I'd like listed afterwards:
Try something like this. Note the hold on part, which prevents plot from deleting the image produced by pcolor:
pcolor(rand(10))
colormap bone
axis xy
hold on
plot([1 10], [10 1], 'r')
Is there an easy command to have a plot like the blue line in the picture (excel)? Matlab defaults to produce something like the line in red. The only way I know to do this is to issue a plot command for each segment of the line:
for i=2:n-1
plot([data(i-1,1) data(i,1)],[data(i-1,2) data(i,2)],'-b'); hold on;
end
You can just plot the entire array and let plot automatically draw straight line segments between each of the points. This is the default behaviour when plotting things in MATLAB. MATLAB plotting smooth lines is not the default behaviour when the plot is produced, so I'm not sure where you're getting that information.
You would need to perform some sort of spline interpolation to get the red line, but you desire the blue curve and so plotting the entire array in a single plot command should suffice.
It's as simple as:
plot(data(:,1), data(:,2), '-b');
Just to be sure that we're on the same page, I'm going to reproduce your data then use the above command to plot the data so you can see for yourself that the behaviour you desire is achieved:
data = [0 0; 1 1; 2 4; 3 6; 4 4]; %// Your data reconstructed
plot(data(:,1), data(:,2), '-b'); %// Main plotting code
%// Some extras
xlim([0 4.5]);
ylim([0 7]);
grid;
I've added in some extra code to get the plot to look like your example. I've made the x-axis limits go up to 4.5 and the y-axis limits go up to 7. I've also placed a grid in the plot.
We get:
This question already has answers here:
How to create a custom colormap programmatically?
(2 answers)
Closed 7 years ago.
I have a contour plot with data that goes from -90 to 90 degrees. for now i am using jet so I have a map that looks like this
I have been asked to change the colormap so that instead of having a gradient, I have a fixed color for each 5 degress (so I believe 36 colors). Also i was thinking of maybe having same colors for the interval [5 10] and [-10 -5], and so on if that makes sense.
My code is quite long because i have a lot of data to process, but that's part of it just so you can see what function i am using to plot this
%%
x1=data(:,5); %x location
y1=data(:,16); %y location
z1=phi*90; %angle phi
z2=gamma*90; %angle gamma
n=300; precision of grid
%Create regular grid across data space
[X,Y] = meshgrid(linspace(min(x1),max(x1),n), linspace(min(y1),max(y1),n));
figure(3);
contourf(X,Y,griddata(x1,y1,z1,X,Y),100,'EdgeColor', 'None')
%title('Variation of In-plane angle \phi')
axis equal
axis ([0 8000 0 12000])
axis off
h=colorbar;
caxis([-90 90])
set(h, 'YTick', [-90:15:90])
Does anyone know how to create this colorbar?
Cheers
Every colormap-generating function in Matlab, including jet, takes an argument that specifies how many colormap entries there should be. In your case, you want 180 / 5 = 36 discrete colors:
colormap(jet(36))
To make sure the 36 colors cover exactly the 5 degree steps, set the color axis explicitly:
caxis([-90 90])
The result looks e.g. like this:
I have a problem in matlab. I want to plot a graph having 5 plots. Let me go through them.
x axis for each data is from 1:500.
For plot 1 to 3, I want to place marker after every 10 values, whereas for plot 4 to 5 I want to place markers after every 5 values. Is it possible to do it ?
I followed a code something like this:
figure,
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
set(gcf,'Color','white');
plot(ObjVal1(1:10:end),'*r','LineWidth',3);
hold on;
plot(ObjVal2(1:10:end),'-.b','LineWidth',3);
plot(ObjVal3(1:10:end),'+-k','LineWidth',3);
plot(ObjVal4(1:5:end),'sm','LineWidth',3);
plot(ObjVal5(1:5:end),'.b','LineWidth',3);
hold off;
title({'Fitness Value'},'FontWeight','bold','FontSize', 12,'Color','black');
xlabel('Fitness Value --->','FontWeight','bold','FontSize', 12,'Color','black');
ylabel('Iterations --->','FontWeight','bold','FontSize', 12,'Color','black');
legend('CV GDS','CV Momentum','CV Exct LS','CV Back Track','CV Conjugate GDS');
Then I get an output like this :
The problem is quite evident from the picture. The plots of 1-3 is given for 50 values as the subplot is taken for each 10 iterations whereas the 4th and 5th plot is given for 100 values as the subplot is taken for each 5 iterations. I do not want to do this. Basically I want the plot of all the values but with the markers placed at each 10 iterations for plot 1-3 and at each 5 iterations for plots 4-5.
Thanks everybody in advance for your help !
Use first argument to plot to specify x-axis positions of the markers:
plot(1:10:numel(ObjVal3), ObjVal3(1:10:end),'+-k', 'LineWidth', 3);
plot(1:5:numel(ObjVal4), ObjVal4(1:5:end), 'sm', 'LineWidth', 3)
I got this question that how to add dots on a 2D graph, like the following picture.
https://www.dropbox.com/s/rs501qkwqqk8qgk/abc.jpg
(the white dots and text on the above graph are needed to be added.)
I have plotted the graph, just do not know the command in matlab of adding the dots on that.
Thanks
(Since there are not many details, I'll go with a generic answer)
If you have the dots coordinates in, say, vectors X and Y, you can plot them with:
hold on; % Keep your plot while updating
plot(X, Y, 'ok'); % Black circles with white background
hold off; % Allow your plots to refresh after that
Also, if you know where the text 'Tower' should be drawn in the current axes (i.e. taking in account the axes limits), say, x_text and y_text, then:
hold on;
text(x_text, y_text, 'Tower');
hold off;
should do the job.