フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I put the values that I made in a for and if loop into a vector?

1 回表示 (過去 30 日間)
Sophie
Sophie 2018 年 4 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
This is what I've got so far, there might be other issues too.
for i = 0:L;
if i == 0:L_1
v_1(i) = P-(P*L_1)/L
m_1(i) = (P-((P*L_1)/L))*i
elseif i == L_1:L
v_1(i) = ((P*L_1)/L)-P
m_1(i) = (P-((P*L_1)/L))*i - P*(i-L_1)
end
v = (i,v_1(i))
m = (i,m_1(i))
end
  9 件のコメント
Sergey Kasyanov
Sergey Kasyanov 2018 年 4 月 6 日
Sophie, try this:
plot([v1,v2],[m1,m2])
Sophie
Sophie 2018 年 4 月 6 日
That fixed it, thank you!

回答 (1 件)

Sergey Kasyanov
Sergey Kasyanov 2018 年 4 月 6 日
編集済み: Sergey Kasyanov 2018 年 4 月 6 日
Code improvements:
%Range of i for different calculation formulas
FirstRange=[1:L_1];
SecondRange=[L_1:L];
%Create array with result of calculations
v=[ones(length(FirstRange),1)*(P-(P*L_1)/L)
ones(length(SecondRange),1)*(((P*L_1)/L)-P)];
m=[FirstRange'*(P-((P*L_1)/L))
(P-((P*L_1)/L))*SecondRange' - P*(SecondRange'-L_1)];
Notes:
1) FirstRange - row array, FirstRange' - column array with same data.
2) ones(length(FirstRange),1) - column array with ones with the same length as FirstRange.
3) In (P-((P*L_1)/L))*i - P*(i-L_1) the i is replaced by array with i values - SecondRange. That also works.
Yoy may plot graph with that:
plot(m,v)
If you want to plot a rectangle you may use function rectangle.
  2 件のコメント
Sophie
Sophie 2018 年 4 月 6 日
This syntax didn't work when I tried using it.
Sergey Kasyanov
Sergey Kasyanov 2018 年 4 月 6 日
Strange. I have tested it. Can you adduce error message?

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by