MATLAB Answers

Why this for loop is not working?

2 views (last 30 days)
Amit Kumar
Amit Kumar on 24 Mar 2020
Commented: Amit Kumar on 24 Mar 2020
clear all;
clc;
a = [1 3 6 8 9];
for i = 1:5
c(i,:) = a(i,:)+5
end

  0 Comments

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 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 Comment

Amit Kumar
Amit Kumar on 24 Mar 2020
Thnak you so much..

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags