Input a matrix

Hello! I'm writing a program that counts the maximum flow through the network and to make it work I need to know only one detail.
How can I input a matrix?
During one of my trials I had the following: >>path=input('Select a path ','s') Select a path 123456 >>path= 123456
Well, I knew that this ought to be incorrect)...anyway, I was curiuos about it)

 采纳的回答

Wayne King
Wayne King 2012-3-13
You want the user to a sequence of numbers that you then shape into a matrix?
If you want to use input(), you can use input in a loop.
disp('Input your path one number at a time');
for nn = 1:6
x(nn) = input(['Enter number ' num2str(nn) '\n']);
end
% then use reshape() to shape into a matrix if you need
% a matrix
x = reshape(x,3,2);
For your purposes, maybe just leaving it as a vector is sufficient.
I think a better way is this:
str = inputdlg('Enter a list of numbers separated by spaces or commas');
numbers = str2num(str{1});
Then you can reshape numbers as you wish.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by