Multiple scatter3 in one figure

조회 수: 6 (최근 30일)
Bus141
Bus141 2016년 2월 1일
답변: Kiran 2016년 2월 10일
I am trying to plot three different scatter3 plots on a figure and have one legend for all three figures. I have written some generic code to replicate my data set. The difference for each figure should be the value in each column of w, (as shown by the code for each figure below). Any help is appreciated!
w=[randi(2,50,1),randi(3,50,1),randi(5,50,1)];
x=repmat((1:10)',5,1);
y=repmat((1:3:15)',10,1);
z=[ones(10,1);ones(10,1)+1;ones(10,1)+2;ones(10,1)+3;ones(10,1)+4];
p=rand(50,1)*75;
c=w(:,1);
%Figure 1
cVals=unique(c);
for i=1:length(cVals)
indices=find(c==cVals(i));
scatter3(x(indices),y(indices),z(indices),p(indices),'filled');
hold on
end
%Figure 2
c=w(:,2);
cVals=unique(c);
for i=1:length(cVals)
indices=find(c==cVals(i));
scatter3(x(indices),y(indices),z(indices),p(indices),'filled');
hold on
end
%Figure 3
c=w(:,3);
cVals=unique(c);
for i=1:length(cVals)
indices=find(c==cVals(i));
scatter3(x(indices),y(indices),z(indices),p(indices),'filled');
hold on
end

답변 (1개)

Kiran
Kiran 2016년 2월 10일
You need to put "drawnow()" function after each "for loop". This will update figure and process callback.
Refer following documentation for drawnow function:

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by