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

1 view (last 30 days)
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

Answers (1)

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

Tags

Products

Community Treasure Hunt

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

Start Hunting!