How do I add a expand a dimension of a matrix by adding an additional value to the dimension but add it to the dimension in a specific order using an index?

1 visualizzazione (ultimi 30 giorni)
I have a 20 X 751 X 1500 matrix that contains a list of temperatures in the first dimension at each point on a 751 X 1500 grid. Those temperatures are in a specific order at each grid point. Call this matrix A.
I also have a 1 X 751 X 1500 matrix that contains a temperature in the first dimension that I'd like to concatenate onto matrix A. Call this matrix B.
I also have a 1 X 751 x 1500 matrix that contains an index at which I want to add the value in matrix B on to Matrix A. Call this matrix C.
For example, in Matrix A at grid point 200 X 200 I have the following temperatures:
59
50
45
40
37
30
25
22
20
15
11
10
7
6
2
1
0
-1
-4
-6
In Matrix B, at grid point 200 X 200 I have a temperature I'd like to add to Matrix A. That temperature is 42.
In Matrix C, at grid point 200 X 200 I have an index value that describes where I want the value in Matrix B to be added to Matrix A to create a new matrix. That index value is 2. So, the combination of Matrix A and B at 200 X 200 should yield:
59
42
50
45
40
37
30
25
22
20
15
11
10
7
6
2
1
0
-1
-4
-6
The end result of this code would be a 21 X 751 X 1500 matrix, which is the combination of matrix A and B, where B combined with A that the index describe by the index value in Matrix C.
I can do this using a loop but am wondering if there's a shorter, more efficient matrix command to do it?
Thanks Joe

Risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by