Creating Matrix using two vectors and scalar
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi guys,
I need your help in solving the following problem: Given a row vector, a column vector and an index create a matrix in the following manner (look at example) without using cell arrays and the implementation should be fast:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152741/image.png)
Remark: "index" correspond to the row column!
Thanks in advance.
댓글 수: 5
답변 (2개)
Andrei Bobrov
2015년 12월 17일
function out = fun1(r,c,ii)
out = ones(numel(c),1)*r;
out(:,ii) = c;
end
use
r = [2 7 3 5];
c = [2;7;10];
ii = 2;
out = fun1(r,c,ii);
댓글 수: 0
Kirby Fears
2015년 12월 17일
jack,
Please read the repmat() documentation to understand its interface and functionality. With repmat, you can stack copies of your row vector into a matrix.
You should be able to determine how many copies of your row vector to stack based on the length() or size() of your column vector.
From there, you just have to insert the column vector into the appropriate column using array indexing .
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!