Excel sheet mean of the row and plot the graph

12 views (last 30 days)
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

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 30 May 2021
Edited: Scott MacKenzie on 30 May 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 Comments
Kristen Chappel
Kristen Chappel on 31 May 2021
Edited: Kristen Chappel on 31 May 2021
Thank u, @Scott MacKenzie. What if value is NAN then what should i change in the code? Also if some datas available in the same file but sheet 1, 2 , 3 then how to take that variable in the code. Just example you can see in the below attached excel file
Thanks a lot
Scott MacKenzie
Scott MacKenzie on 31 May 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

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!