Create a 4D array from 3D data set and a 2D variable location index
Ältere Kommentare anzeigen
Hello, I am having some problems getting my head around creating a 4D array, and would appreciate some help with the fine tuning!
I have a set of 36 data sets, each of which is a 250 x 2 array. These comprise 12 readings, each repeated twice (so there are 3 sets of each reading which I will use to calculate a mean). These data sets are stored in data which is a 250 x 2 x 36 variable. I also have a matrix A which gives the location index of each 250 x 2 data set when I read them all in using a combination of files=dir() and dlmread(files.name). A looks like this:
A = [2 8 3 9 4 10 5 11 6 12 7 1;
14 20 15 21 16 22 17 23 18 24 19 13 ;
26 32 27 33 28 34 29 35 30 36 31 25];
I would like to create a 4D matrix out of my 2D data sets by having a 3rd dimension which is the 12 different readings, and a 4th dimension which is the 3 incidences of each set.
So far I have used the cat() function in this way:
set= cat(4, data(:,:,A(1,:)), data(:,:,A(2,:)), data(:,:,A(3,:)));
I am sure though that there must be a more elegant way to do this without manually typing out 'data(:,:,A(1,:))' etc as this would not work if I had many more repeats.
Is there a better way for me to do this? I thought set= cat(4, data(:,:,A)) might work, but it takes A as a 1D list rather than a 2D matrix.
Thank you for your time!
2 Kommentare
Azzi Abdelmalek
am 29 Dez. 2014
I think you can make your question more clear if you post a simple and short example, and avoid describing things that will not help.
ML
am 30 Dez. 2014
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!