Why this for loop is not working?

2 vues (au cours des 30 derniers jours)
Amit Kumar
Amit Kumar le 24 Mar 2020
Commenté : Amit Kumar le 24 Mar 2020
clear all;
clc;
a = [1 3 6 8 9];
for i = 1:5
c(i,:) = a(i,:)+5
end

Réponse acceptée

Geoff Hayes
Geoff Hayes le 24 Mar 2020
Amit - a is a row array but the code in the loop is treating it like a column array. Try changing the code to
for i = 1:5
c(i,:) = a(i)+5
end
You should decide whether c should be a row or column array.
  1 commentaire
Amit Kumar
Amit Kumar le 24 Mar 2020
Thnak you so much..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by