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 Center および File ExchangeResizing 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