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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!