Creating an array for a set number iterations

I currently have the code that I have made for calculating a value Ct. But for this code I am trying to modify it such that I can calulate the array of values of Ct, for the values of i being from 1 to 30. I have tried a for loop but just cant get it to output the right values. F must be added to the last value of Ct. If i = 3 then there should be three elements in the array Ct which are [4000 4000 104000]
F = 100000;
i = 1;
Ct= F*0.04.*ones(i,1);
Ct(i) =Ct(i)+F;
T=length(Ct);
t=(1:1:T)';

 채택된 답변

Voss
Voss 2022년 4월 16일
F = 100000;
for i = 1:30
Ct = F*0.04.*ones(i,1);
Ct(i) = Ct(i)+F
end
Ct = 104000
Ct = 2×1
4000 104000
Ct = 3×1
4000 4000 104000
Ct = 4×1
4000 4000 4000 104000
Ct = 5×1
4000 4000 4000 4000 104000
Ct = 6×1
4000 4000 4000 4000 4000 104000
Ct = 7×1
4000 4000 4000 4000 4000 4000 104000
Ct = 8×1
4000 4000 4000 4000 4000 4000 4000 104000
Ct = 9×1
4000 4000 4000 4000 4000 4000 4000 4000 104000
Ct = 10×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 104000
Ct = 11×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 12×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 13×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 14×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 15×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 16×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 17×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 18×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 19×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 20×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 21×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 22×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 23×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 24×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 25×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 26×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 27×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 28×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 29×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000
Ct = 30×1
4000 4000 4000 4000 4000 4000 4000 4000 4000 4000

추가 답변 (1개)

Bruno Luong
Bruno Luong 2022년 4월 16일
F = 100000;
i = 3;
Ct= F*0.04.*ones(1,i);
Ct(end) = Ct(end)+F
Ct = 1×3
4000 4000 104000

댓글 수: 4

Jd45ter
Jd45ter 2022년 4월 16일
This looks good but I need it to calculate it for i = 1:1:30 thanks
loop on i? You don't know to use for-loop ?
Jd45ter
Jd45ter 2022년 4월 16일
편집: Jd45ter 2022년 4월 16일
I have tried a for loop, as I stated in the question. But it wasnt getting the correct output.
Then post your code with for-loop, and please be more precise when asking question.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2022년 4월 16일

답변:

2022년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by