Correlate a 3d array into n times 2d rows
3 views (last 30 days)
Show older comments
Hi
Was just wondering if there was a simple way to flatten a 2d array into correlation rows. Ok so here's an example:
I have n numbers of a 2d array as such:
a b c d e f
1 1.771 1.771 1.771 1.771 2.314 2.314
2 1.802 1.802 1.802 1.802 2.288 2.288
3 2.071 2.071 2.071 2.071 2.184 2.184
4 1.961 1.961 1.961 1.961 2.086 2.086
5 1.94 1.94 1.94 1.94 2.649 2.649
6 1.924 1.924 1.924 1.924 2.458 2.458
7 2.065 2.065 2.065 2.065 2.211 2.211
8 1.981 1.981 1.981 1.981 2.066 2.066
9 1.752 1.752 1.752 1.752 2.108 2.108
10 1.907 1.907 1.907 1.907 2.153 2.153
So say example here a 3d (6x10x n)
How can i correlate a1:a10, b1:b10 till f1:f10 so call them feature a1,a2,a3....f8,f9,f10 and do this for n rows. N rows of 60 features (a1,a2,a3...). Is there a simple matlab function ? Thank you for any help.
Answer for n rows is:
a1 a2 a3 a4 a5 … f8 f9 f10
n1 1.771 1.802 2.071 1.961 1.94 2.066 2.108 2.153
n2
n3
….
Kevin
2 Comments
Answers (1)
madhan ravi
on 12 Dec 2018
Edited: madhan ravi
on 13 Dec 2018
Don't even think of creating numbered variables use cell instead
matrix=yourmatrix';
n=size(matrix,1);
result=cell(1,n);
for i = 1:n
result{i}=matrix(i,:);
end
celldisp(result)
5 Comments
madhan ravi
on 13 Dec 2018
Edited: madhan ravi
on 13 Dec 2018
{ } instead of ( )
n=size(matrix,3);
^--change it to 3 from 1
result{i}=matrix{:,:,i}
If it's not what you are looking for attach your matrix as .mat file
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!