How do i store value in a array from for loop?

1 次查看(过去 30 天)
p=0;
q=0;
G=0.1;
K=0.2;
M=1.2;
c=20;
Ms=0.8;
eps_v=0;
eps_s=0;
deps_v= 0.0001;
deps_s= .67*deps_v;
for i=1:5
dp= K*deps_v;
dq= (3*G)*deps_s;
pt=p+dp;
qt=q+dq;
f= qt-M*pt+c;
if (f<0)
deps_ve=deps_v;
deps_se=deps_s;
deps_vp=0;
deps_sp=0;
else
dpe=M*p-c-q/(.67-M);
dqe=0.67*dpe;
deps_ve=dpe/K;
deps_se=dqe/(3*G);
deps_vp=deps_v-deps_ve;
deps_sp=deps_s-deps_se;
dpp= ((K-((0.67*K*K*M-K*K*M*Ms)/(0.67*M*K-K*M*Ms+3*G)))*deps_vp)+ (((2*G*K-3*K*G*Ms)/(0.67*M*K-K*M*Ms+3*G))*deps_sp);
dqp= (((3*M*G*K)/(0.67*M*K-K*M*Ms+3*G))*deps_vp)+(((3*G)-((9*G*G)/(0.67*M*K-K*M*Ms+3*G)))*deps_sp);
dp= dpe+dpp;
dq= dqe+dqp;
end
p=p+dp;
q=q+dq;
eps_v=eps_v+deps_ve+deps_vp;
eps_s=eps_s+deps_se+deps_sp;
end
disp(p)
disp(q)
disp(eps_v)
disp(eps_s)
here i want to store the updated values of p and q in a array so that i can plot p,q
please tell me how to do it

采纳的回答

darova
darova 2020-3-29
I give you simple example for a start
n = 10;
y = zeros(1,n);
for i = 1:n-1
x = x + dx;
dy = sin(x);
y(i+1) = y(i) + dy;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by