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 で Matrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by