How can i variate the index for the matrix input by the user in command window
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Paulo Silva
on 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
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!