Reputation: 11
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:
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
Upvotes: 0
Views: 156
Reputation: 1190
example: Assuming you want to plot different data y1 and y2 against the same vector x, you can do
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.
hold on
tells matlab to not overwrite the old plot with the new one. Otherwise only the latest plot would be visible.
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 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.
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
plot(x,y,'color', color_pink);
plot(x,y,'color', [0.8, 0, 0.4]); % Same as above
Upvotes: 2
Reputation: 35525
To plot more things in the same axes use 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);
Upvotes: 3