How can i variate the index for the matrix input by the user in command window
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!