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일

0 개 추천

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

Assel Belgibekova
Assel Belgibekova 2012년 3월 13일
Dear Wayne,
Thank you very much! That helps a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (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