行列の大きさをそろえる

A = [5 2 3]
B = [6 9 4 1 4]、、
と様々な大きさの行列が数十種類あります。これらの行列を1行10列の行列に揃えたいです。
大きくした分は0などで補えれば良いかなと思っているのですが何か解決策有りますでしょうか。
A = [5 2 3 0 0 0 0 0 0 0]
B = [6 9 4 1 4 0 0 0 0 0]、、、

 Respuesta aceptada

Keito Endo
Keito Endo el 4 de Oct. de 2021

0 votos

ありがとうございます。
解決できました。

Más respuestas (1)

Toru Ikegami
Toru Ikegami el 3 de Oct. de 2021

1 voto

こんにちは,元の行列のサイズは全て1行n列(n < 10)だと仮定しての解決策になりますが,
A = [ 3 2 3]
A = 1×3
3 2 3
B = [ 6 9 4 1 4]
B = 1×5
6 9 4 1 4
に対して,
A(end+1:10) = 0
A = 1×10
3 2 3 0 0 0 0 0 0 0
B(end+1:10) = 0
B = 1×10
6 9 4 1 4 0 0 0 0 0
でそれぞれ1行10列の行列になります.(空いている要素は0で補っています)

Categorías

Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 3 de Oct. de 2021

Respondida:

el 4 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!