Read from an Excel File and assign index that have the max/min value

조회 수: 5 (최근 30일)
sohaib bakr
sohaib bakr 2020년 1월 4일
편집: dpb 2020년 1월 5일
Hello Evreyone >
If i am reading from an Excel file and let suppose that the Excel file contains 36 columns and 22 rows and i want to find the maximum for that table with its Location
I know how to find the maximum value but the thing that i don't know is how to get it is location of (row,column) !!!
for example let suppose that the maximum =0.77775 and it located
at Column =10 and Row = 12 i want it to give me the result like that:
the maximum =0.77775 at location Column =10 , Row = 12 .
and this is my code :
clc
clear all
Leakage_power_matrix = xlsread ('leakged_power_with_windows.csv') ;
Max_leakage_power = max(max(Leakage_power_matrix)) ;
fprintf('Maximum Leakage power is equal to= %f DB\n', Max_leakage_power ) ;
Regards.

채택된 답변

dpb
dpb 2020년 1월 4일
편집: dpb 2020년 1월 5일
Use the optional returned location variable and ind2sub to convert the position to coordinates. See the documentation; it shows examples.
[Max_leakage_power,loc]=max(Leakage_power_matrix(:));
[r,c]=ind2sub(size(Leakage_power_matrix),loc);
fmt='The maximum =%0.5f at location Column = %d, Row = %d.\n';
fprintf(fmt,Max_leakage_power,r,c);
Just noticed to refresh my memory of order of inputs; ind2sub should be in the See Also list for min,max
BTW, can eliminate the need for the (:) idiom if have R2018 or later by using the optional 'all' argument to return the global maximum.
NB: ERRATUM
The order of the row,column outputs are reversed relative to the format string in the order you wrote them as column, row...normally the row is given first and I just automatically wrote them in that order in the fprintf argument list...
Either swap them there or fix the format string to match the present order.
  댓글 수: 3
dpb
dpb 2020년 1월 4일
My bad...it's ind2sub you want here; not sub2ind. I wrote the correct one in the text but the wrong one in the code...
sohaib bakr
sohaib bakr 2020년 1월 4일
Thanks alot >>> it's works .

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by