I would like to plot more curves in one window , I want to see superposing those curves.. Concretely plot RHO_start for 3 curves in one window. I don´t know how to write in my code. Here is it:
我想在一个窗口中绘制更多曲线,我想看到叠加这些曲线。具体地在一个窗口中绘制3条曲线的RHO_start。我不知道怎么写我的代码。就这个:
clear,clc,close all
abc='abc'; cal=18/230;
Results=[];
data=[];
for i=1:3
im=imread(['vz_' num2str(j) abc(i) '.jpg']);
im=imresize(im,0.5);
%figure,imshow(im)
I=rgb2gray(im);
%figure,imshow(I);
J=imadjust(I);
%figure,imshow(J);
T=graythresh (J);
BW=im2bw(J,T);
%figure,imshow(BW);
BWI=1-BW;
%figure,imshow(BWI);
B=imclearborder(BWI);
O=bwareaopen(B,40000);
H=imfill(O,'holes');
L=bwlabel(H);
S=regionprops(L,'Area','Perimeter');
SE=[0 1 0;1 1 1;0 1 0];
%figure,imshow(H);
D=imdilate(H,SE);
E=edge(D,'canny');
%imshow(E);
bound=bwboundaries(E);
%figure,imshow(E);hold on;
for k=1
b=bound{k};
%plot(b(:,2),b(:,1),'r','LineWidth',1.5);
end
for x=1:numel(S)
%plot(S(x).Centroid(1),S(x).Centroid(2),'ro');
end
xx=b(:,2);
yy=b(:,1);
%figure,plot(xx,yy);axis equal;
XX=xx-mean(xx);
YY=yy-mean(yy);
THETA=XX;
RHO=YY;
%figure,plot(XX,YY);axis equal;
[THETA,RHO]=cart2pol(XX,YY);
%figure,polar(THETA,RHO);
%figure,plot(THETA);
%figure,plot(RHO);
RHO_smooth=smooth(RHO,30);
[Mc,Xc]=min(RHO_smooth);
*RHO_start* =[RHO_smooth(Xc:size(RHO_smooth));RHO_smooth(1:Xc)];
tc=1:length(RHO_start);
[~,locsc]=findpeaks(RHO_start,'MinPeakHeight',160,'MinPeakDistance',50);
figure;hold on;
plot(tc,RHO_start);
plot(locsc,RHO_start(locsc),'rv','MarkerFaceColor','r');
grid on;
title('Number of peaks');
xlabel('angle');
ylabel('radius');
data=[data; i (S.Area)*cal^2 (S.Perimeter)*cal];
end
data
As=mean(data(:,2));
Results=[Results; j As];
end
2 个解决方案
#1
#2
example: Assuming you want to plot different data y1 and y2 against the same vector x, you can do
示例:假设您想要针对相同的向量x绘制不同的数据y1和y2,您可以这样做
figure
plot(x,y1);
hold on;
plot(x,y2);
legend('Data1', 'Data2')
figure
creates a new window. You only want to call this once! Otherwise if you take your case as an example 3 windows will pop up, each with one plot.
图创建一个新窗口。你只想打电话一次!否则,如果以您的情况为例,将弹出3个窗口,每个窗口都有一个图表。
hold on
tells matlab to not overwrite the old plot with the new one. Otherwise only the latest plot would be visible.
hold on告诉matlab不要用新的情节覆盖旧的情节。否则只能看到最新的情节。
And here's an example with a loop:
这是一个循环的例子:
figure % Create one figure to draw in
hold on;
for iter=1:10 % In matlab you should never use 'i' as a variable name
plot(x,y{iter}) % Assuming that y is now a cell containing the individual vectors
end
EDIT: Adding colors to your plots
编辑:为您的地块添加颜色
You probably already know the "normal" way of specifying the color via a keyword:
您可能已经知道通过关键字指定颜色的“正常”方式:
plot(x,y,'color', 'green')
But you can easily create your own colors using the RGB (Red Green Blue) scheme. RGB Colors are defined by three values, each value describing the intensity of the corresponding color. You can mix a lot of colors only from these three (everything your monitor is displaying now is very likely defined in RGB). Usually RGB is defined by 3 bits and a bit has 256 values. Therefore your values can take on values between 0 and 255. However, Matlab uses RGB values in the range between 0 and 1. So, if you want to specify the color black you have to use [0 0 0]
and for white [1 1 1]
.
但您可以使用RGB(红绿蓝)方案轻松创建自己的颜色。 RGB颜色由三个值定义,每个值描述相应颜色的强度。你可以只从这三种颜色中混合很多颜色(你的显示器现在显示的所有颜色很可能都是用RGB定义的)。通常RGB由3位定义,并且位具有256个值。因此,您的值可以取0到255之间的值。但是,Matlab使用0到1之间的RGB值。因此,如果要指定黑色,则必须使用[0 0 0]和白色[1] 1 1]。
RGB Colors can be found with google, just type in "RGB Table" in the image search and there you should find what you need. Since these tables often specify the colors in the 0-255 range, you can use these values and simply divide your vector by 255.
可以通过谷歌找到RGB颜色,只需在图像搜索中键入“RGB表”,您就可以找到所需内容。由于这些表通常指定0-255范围内的颜色,因此您可以使用这些值并简单地将矢量除以255。
Let me show you: Let's first define some colors we can use later on
让我告诉你:让我们先定义一些我们以后可以使用的颜色
color_red = [255 0 0]/255;
color_green = [0 255 0]/255;
color_blue = [0 0 255]/255;
color_orange = [255 102 0]/255;
color_pink = [204, 0, 102]/255;
Now our colors can simply be used like the ones integrated in matlab
现在我们的颜色可以像在matlab中集成一样使用
plot(x,y,'color', color_pink);
plot(x,y,'color', [0.8, 0, 0.4]); % Same as above
#1
To plot more things in the same axes use hold on
:
要在同一轴上绘制更多东西,请使用hold on:
figure;
hold on;
plot(1:10,1:10);
plot(1:5,:2:6);
to plot more than one axes in each plot use subplot
在每个图中使用子图绘制多个轴
figure;
subplot(121)
plot(1:10,1:10);
subplot(122)
hold on
plot(1:10,1:10);
plot(1:5,:2:6);
#2
example: Assuming you want to plot different data y1 and y2 against the same vector x, you can do
示例:假设您想要针对相同的向量x绘制不同的数据y1和y2,您可以这样做
figure
plot(x,y1);
hold on;
plot(x,y2);
legend('Data1', 'Data2')
figure
creates a new window. You only want to call this once! Otherwise if you take your case as an example 3 windows will pop up, each with one plot.
图创建一个新窗口。你只想打电话一次!否则,如果以您的情况为例,将弹出3个窗口,每个窗口都有一个图表。
hold on
tells matlab to not overwrite the old plot with the new one. Otherwise only the latest plot would be visible.
hold on告诉matlab不要用新的情节覆盖旧的情节。否则只能看到最新的情节。
And here's an example with a loop:
这是一个循环的例子:
figure % Create one figure to draw in
hold on;
for iter=1:10 % In matlab you should never use 'i' as a variable name
plot(x,y{iter}) % Assuming that y is now a cell containing the individual vectors
end
EDIT: Adding colors to your plots
编辑:为您的地块添加颜色
You probably already know the "normal" way of specifying the color via a keyword:
您可能已经知道通过关键字指定颜色的“正常”方式:
plot(x,y,'color', 'green')
But you can easily create your own colors using the RGB (Red Green Blue) scheme. RGB Colors are defined by three values, each value describing the intensity of the corresponding color. You can mix a lot of colors only from these three (everything your monitor is displaying now is very likely defined in RGB). Usually RGB is defined by 3 bits and a bit has 256 values. Therefore your values can take on values between 0 and 255. However, Matlab uses RGB values in the range between 0 and 1. So, if you want to specify the color black you have to use [0 0 0]
and for white [1 1 1]
.
但您可以使用RGB(红绿蓝)方案轻松创建自己的颜色。 RGB颜色由三个值定义,每个值描述相应颜色的强度。你可以只从这三种颜色中混合很多颜色(你的显示器现在显示的所有颜色很可能都是用RGB定义的)。通常RGB由3位定义,并且位具有256个值。因此,您的值可以取0到255之间的值。但是,Matlab使用0到1之间的RGB值。因此,如果要指定黑色,则必须使用[0 0 0]和白色[1] 1 1]。
RGB Colors can be found with google, just type in "RGB Table" in the image search and there you should find what you need. Since these tables often specify the colors in the 0-255 range, you can use these values and simply divide your vector by 255.
可以通过谷歌找到RGB颜色,只需在图像搜索中键入“RGB表”,您就可以找到所需内容。由于这些表通常指定0-255范围内的颜色,因此您可以使用这些值并简单地将矢量除以255。
Let me show you: Let's first define some colors we can use later on
让我告诉你:让我们先定义一些我们以后可以使用的颜色
color_red = [255 0 0]/255;
color_green = [0 255 0]/255;
color_blue = [0 0 255]/255;
color_orange = [255 102 0]/255;
color_pink = [204, 0, 102]/255;
Now our colors can simply be used like the ones integrated in matlab
现在我们的颜色可以像在matlab中集成一样使用
plot(x,y,'color', color_pink);
plot(x,y,'color', [0.8, 0, 0.4]); % Same as above