simple for loop problem

조회 수: 13 (최근 30일)
Josiah Miles
Josiah Miles 2019년 10월 22일
답변: Darshan 2023년 11월 8일
Create a for loop that adds one to every number in the array. For example [1,2,3] becomes [2,3,4] after the loop is complete.
a. create the variable x=1:10;
b. set the loop to run the correct amount of times
c. write the loop
d. use disp(x)
  댓글 수: 1
per isakson
per isakson 2019년 10월 22일
Sounds like homework. What you done so far and what's your problem?

댓글을 달려면 로그인하십시오.

답변 (2개)

Maz M. Khansari
Maz M. Khansari 2019년 10월 23일
The following will do the job for you.
x = 1:10;
x_new = zeros(1,numel(x));
for i=1:numel(x)
x_new(i) = x(i)+1;
end
disp(x);

Darshan
Darshan 2023년 11월 8일
x = [1:10]
for i=1:10
new_x(i,:) = x(i)+1
end

카테고리

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