Python Argmin function in MATLAB ( Finding an indexing in AxBxC array in specific colomn)

I have an matrix as dimensions 11x360x1360. I have to find the minimum indexes in each (11) column. In python i can do this operation with np.argmin(abs(x),axis = 0)). How can i do that in MATLAB? I have to search minimum index in 1x360x1360,2x360x1360 and my output should be 360x1360 and values in output should be 1,2,3,4,5,6,7,8,9,10,11('11' values).

回答 (1 件)

Aditya Patil
Aditya Patil 2020 年 9 月 22 日
You can pass the linear option of the min function when you want to find the index of the minimum over multiple dimensions. Then use the ind2sub function to get subscript indices from the linear one's.
matrix = rand([11,360,1360]);
[value, index] = min(matrix, [], [2, 3], 'linear');
[I1, I2, I3] = ind2sub(size(matrix), index);

9 件のコメント

Emre Can Ertekin
Emre Can Ertekin 2020 年 9 月 22 日
not working
Aditya Patil
Aditya Patil 2020 年 9 月 23 日
can you elaborate the issue you are facing?
Emre Can Ertekin
Emre Can Ertekin 2020 年 9 月 23 日
Error using min
Dimension argument must be a positive integer scalar within indexing range.
i get this error
Aditya Patil
Aditya Patil 2020 年 9 月 24 日
What version of MATLAB are you using?
Emre Can Ertekin
Emre Can Ertekin 2020 年 9 月 24 日
I have R2018a
Emre Can Ertekin
Emre Can Ertekin 2020 年 9 月 24 日
I upgrade my MATLAB to 2020b. But in result of this code i have again 11x360x1360 matrix in I1, I2,I3. But i need 360x1360 matrix and when I print for example A(129,398) = 1 or A(138,293) = 9 etc. This is not work for me
You can get the 360x1360 matrix by providing only the first dimension as such,
A(1,:,:)
If you want to change a specific value, then provide all three indices. You can also use the linear indices for this.
Emre Can Ertekin
Emre Can Ertekin 2020 年 9 月 25 日
this is not work for me, A(1,:,:) is 1x360x1360 array i need 360x1360 and output of A(1, : , :) is 1 2 3 4 5 6 7 8 9 10 11; i need one number. like 1 or 7. I try to made it in for loop thank you anyway.
Aditya Patil
Aditya Patil 2020 年 9 月 28 日
You can use reshape to change it to 360x1360.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2018a

質問済み:

2020 年 9 月 17 日

コメント済み:

2020 年 9 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by