How does this vector expanding work?

Good night, I'm trying to understand how a vector can expand to a matrix using a vector formed by ones. Here is the example I'm trying to understand:
xx = [1 2 3]; yy = xx(ones(3,1),:);
I don't know how the part of xx(ones(3,1),:) works, and it would be great if you could explain it to me. The result of this operations is a 3x3 matrix:
1 2 3
1 2 3
1 2 3
Thank you!

 채택된 답변

Sean de Wolski
Sean de Wolski 2012년 10월 2일

2 개 추천

Think about it this way:
x = [1 2;3 4];
to index the first row of this, you would use:
x(1,:)
If you wanted to index the 2nd row then the first row:
x([2 1],:)
What you're doing above is essentially:
x([1 1 1],:)

댓글 수: 1

Daniel
Daniel 2012년 10월 3일
I've finally understood it! Thank you, it has been very useful!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by