i want to make for loop to creat an array
h1=550
h2=0.8*h1
h3=0.8*h3
..
and strore the values from h1 to h_n
i made that
what is the error
clear all
clc
for i=2:5
h(1)=550;
h(i)=0.8*h(i-1);
[a(i)]=[h(i)]
end

댓글 수: 2

Ameer Hamza
Ameer Hamza 2020년 10월 17일
편집: Ameer Hamza 2020년 10월 17일
This code runs without any syntax error?
Mohamed Nasser
Mohamed Nasser 2020년 10월 17일
Yes

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

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 17일
편집: Ameer Hamza 2020년 10월 17일

0 개 추천

Try corrects the logical error in your code
clc
h = zeros(1, 5);
h(1)=550;
for i=2:5
h(i)=0.8*h(i-1);
end

댓글 수: 2

Mohamed Nasser
Mohamed Nasser 2020년 10월 17일
what is the use of this code
h = zeros(1, 5);
Ameer Hamza
Ameer Hamza 2020년 10월 17일
This is pre-allocation: https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html. It is there to make code efficient.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

태그

질문:

2020년 10월 17일

댓글:

2020년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by