Borrar filtros
Borrar filtros

ある特定の数値のある行列の位置を検出

93 visualizaciones (últimos 30 días)
Saito
Saito el 29 de Dic. de 2019
Respondida: Saito el 29 de Dic. de 2019
例えば、列に1 3 5 7 2 3 5 9 4 6 11 4 12 2 13 などという数値がある中で、3 がある列の位置を検出するにはどうしたら良いですか?

Respuesta aceptada

Musashi Ito
Musashi Ito el 29 de Dic. de 2019
string 配列でテキスト表現に変換して 3 が含まれる列の位置が検出できそうですが、いかがでしょうか。
a = [1 3 5 7 2 3 5 9 4 6 11 4 12 2 13]
% string 配列に変換
a_str = string(a)
% contains 関数で 3 を含む列の位置を検出。 0,1 の論理インデックスとして取得できる。
idx_3 = contains(a_str,"3")
% 数値配列 a から 3 の列だけを抽出
a_3 = a(idx_3)
  2 comentarios
Kenta
Kenta el 29 de Dic. de 2019
a=[1 3 5 7 2 3 5 9 4 6 11 4 12 2 13];
find(a==3)
こんにちは。こちらでもよさそうです。
Musashi Ito
Musashi Ito el 29 de Dic. de 2019
すみません、3 が含まれる数字(3,13 など) の列の位置を検出する場合は、最初のプログラムです。3 と等しい列の位置を検出する場合は、 Kenta さんがコメントしたプログラムです。

Iniciar sesión para comentar.

Más respuestas (1)

Saito
Saito el 29 de Dic. de 2019
お二人とも有難うございます。解決しました。

Categorías

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

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!