MATLAB: When i add ‘s’ when writing a program for matrix in script then there is no space between the eelements of any row

%s

fprintf('FIRST TYPE NUMBER OF ROWS AND COLUMNS\nTHEN TYPE THE VALUES OF THE ELEMENTS\nIN THE SEQUENCE OF\n(1,1),(1,2),...,(1,n),(2,1),(2,2),...,(2,n),...,(m,1),(m,2),...,(m,n)\nWHERE (r,c) MEANS THE ELEMENT OF\nrth ROW AND cth COLUMN.\n')
m=input('ENTER NUMBER OF ROWS : ');
n=input('ENTER NUMBER OF COLUMNS : ');
for r=1:m
for c=1:n
MATRIX(r,c)=input('ENTER THE VALUE OF THE ELEMENT : ','s');
end
end
MATRIX

Best Answer

  • Wrap input in str2double:
    MATRIX(r,c) = str2double(input('...','s'));