1つの行列を等間隔の​列に分割し、それぞれ​の要素を足し合わせる​にはどうしたらよいで​すか?

A = rand(10 ,1000)
のような10行、1000列の行列 A が存在した時、
B = A(: ,1:100) + A(: ,101:200) + ... + A(: ,901:1000)
となる行列B(10行、100列) を求めるにはどうしたらよいでしょうか。

 Respuesta aceptada

Akira Agata
Akira Agata el 5 de Sept. de 2018

3 votos

reshape 関数をうまく使うと、以下のように簡単に求めることができます。
A2 = reshape(A,[10,100,10]);
B = sum(A2,3);

1 comentario

Ryo
Ryo el 6 de Sept. de 2018
ありがとうございます。助かりました。

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Versión

R2017b

Preguntada:

Ryo
el 5 de Sept. de 2018

Comentada:

Ryo
el 6 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!