Matrix and For?
显示 更早的评论
for i=1:n
a=input('a=');
b=input('b=');
end
i want to create a matrix whose name is 'C'. C matrix should be formed;
C=[a1
b1
a2
b2
.
.
.
an
bn
]
How can i do it?
采纳的回答
更多回答(1 个)
Star Strider
2015-11-20
编辑:Star Strider
2015-11-20
One way:
n = 3;
C = zeros(1,2*n);
for i=1:n
ai=inputdlg('a=');
a(i) = str2double(ai);
bi=inputdlg('b=');
b(i) = str2double(bi);
end
C = reshape([a; b], 1, [])';
I prefer inputdlg to input.
类别
在 帮助中心 和 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!