Filter löschen
Filter löschen

Extracting along a dimension in a 4D array

25 Ansichten (letzte 30 Tage)
Prerna Mishra
Prerna Mishra am 30 Jun. 2022
Kommentiert: KSSV am 30 Jun. 2022
I have a 4D array of dimsension na*nk*nkprime*nd, each dimension representing, number of shock, number of capital today, number of capital tomorrow and number of debt recently. na = 11, nk = 121, nkprime = 121 and nd = 51. I was to extract the values from nk and nkprime positions when na = 2 and nd = 1;
I am doing the following:
V = Rmat(2,:,:,1)
Is this correct?

Akzeptierte Antwort

KSSV
KSSV am 30 Jun. 2022
YEs, it is correct. When you extract you will get 1x121x121 array. You may remove the extra dimension using squeeze.
na = 11; nk = 121 ; nkprime = 121 ; nd = 51 ;
A = rand(na,nk,nkprime,nd) ;
iwant = squeeze(A(2,:,:,1)) ;
  2 Kommentare
Prerna Mishra
Prerna Mishra am 30 Jun. 2022
Thanks! Could you help me plot the values of k againt kprime. Since this would be a 2-D array after squeezing, it is giving me errors.
KSSV
KSSV am 30 Jun. 2022
A 2D array can be plotted using pcolor, surf

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by