How can I create multiple scatter3 figures for each k-value?

2 views (last 30 days)
I'm trying to plot different scatter3 graphs for each of the different k-values. The code below just gives me the same graph seven times with all the data for the all k-values on each graph (instead of separating it). How do I get the loop to plot a new figure for each k-value?
For the sake of this question, please ignore the boxplot stuff, I'm assuming that whatever is applied for this problem to the scatter3, I'll end up applying to the boxplot problem as well.
load('../output/kmeans_clustering','S','LesAll')
for k = 4:10 % recalculate clustering for those k
for irep = 1:50
Idx(:,irep) = kmeans(S,k);
end
d = agreement(Idx)/50; % build agreement matrix
ciu = consensus_und(d,0.5,250); % consensus clustering
load('../mat/coor.mat') % where the coor nodes are stored
x = coor(:,1); % correspond xyz to values on coor
y = coor(:,2);
z = coor(:,3);
figure
hold on
scatter3(x,y,z,100,ciu); % make fig; ciu choooses the colors
LA = mean(LesAll,2); % matrix storing the avg of lesion masks
figure
boxplot(LA,ciu);
end

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 2 May 2020
Try running the following code and check whether you are getting different plots or not:
close all
for i=4:6
[X,Y,Z] = sphere(i^2);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
S = repmat([50,25,10],numel(X),1);
C = repmat([1,2,3],numel(X),1);
s = S(:);
c = C(:);
figure
hold on
scatter3(x,y,z,s,c)
figure
xx = randn(100,25);
boxplot(xx)
end
If you are getting different plots then I would suggest you to check the values of x,y,z,ciu provided to the the scatter3 function w.r.t different k values whether they are same or not.

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!