How to use scatterplot in a loop

Hi all,
I have two data sets which are matrixes 100x18 double.
I want to scatterplot:
column 1(data1) vs column 1 (data2)
column 2(data1) vs column 2 (data2)
....
column 18 (data 1) vs column 18(data2)
The below:
for g=1:length(Data2) %for each column
scatter(Data1(g), Data2(g));
end
produces:
I would like these data sets plotted in diffrent colours. Can you help please?

 Respuesta aceptada

Simon Chan
Simon Chan el 18 de Mzo. de 2022
Try this:
clear;clc;
Data1 = reshape(1:100*18,[],18);
Data2 = randi([50 100],100,18);
c = repmat(linspace(1,10,18),100,1);
scatter(Data1(:),Data2(:),[],c(:));

5 comentarios

@Simon Chan Thanks!
So the below produces what I want but cant get the two data sets in diffrent colours:
for k=1:size(Data1,2)
% for k=1
c = repmat(linspace(1,10,18),100,1);
figure(k)
scatter(Data1(:,k),Data2(:,k),[],c(:,k))
end
Simon Chan
Simon Chan el 18 de Mzo. de 2022
Do you want two colors or 18 different colors?
Tomaszzz
Tomaszzz el 18 de Mzo. de 2022
two
If everything plot into one figure, see below:
Or do you want to plot them in separate figures?
Data1 = randi([1 50],100,18); % Value for dummy data from 1 to 50 (Set #1)
Data2 = randi([50 100],100,18); % Value for dummy data from 50 to 100 (Set #2)
scatter(1:1800,Data1(:),[],[1 0 0]); % 1st set
hold on
scatter(1:1800,Data2(:),[],[0 1 0]); % 2nd set
hold off
Tomaszzz
Tomaszzz el 18 de Mzo. de 2022
Thanks @Simon Chan your first answer is what actually wanted

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 18 de Mzo. de 2022

Comentada:

el 18 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by