Trying to in do a vector in a for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Chrishell Mercado
am 15 Nov. 2018
Bearbeitet: madhan ravi
am 15 Nov. 2018
clc
n=input('Enter number of rows: ');
m=input('Enter number of column: ');
matrix = zeros(n, m); % preallocate your matrix
for k=1:n
for i = 1:m
M(i) = input(['Enter row ' num2str(k) ' column ' num2str(i) ' number: ']);
matrix(:,i) = M(i);
end
end
A=[matrix]
Im trying to input numbers for the first row with a set number of columns and once that is done i need it to move on to next row. At the end im trying to show them as one matrix. I cant seem to find a way or know a way that allows me to save the inputs as one row and be able to call on that row for however many rows there are.
I guess i want the solution to look like this when i call on it. That s
A =
1 0 2
3 4 5
4 5 8
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 15 Nov. 2018
Bearbeitet: madhan ravi
am 15 Nov. 2018
n=input('Enter number of rows: ')
m=input('Enter number of column: ')
matrix = zeros(n, m); % preallocate your matrix
for k=1:n
for i = 1:m
matrix(k,i) = input('input number: ')
end
end
A=matrix
0 Kommentare
Weitere Antworten (1)
KSSV
am 15 Nov. 2018
m = 3 ; n = 3 ;
A = zeros(m,n) ;
for i = 1:m
for j = 1:n
prompt = sprintf('(%d,%d) element:',i,j) ;
A(i,j) = input(prompt) ;
end
end
Once your matrix is ready, you can do what ever you want.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!