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 日

0 投票

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
Max Heimann
Max Heimann 2022 年 1 月 16 日
編集済み: Max Heimann 2022 年 1 月 16 日
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.
Max Heimann
Max Heimann 2022 年 1 月 16 日
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 2022 年 1 月 16 日
It worked! Thanks!!! :D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data 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