Creating multiple plots from a data file using a for loop
Afficher commentaires plus anciens
Hi all,
I am very new to Matlab, and I am trying to plot multiple figures from a dataset using a for loop.
However, it's not working and I don't how to solve it.
The idea is that the loop plots 42 different figures (one for each participant), and that the first figure contains the data from the 1:14 row from columns 3 (x-axis) and column 5 (reaction times), figure 2 should contain the data from the 15:28 row from columns 3 (x-axis) and column 5 (y-axis), etc..
Below is the code that I have used:
Thai_UniversalPictures_Categorization = readtable('Thai_UniversalPictures_Categorization.xlsx'); % This is the table with the data
figure;
hold on;
for i = 1 : 14 : 588(Thai_UniversalPictures_Categorization); % I would like 42 figures
x = Thai_UniversalPictures_Categorization(i:1+13, 3); % The x-axis should contain the picture's names, which are located in the third column of the data file. The i:1+13 was written as an attempt to tell the code it's a loop and that it should take the first 14 pictures' names for the first figure, the next 14 pictures for the second figure etc.
y = Thai_UniversalPictures_Categorization(1:1+13, 5); % The y-axis should contain reaction times , which are located in the fifth column of the data file. The i:1+13 was written as an attempt to tell the code it's a loop and that it should take the first 14 reaction times for the first figure, the next 14 reaction times for the second figure etc.
plot(x,y);
end
I get an error which says:
Error using tabular/plot
Too many input arguments.
Error in outlierplots (line 11)
plot(x,y);
I hope you can follow my explanation and help me.
Best regards, Anne
6 commentaires
KSSV
le 10 Juil 2019
Tell us what does
whos x y
shows up?
Anne Reuten
le 10 Juil 2019
KSSV
le 10 Juil 2019
YOu cannot input table to plot.....you can access the data data using:
x.(1)
y.(1)
But note that, your tables are of different size......to plot, the data should be of same size.
Anne Reuten
le 10 Juil 2019
Modifié(e) : Anne Reuten
le 10 Juil 2019
Anne Reuten
le 10 Juil 2019
Modifié(e) : Anne Reuten
le 10 Juil 2019
Anne Reuten
le 10 Juil 2019
Réponse acceptée
Plus de réponses (2)
KALYAN ACHARJYA
le 10 Juil 2019
plot(x',y');
Shubham Sangle
le 10 Juil 2019
0 votes
You can use this,
() indexing on a table returns a portion of a table as a table
plot(table(:, column1), table(:, column2))
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!