i need a for loop that outputs certain numbers
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mahmoud Chawki
il 16 Mag 2022
Commentato: Mahmoud Chawki
il 16 Mag 2022
i want a loop that does the following:
first it gives me the 2 numbers which are 1 and 2
then it loops again and gives me the 2 number 3 and 4
then it loops again and gives me the 2 numbers 5 and 6
1 Commento
Jon
il 16 Mag 2022
what do you mean "gives me", do you just want to display the number on the screen, do you want it saved in array?
Risposta accettata
Jon
il 16 Mag 2022
Modificato: Jon
il 16 Mag 2022
incr = 2; % increment value
numIter = 3; % number of iteration
x = 1; % initial value
X = zeros(numIter,2); % array to hold values
for k = 1:numIter
X(k,:) = [x,x+1];
% display the values
disp(X(k,:))
% increment the value
x = x + incr;
end
X
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!