How to plot scattered data YZ with diffrent color for each slice X of 3 dim matrix XYZ

1 次查看(过去 30 天)
How to plot scattered data YZ with diffrent color for each slice X of 3 dim matrix XYZ ?
There are two F1 F2 matrices (3 dimensional) with same dimensions.
scattered plot scatter(F1(:), F2(:)) will plot all the data with same color.
I would like slice 'k' index in one of the dimensions (let say X) to be colored with same color and the color to change for the values of k.
the code below works however if has two loops .
n = [1:1:10]; % X
m = [1:1:3]; % Y
z1 = rand(1,20);
z2 = rand(1,20);
zr1 = reshape(z1,1,1,[]); % Z
zr2 = reshape(z2,1,1,[]); % Z
F1 = meshgrid(n,m).*zr1; %XYZ
F2 = meshgrid(n,m).*zr2; %XYZ
C = jet(length(n))
for en = 1:length(n)
for pll = 1:length(m)
scatter(reshape(F1(pll,en,:),1,[]),reshape(F2(pll,en,:),1,[]),[],C(en,:)); % ? on one plot with different collor for slices in x
hold on
end
end

回答(1 个)

Adam Danz
Adam Danz 2020-7-12
编辑:Adam Danz 2020-7-15
I think you're describing this.
Cfull = repmat(repelem(C,size(F1,1),1),size(F1,3),1);
scatter(F1(:),F2(:),40,CFull,'filled')

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by