Excel sheet mean of the row and plot the graph
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kristen Chappel
le 30 Mai 2021
Commenté : Scott MacKenzie
le 31 Mai 2021
Hi guys,
I have one excel file named as "Kendri" I wanted to do mean value of some of the column as below and plot the graph
Curve 1 :
X value vs Mean value of the (Elex1 Elex2 Elex3)
Curve 2 :
X value vs Mean value of the (John1 John2 John3)
Curve 1 :
X value vs Mean value of the (Henry1 Henry2 Henry3)
here mean value means, for example :- (Elex1 Elex2 Elex3)/3, also this mean sometimes shows the NAN value in the ouput, how can be the NAN output removed?
is it possible to do it through matlab ? you can see excel file in the question. Also i wanted to draw plot similar like attached picture.
Thanks a ton
1 commentaire
Réponse acceptée
Scott MacKenzie
le 30 Mai 2021
Modifié(e) : Scott MacKenzie
le 30 Mai 2021
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/635705/Kendri.xlsx');
x = T{:,1}; % x-axis conditions
y1 = mean(T{:,2:4}, 2); % Elex
y2 = mean(T{:,5:7}, 2); % John
y3 = mean(T{:,8:10}, 2); % Henry
plot(x, y1);
hold on;
plot(x, y2);
plot(x, y3);
labels = {'Elex', 'John', 'Henry' };
legend(labels);
It appears all the data are positive except for the values in the first and last rows. You can remove these values, if you wish, by changing
x = T{:,1}; % x-axis conditions
y1 = mean(T{:,2:4}, 2); % Elex
y2 = mean(T{:,5:7}, 2); % John
y3 = mean(T{:,8:10}, 2); % Henry
to
x = T{2:end-1,1}; % x-axis conditions
y1 = mean(T{2:end-1,2:4}, 2); % Elex
y2 = mean(T{2:end-1,5:7}, 2); % John
y3 = mean(T{2:end-1,8:10}, 2); % Henry
There are no NaN values in your spreadsheet.
2 commentaires
Scott MacKenzie
le 31 Mai 2021
If the data include NaN values, just use the omitnan option in the mean function. See Walter's comment.
The readtable function allows you to specify the sheet where the data are located. To read data from sheet 2, use
T = readtable( . . . , 'sheet', 2)
Good luck
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!