필터 지우기
필터 지우기

Excel sheet mean of the row and plot the graph

조회 수: 3 (최근 30일)
Kristen Chappel
Kristen Chappel 2021년 5월 30일
댓글: Scott MacKenzie 2021년 5월 31일
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

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 5월 30일
편집: Scott MacKenzie 2021년 5월 30일
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
Kristen Chappel
Kristen Chappel 2021년 5월 31일
편집: Kristen Chappel 2021년 5월 31일
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 2021년 5월 31일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by