Hi, I have a matrix m (x, y, z) with a size of 12x6x5. I would like to reshape the matrix having other z-values given in f (5x1 vector). I have written the reshape command like this: g=reshape(f, [m],3) This is the error message: Error using reshape. Size arguments must be integer scalars. I don't understand the error. Thanks for your help!

댓글 수: 4

Adam
Adam 2017년 9월 19일
I don't understand what you are trying to do. Reshape simply changes the shape of one matrix as shown in
doc reshape
What you are wanting to do seems more complicated. Can you give an example of what you are trying to do and what result you are expecting from what inputs.
Azzi Abdelmalek
Azzi Abdelmalek 2017년 9월 19일
What is [m] ?
Star Strider
Star Strider 2017년 9월 19일
It appears that ‘m’ is the (12x6x5) original matrix.
We need to know the desired result.
anne d.
anne d. 2017년 9월 19일
@Azzi: m is the matrix with dimensions x, y, z (12x6x5) @Adam: x is longitude, y is latitude and z is depth. each x, y, z correspond to the center of the grid box. but i would like to use the top of each grid box instead of the center. therefore, i defined the top of each box in f, which is a 5x1 vector. all in all, i would like to use the same x and y values but the top of each box which is given in f.

댓글을 달려면 로그인하십시오.

 채택된 답변

Rik
Rik 2017년 9월 19일

0 개 추천

Assuming you want to change all 3rd dimension values to the vector f, this code should do what you want.
for n=1:length(f)
g(:,:,n)=f(n);
end
You can remove the loop by using repmat on the result of reshape(f,[1 1 5]) or permute(f,[2 3 1]).

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2017년 9월 19일

답변:

Rik
2017년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by