필터 지우기
필터 지우기

MxM correlation Matrix output

조회 수: 3 (최근 30일)
Evans Gyan
Evans Gyan 2018년 11월 23일
댓글: Evans Gyan 2018년 11월 23일
Given a vector
Vec = [ 0 1 2 3 4 5 6 7 8 9 ]
I want to use the vec value to obtain a matrix output as
0 1 2 3 4 5 6 7 8 9
1 0 1 2 3 4 5 6 7 8
2 1 0 1 2 3 4 5 6 7
3 2 1 0 1 2 3 4 5 6
mat = 4 3 2 1 0 1 2 3 4 5
5 4 3 2 1 0 1 2 3 4
6 5 4 3 2 1 0 1 2 3
7 6 5 4 3 2 1 0 1 2
8 7 6 5 4 3 2 1 0 1
9 8 7 6 5 4 3 2 1 0
Your input is highly appreciated. Thanks in advance

채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 11월 23일
toeplitz(vec)
  댓글 수: 1
Evans Gyan
Evans Gyan 2018년 11월 23일
Thank you Andrei. You really saved me the headache. It worked

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

추가 답변 (1개)

John D'Errico
John D'Errico 2018년 11월 23일
편집: John D'Errico 2018년 11월 23일
What does that even remotely have to do with a covariance matrix? :)
Now, IF your goal really is just to create that array, then try this:
vec = 0:9;
abs(vec - vec')
ans =
0 1 2 3 4 5 6 7 8 9
1 0 1 2 3 4 5 6 7 8
2 1 0 1 2 3 4 5 6 7
3 2 1 0 1 2 3 4 5 6
4 3 2 1 0 1 2 3 4 5
5 4 3 2 1 0 1 2 3 4
6 5 4 3 2 1 0 1 2 3
7 6 5 4 3 2 1 0 1 2
8 7 6 5 4 3 2 1 0 1
9 8 7 6 5 4 3 2 1 0
The above will work as long as you are using at least R2016b or MATLAB. Older releases will require tools like bsxfun, or even meshgrid.
It is a bit unclear because again, this has nothing to do with a covariance matrix, except that both are symmetric matrices.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by