필터 지우기
필터 지우기

Correlate a 3d array into n times 2d rows

조회 수: 3 (최근 30일)
Kevin Teh
Kevin Teh 2018년 12월 12일
편집: madhan ravi 2018년 12월 13일
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
madhan ravi
madhan ravi 2018년 12월 12일
example of your output?
Kevin Teh
Kevin Teh 2018년 12월 12일
Sure sorry say n number of rows:
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
.

댓글을 달려면 로그인하십시오.

답변 (1개)

madhan ravi
madhan ravi 2018년 12월 12일
편집: madhan ravi 2018년 12월 13일
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
Kevin Teh
Kevin Teh 2018년 12월 13일
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in addHeader (line 19)
result(i)=matrix(i,:);
my matrix is 165x165x59 cell
madhan ravi
madhan ravi 2018년 12월 13일
편집: madhan ravi 2018년 12월 13일
{ } 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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by