필터 지우기
필터 지우기

How to assign values to 100 by 2 matrix?

조회 수: 8 (최근 30일)
Robin Li
Robin Li 2019년 5월 15일
댓글: Robin Li 2019년 5월 15일
I have a matrix (2,3); how could I initialize a 100 by 2 matrix with the first column all=2 and second column all=3.
Thank you!

채택된 답변

madhan ravi
madhan ravi 2019년 5월 15일
편집: madhan ravi 2019년 5월 15일
By the looks of the question probably you want:
% if you want first columns with 2 and the other as 3 then
ones(100,2).*[2,3] % since 2016b
bsxfun(@times,ones(100,2),[2,3]) % prior 2016b
By basic indexing [if you want to feed in the 2 by 3 matrix to a 100 by 2 matrix] then:https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html :
a=rand(2,3); % example
[m,n]=size(a);
b=zeros(100,2);
b(1:n,:)=a'
  댓글 수: 1
Robin Li
Robin Li 2019년 5월 15일
yea. I was asking for if the matrix is (2 3). Thank you!

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

추가 답변 (2개)

Raj
Raj 2019년 5월 15일
편집: Raj 2019년 5월 15일
A=[2 3]
A1=[A(1)*ones(100,1) A(2)*ones(100,1)]

Murugan C
Murugan C 2019년 5월 15일
x=ones(100,2);
x(1:end,1) =2;
x(1:end,2) =3;
Try the above code.
Thanks in advance!!!

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by