How to find "maximum" value in a table

How to find "maximum" value in a table and to extract the other data's based on maximum value (i.e maximum value row):
I have a table with 6 columns as shown below
Calcul = table;
Calcul.Element = cell2mat(raw(:, 1));
Calcul.Tau = cell2mat(raw(:, 2));
Calcul.Pressure = cell2mat(raw(:, 3));
Calcul.VMStress = cell2mat(raw(:, 4));
Calcul.SPmax = cell2mat(raw(:, 5));
Calcul.SPmin = cell2mat(raw(:, 6));
I need to find a maximum value/cell of a particular column and to extract all the data from these 6 columns (i.e row of a particular cell) as attached in the image.
Please help me
Thanks in advance

댓글 수: 4

Stephen23
Stephen23 2018년 6월 5일
Wouldn't that be easier with cell2table ?
Lal
Lal 2018년 6월 5일
편집: Lal 2018년 6월 5일
I used "import data". Let me know if I can do in a easy way. Thanks for your reply
Lal
Lal 2018년 6월 5일
편집: Lal 2018년 6월 5일
VM_max = max(Calcul.VMStress);
VM_max
This is giving maximum of 4th column. How do I extract the row (VM_max) ?
Thanks in advance
Peter Perkins
Peter Perkins 2018년 6월 7일
Stephen's comment was just that you have six lines to create six table variables, and because each of those six references a column in the same cell array, you could replace all those with one call to cell2table.

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

 채택된 답변

Razvan Carbunescu
Razvan Carbunescu 2018년 6월 5일

2 개 추천

Can accomplish this easier with indexing
>> T = readtable('test1.txt');
>> [~,maxidx] = max(T.SPmin);
>> T(maxidx,:)
ans =
1×6 table
Element Tau Pressure VMStress SPmax SPmin
_______ ______ ________ ________ ______ ______
54281 2.5304 -3.6719 4.479 6.5101 1.4493

댓글 수: 2

Lal
Lal 2018년 6월 5일
편집: Lal 2018년 6월 5일
Thank you for your answer. Could you please explain me how the code is working?
Thank you
Razvan Carbunescu
Razvan Carbunescu 2018년 6월 5일
The second line computes the max of T.SPMin and stores the position where that max is found in maxidx. Then via table indexing on the 3rd line can find the result.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

질문:

Lal
2018년 6월 5일

댓글:

2018년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by