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.

 채택된 답변

Max Heimann
Max Heimann 2022년 1월 16일
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

MBM
MBM 2022년 1월 16일
편집: MBM 2022년 1월 16일
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
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 2022년 1월 16일
편집: MBM 2022년 1월 16일
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?
It worked! Thanks!!! :D

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scatter Plots에 대해 자세히 알아보기

질문:

MBM
2022년 1월 16일

편집:

MBM
2022년 1월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by