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)

 Respuesta aceptada

Wayne King
Wayne King el 13 de Mzo. de 2012

0 votos

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 comentario

Assel Belgibekova
Assel Belgibekova el 13 de Mzo. de 2012
Dear Wayne,
Thank you very much! That helps a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by