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)

 Réponse acceptée

Wayne King
Wayne King le 13 Mar 2012

0 votes

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.

1 commentaire

Assel Belgibekova
Assel Belgibekova le 13 Mar 2012
Dear Wayne,
Thank you very much! That helps a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by