Excel sheet mean of the row and plot the graph
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kristen Chappel
el 30 de Mayo de 2021
Comentada: Scott MacKenzie
el 31 de Mayo de 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 comentario
Respuesta aceptada
Scott MacKenzie
el 30 de Mayo de 2021
Editada: Scott MacKenzie
el 30 de Mayo de 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 comentarios
Scott MacKenzie
el 31 de Mayo de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!