How can i variate the index for the matrix input by the user in command window
Afficher commentaires plus anciens
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
Réponses (1)
Paulo Silva
le 2 Mar 2011
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
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!