任意サイズの単位ベクトルの作り方

任意サイズの単位ベクトルの作り方を教えてください。
a=[1,1,1,1,1,…]
簡単に作れる方法を知りたいです。

Respuestas (1)

Kojiro Saito
Kojiro Saito el 29 de Dic. de 2018

3 votos

onesを使う方法が最も簡単だと思います。1行n列の単位ベクトルを作成したい時、ones(1, n)で作成できます。
例えばnが20の時はこんな感じです。
n = 20;
a = ones(1, n);

2 comentarios

Masato Hayashi
Masato Hayashi el 11 de En. de 2019
できました。ありがとうございました!
Kojiro Saito
Kojiro Saito el 11 de En. de 2019
解決できてよかったです。差し支えなければ、回答の採用(accept)もポチッとお願いできますでしょうか。

Iniciar sesión para comentar.

Categorías

Más información sobre 行列および配列 en Centro de ayuda y File Exchange.

Productos

Versión

R2015b

Preguntada:

el 29 de Dic. de 2018

Comentada:

el 11 de En. de 2019

Community Treasure Hunt

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

Start Hunting!