How to assign values to 100 by 2 matrix?
8 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!