I am trying to get the code to start at a certain value lets say 80 and start counting down from there. But I am struggling to see where to put this information into my code to make this happen.
xdt3 = 5;
xt03 = 0;
xtf3 = 60;
xt3 = xtf3:-xdt3:xt03;
x3 = zeros(1,13);
for i = length(xt3):-1:2
x3(i-1) = x3(i) - ((5 - (4 /50)*x3(i)))*xdt3;
end

2 件のコメント

Stephen23
Stephen23 2016 年 2 月 8 日
WhatIsMatlab-
WhatIsMatlab- 2016 年 2 月 8 日
It is a different question. Similar titles

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2016 年 2 月 8 日

0 投票

You have to make the appropriate modifications to my previous code to make your new step size work:
xdt3 = 5;
xt03 = 0;
xtf3 = 60;
xt3 = xtf3:-xdt3:xt03;
x3 = zeros(1,13*xdt3);
for i = xtf3:-xdt3:xdt3+1
x3(i-xdt3) = x3(i) - ((5 - (4 /50)*x3(i)))*xdt3;
end
This runs, so you have to decide if it gives you the result you want. Note that MATLAB will skip the indices you do not address, resulting in a significant number of zero
values in your vector. You may also want to change the initial line in the for loop to:
for i = xtf3+xdt3:-xdt3:xdt3+1

2 件のコメント

WhatIsMatlab-
WhatIsMatlab- 2016 年 2 月 8 日
Thank you!! I understand what you are saying
Star Strider
Star Strider 2016 年 2 月 8 日
My pleasure!
Also, if you want only the non-zero values, this works:
X3 = x3(x3~=0);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by