Expand Elements in a Table/Matrix

Sorry i re-post, I was not able to find an answer for this.
Let's say I have a matrix A, where the 1st row and column would be indexes.
A =
0 1 2 3
10 5 6 9
20 5 23 6
30 3 4 7
How would I expand it to all the combination of row x column values with out using loops. Like bellow:
A_Elements=
1 10 5
1 20 5
1 30 3
2 10 6
2 20 23
2 30 4
3 10 9

댓글 수: 3

Walter Roberson
Walter Roberson 2011년 5월 16일
What determines how often each item should be repeated?
Walter Roberson
Walter Roberson 2011년 5월 17일
Should that have continued with
3 20 9
3 30 7
?
Carlos C
Carlos C 2011년 5월 17일
The answer A_Elements is what the answer needs to be. Essentially think of the values in row 1 to be "x" values and column 1 to be the "y" values and the values in the middle to be z(x,y)

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 17일

0 개 추천

my variant
[j i] = meshgrid(A(1,2:end),A(2:end,1));
A_Elements2 = [j(:) i(:) reshape(A(2:end,2:end),[],1)]

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 5월 17일

0 개 추천

[reshape(repmat(A(1,2:end),size(A,1)-1,1),[],1), repmat(A(2:end,1),size(A-1)-1,1), reshape(A(2:end,2:end),[],1)]

댓글 수: 1

Carlos C
Carlos C 2011년 5월 17일
I get this error when running this script:
"??? Error using ==> horzcat
CAT arguments dimensions are not consistent."

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

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by