各次元内の最大値を線​形インデックスを含む​ベクトルで返す方法

6 visualizaciones (últimos 30 días)
翔 池田
翔 池田 el 26 de Mayo de 2021
Respondida: TT el 26 de Mayo de 2021
A(:,:,1)=[2 , 3]
A(:,:,2)=[4 , 3]
A(:,:,3)=[7 , 3]
とした1×2×3行列において
各次元の最大値を線形インデックスで返す方法を教えてください.
この際,for文を用いずにしたいです.
出力結果としては変数Xとすると
X(:,:,1)=2
X(:,:,2)=1
X(:,:,3)=1
としたいです.宜しくお願い致します.

Respuestas (1)

TT
TT el 26 de Mayo de 2021
こちらはいかがでしょうか.
[~,idx]=max(A,[],2)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!