How can I shape a column vector into a matrix?

Hello everyone,
with the following code I calculate the mean of each of the 25 columns of a matrix and then order the resulting 1x25 array into a 5x5 matrix. The code is working but I was wondering if there is a shorter way to achieve the desired result.
meanv = mean(ERFF25USshort);
mat=ones(5,5);
mat(1,:) = meanv(1:5)
mat(2,:) = meanv(6:10)
mat(3,:) = meanv(11:15)
mat(4,:) = meanv(16:20)
mat(5,:) = meanv(21:25)
Thanks in advance!

 채택된 답변

Bruno Luong
Bruno Luong 2018년 10월 23일
편집: Bruno Luong 2018년 10월 23일

0 개 추천

mat = reshape(mean(ERFF25USshort),[5 5]).'

추가 답변 (1개)

Torsten
Torsten 2018년 10월 23일

0 개 추천

mat = (reshape(meanv,5,5)).'
Best wishes
Torsten.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2018년 10월 23일

댓글:

2018년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by