Clear Filters
Clear Filters

Merge arrays with different dimensions

3 views (last 30 days)
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.

Accepted Answer

Torsten
Torsten on 17 Nov 2022
T(2:nx-1,2:ny-1) = Tini(2:nx-1,2:ny-1)

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!