Why this for loop is not working?

2 次查看(过去 30 天)
clear all;
clc;
a = [1 3 6 8 9];
for i = 1:5
c(i,:) = a(i,:)+5
end

采纳的回答

Geoff Hayes
Geoff Hayes 2020-3-24
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by