Merge arrays with different dimensions

2 次查看(过去 30 天)
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