How to build two shapes in MATLAB

I am implementing a clustering algorithm for n data points, and I want to plot n data points in a figure before clustering and in another figure after clustering, which means that there must be two figures in the same file with the same data points.

My code is similar:

 X = 500*rand([n,2]); plot(X(:,1), X(:,2), 'r.') 1 %Some coding section here 

After:

 symbs = {'r+','g.','bv','m*','ko'}; hold on for i = 1: length(I) plot(X(C==i,1), X(C==i,2), symbs{i}) 2 end 

I just want to build (1) in one drawing and (2) in another.

+6
source share
1 answer

Try subplot :

 figure; subplot(1,2,1) plot(firstdata) subplot(1,2,2) plot(seconddata) 

This will create two axis areas inside the same shapes window ... from your description, this is my best guess about what you want.

Edit: from the comments below, here is what you do

 n=50; X = 500*rand([n,2]); subplot(1,2,1); #% <---- add 'subplot' here plot(X(:,1),X(:,2),'r.') symbs= {'r+','g.','bv','m*','ko'}; subplot(1,2,2); #% <---- add 'subplot' here (with different arguments) hold on for i = 1: length(I) plot(X(C==i,1),X(C==i,2),symbs{i}) end 

If all you need is a second figure window, instead of doing subplot , you can just say figure in the place where I put the second subplot call and a new figure window will be created.

 figure; #% <--- creates a figure window n=50; X = 500*rand([n,2]); plot(X(:,1),X(:,2),'r.') #% <--- goes in first window symbs= {'r+','g.','bv','m*','ko'}; figure; #% <---- creates another figure window hold on for i = 1: length(I) plot(X(C==i,1),X(C==i,2),symbs{i}) #% <--- goes in second window end 
+17
source

Source: https://habr.com/ru/post/916792/


All Articles