How can i variate the index for the matrix input by the user in command window

1 回表示 (過去 30 日間)
Muhammad Usman
Muhammad Usman 2011 年 3 月 2 日
Code: syms('a','b','A','n') fprintf('Enter the value of n:') n=input(' '); for a=1:n; for b=1:n; A(a,b)=input(' '); end end A
Output:
Enter the value of n: 2 1 2 3 4
A =
[ 1, 2] [ 3, 4]
i want to have an interface like A(1,1)=1 A(1,2)=2
please guide me as soon as possible

回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 3 月 2 日
n=input('Please input the size (n) of the matrix:');
A=zeros(n,n)
for idx=1:n
[row,col]=ind2sub(size(A),idx);
A(idx)=input(sprintf('A(%d,%d)=A(%d)=',row,col,idx));
end
A

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by