how to have a changing input in a function

I wrote a script with a function
ex: function [DV] = deltaV(debris1, debris2, t1,t2,t1_0,t2_0,rE,mu,J2)
I have to plot the function with an increasing t2 or an increasing debris2(3) (debris1 and debris2 are vectors)
how can I do that?

 采纳的回答

t2 = linspace(0, 10, 100);
DV = zeros(size(t2));
for k = 1:numel(t2)
DV(k) = deltaV(debris1, debris2, t1, t2(k), t1_0, t2_0, rE, mu, J2);
end
plot(t2, DV);

2 个评论

Thank you
It works for t2 even though I have to use it for small numbers, but I can't make it work for debris2(3).
Do I have to use it in the same way even if debris2 is a vector?
debris2 = rand(1, 3);
DV = zeros(1, 100);
for k = 1:100
debris2(3) = rand;
DV(k) = deltaV(debris1, debris2, t1, t2, t1_0, t2_0, rE, mu, J2);
end

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File 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