Read from an Excel File and assign index that have the max/min value
5 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
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...
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!