Convert 2-D array to multidimensional array
Ältere Kommentare anzeigen
I have a 2-D array with 7 columns that I want to convert to a 6-D array of dimensions 16*20*22*6*3*2. The values in the first 5 columns of the 2-D array are the first 5 indices of the 6-D array and the values in the 6th and 7th columns of the 2-D array shall be contained in the 6th dimension of the 6-D array.
I tried the following
misc(rslts1(:,1:5),1:2) = rslts1(:,6:7)
where misc is the 6-D array and rslts1 is the 2-D array but got the error "Subscripted assignment dimension mismatch"
Akzeptierte Antwort
Weitere Antworten (2)
Steven Lord
am 6 Apr. 2016
0 Stimmen
Either use accumarray or sub2ind depending whether there are repeated values for the same coordinate that you want to accumulate or not.
Kuifeng
am 6 Apr. 2016
How about the function reshape? Take one column for example, Assume there is 126720 data. Make some changes for more columns.
a = rand([126720 1]);
a_5D = reshape(a,[16 20 22 6 3])
1 Kommentar
The only way that reshape would work is in the unlikely case that the indices in the first five columns happened to be ordered linearly with no gaps and no repetition. In that case, there actually would be no need for the 5 index columns.
Kategorien
Mehr zu Matrices and 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!