MATLAB: How can i prompt user to enter elements for specific row/columns

columninputlooprow

script ive used:
m = input('Enter number of rows: ');
n = input('Enter number of columns: ');
for i = 1:m
for j = 1:n
str = ['Enter element in row ' num2str(i) ', col ' num2str(j) ': '];
a(i,j) = input(str);
end
end
a
but this script prompts the user for to enter all elements while i need only to prompt the user for specific rows and columns,can anyone kindly advise me on this?

Best Answer

Let's say that you've stored the row, column combinations that need replacing in an array called rc. Then just do
numberOfElements = size(rc, 1);
for k = 1 : numberOfElements
row = rc(k, 1);
column = rc(k, 2);
str = sprintf('Enter the value to go into row %d, column %d : ', row, column);
a(row, column) = input(str);
end
a
This will ask for only the table elements that you've specified in advance rather than all of them. For a little nicer program you should use inputdlg() instead of input().