Why this for loop is not working?

2 visualizzazioni (ultimi 30 giorni)
Amit Kumar
Amit Kumar il 24 Mar 2020
Commentato: Amit Kumar il 24 Mar 2020
clear all;
clc;
a = [1 3 6 8 9];
for i = 1:5
c(i,:) = a(i,:)+5
end

Risposta accettata

Geoff Hayes
Geoff Hayes il 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.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by