How to transform an array into a bottom triangle

조회 수: 5 (최근 30일)
Prabhjot Dhami
Prabhjot Dhami 2019년 6월 22일
편집: dpb 2019년 6월 22일
Dear Matlab community,
I have an array by the size of 11175 x 1 elements. These values come from a bottom triangle, which was created from a 149 x 149 matrix. My problem is I would like to get the vector of the last row and all the columns (so (149,:)) of the original matrix. If I could somehow transform this 11175 element array into the original matrix, I could get the values I want, but I'm having trouble as to how to do such a transformation. Any help would be greatly appreciated.
Thank you,
Paul
  댓글 수: 2
dpb
dpb 2019년 6월 22일
Depends on how the vector was created -- what's the storage order? Is it the normal ML column-major?
Prabhjot Dhami
Prabhjot Dhami 2019년 6월 22일
Dear dpb,
Yes, I beleive so it's in the column-major. I could verify the transformation because I do have the original matrix, but only as a plot where I can see the values.

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

채택된 답변

dpb
dpb 2019년 6월 22일
편집: dpb 2019년 6월 22일
On the above assumption, if V is the vector, then
N=149; % array size parameter
R=V(cumsum([N:-1:1])); % last row elements from vector
The difference between locations in the tril() vector of nonzero elements is just one less than that previous for each column; the first location in the vector for the Nth row is the Nth element so the last is just the size.
  댓글 수: 4
Prabhjot Dhami
Prabhjot Dhami 2019년 6월 22일
I'm sorry, I believe it was row - major, any chance you could provide your answer for that format instead of row?
dpb
dpb 2019년 6월 22일
편집: dpb 2019년 6월 22일
Show how that would have been generated...what would be the V you would have from the above example?
ADDENDUM
Presuming the actual array is as the example (only larger, but absolute number of elements is immaterial), it's pretty difficult to generate the same tril() elements but from the opposite order--BUT if that is what was actually done, then the result is simply the last N values of the vector...
R=V(end-N+1:end);
Attach the actual dataset (or, even better, a smaller one so not so much to look at) that illustrates the actual storage order for the matrix in question. It's not unheard of that perhaps there's an error in having generated the data vector itself that makes for unexpected result, too, of coure.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 6월 22일
squareform() ?
  댓글 수: 2
Prabhjot Dhami
Prabhjot Dhami 2019년 6월 22일
Hi Walter,
thanks for the suggest, but I'm getting a 150 x 150 matrix with this solution, instead of the original 149 x 149. Any reason for that?
dpb
dpb 2019년 6월 22일
squareform is specific to pdist function in that it returns a 0 diagonal as well. No way I can see to not return that. But, you could simply acknowledge it being there and use
S=squareform(V);
R=S(end,1:end-1);

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by