Assigning a 2D matrix
34 次查看(过去 30 天)
显示 更早的评论
I have to create a 2D matrix, where the row number is unknown. I will have to find the row number.
Say, for i=1:5
for j=1:3
I want to create a 2D matrix with 2 columns, where the entries will be like [i j]
How should I write the code?
2 个评论
Raj
2019-5-31
Your question is not at all clear. What exactly are you looking for? Can you give a better example?
采纳的回答
KSSV
2019-5-31
If you know column numbers and don;t know row number; you can initialize as below;
iwant = zeros([],col) ;
If you know row numbers and dont know column number; you can initialize as below;
iwant = zeros(row,[] ;
But, it seems in your case:
iwant = zeros(5,3) ;
for i=1:5
for j=1:3
iwant(i,j) = rand ;
end
end
另请参阅
类别
在 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!