How do i plot N amount of rows into a point plot?

Guys, how do you plot multiple rows into a point plot?
Here's what i've done so far:
figure(2)
F = grades(1,:);
E = 1:width(grades);
scatter(E,F)
xlabel('Assignment','FontSize',15);ylabel('Grade','FontSize',15);
yticklabels({'-3','00','02','4','7','10','12'});
title ('Grades per assignment','FontSize',20);
In this code i only plot row 1 but what if i need to plot N Rows? I need to write a code where the input argument is an NxM Matrix.

 Respuesta aceptada

Max Heimann
Max Heimann el 16 de En. de 2022
Whats the content of your variable "grades"?
You can plot multiple lines one after the other with the hold command. (A,B,C,D,E,F are your data vectors)
figure('Name','Example Plot')
scatter(A,B)
hold on
scatter(C,D)
scatter(E,F)
...
You could simply loop over your matrix and plot each line like this.

5 comentarios

MBM
MBM el 16 de En. de 2022
Editada: MBM el 16 de En. de 2022
the content of the variable "grades" is a [NxM] matrix. I dont know how big the matrix is, but i need to make a code that can handle any type of matrix input.
Also i must add a small random number (between -0.1 and 0.1) to the x- and y-coordinates of each dot, to be able tell apart the different dots
Max Heimann
Max Heimann el 16 de En. de 2022
Editada: Max Heimann el 16 de En. de 2022
You can get the dimensions of you matrix with the "size" command.
[N,M] = size(grades)
Afterwards you could loop over N or M
for nn = 1:N
scatter((1:M) + (1 - 2 * rand) * 0.1 , grades(N,:) + (1 - 2 * rand) * 0.1 )
hold on
end
MBM
MBM el 16 de En. de 2022
Editada: MBM el 16 de En. de 2022
So i've made some changes to the code and now i'm able to plot all the rows from the matrix in the scatter plot. But my only problem now is that i need to add a small random number (between -0.1 and 0.1) to the x- and y-coordinates of each dot, to be able tell apart the different dots otherwise would be on top of each other when more than one student has received the same grade in the same assignment which is the case now.
I did account for that by adding
(1 - 2 * rand) * 0.1
To the data on each cycle. This should be a random number between -.1 and .1. Did this not work?
MBM
MBM el 16 de En. de 2022
It worked! Thanks!!! :D

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

MBM
el 16 de En. de 2022

Editada:

MBM
el 16 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by