Merge arrays with different dimensions

조회 수: 2 (최근 30일)
Steffen B.
Steffen B. 2022년 11월 17일
편집: Steffen B. 2022년 11월 17일
Hello,
I have a small problem with an array.
I have an initial array with nx x ny positions, then I create another array with nx x ny positions, but I set only the Boundary values.
Afterward, I would like to merge the inner values from Tini (nx-2 x ny-2 positions, marked with a red rectangle in the picture below) into the inner area of the array T (marked with a blue rectangle in the image below).
nx=6;
ny=6;
Tini=300*ones(nx,ny)
TL=400;
TR=800;
TT=600;
TB=900;
T(2:ny-1,1)=TL;
T(2:ny-1,nx)=TR;
T(1,2:nx-1)=TT;
T(ny,2:ny-1)=TB;
T(1,1)=(T(2,1)+T(1,2))/2;
T(nx,ny)=(T(nx-1,ny)+T(nx,ny-1))/2;
T(1,ny)=(T(2,ny)+T(1,ny-1))/2;
T(nx,1)=(T(nx-1,1)+T(nx,2))/2;
The array addition works only with the same dimensions, but I don't want to overwrite the boundary values of T when I add Tini.
I am not sure how to achieve this. Maybe someone has a clue.

채택된 답변

Torsten
Torsten 2022년 11월 17일
T(2:nx-1,2:ny-1) = Tini(2:nx-1,2:ny-1)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by