different basevalue for stems in a for loop

11 vues (au cours des 30 derniers jours)
Chien-Cheng Chiu
Chien-Cheng Chiu le 11 Sep 2020
I am stuck on how I can reset the multiple stems' BaseValues in a for loop.
However, when I run my code, the BaseValues of stem1 to stem11 switch from 0 to -y_shift after some time. Is there a way where I can reset the BaseValues of my stems to be at the right BaseValues?
stem1 to stem11 should have a BaseValue at 0.
stem12 should have a BaseValue at -y_shift.
y_shift = 1;
for k = 1:10:m+1 % for faster animations i.e. skip frame
z = u_approx_dirac(k,:);
clf
hold on
plot(x, zeta(x), 'r');
if t(k) < x_dis(1)
u(k) = u_approx(2,3)*sqrt(zeta(c)/zeta(c+t(k)));
stem1 = stem(t(k), u(k), 'filled', 'k');
set(stem1, 'ShowBaseLine', 'off');
plot1 = plot(x_dirac (abs(z) < z_min), z (abs(z) < z_min), 'k');
end
if x_dis(1) < t(k) && t(k) < x_dis(2)
u(k) = (1 + r_dis(1))*u_approx(2,3)*sqrt(zeta(c)/zeta(c + t(k)));
stem2 = stem(t(k), u(k), 'filled', 'k');
set(stem2, 'ShowBaseLine', 'off');
plot2 = plot(x_dirac (abs(z) < 2), z (abs(z) < 2), 'k');
end
if x_dis(1) < t(k)
u(k) = r_dis(1)*u_approx(2,3)*sqrt(zeta(c)/zeta(2*x_dis(1) - c - t(k)));
stem3 = stem(2*x_dis(1) - c - t(k), u(k), 'filled', 'k');
set(stem3, 'ShowBaseLine', 'off');
end
if x_dis(2) < t(k)
u(k) = (1 + r_dis(2))*(1 + r_dis(1))*u_approx(2,3)*sqrt(zeta(c)/zeta(c + t(k)));
stem4 = stem(t(k), u(k), 'filled', 'k');
set(stem4, 'ShowBaseLine', 'off');
end
if x_dis(2) < t(k) && t(k) < 2*x_dis(2) - x_dis(1)
u(k) = r_dis(2)*(1+r_dis(1))*sqrt(zeta(c)/zeta(2*x_dis(2) - c - t(k)));
stem5 = stem(2*x_dis(2) - c - t(k), u(k), 'filled', 'k');
set(stem5, 'ShowBaseLine', 'off');
plot3 = plot(x_dirac (abs(z) < 2), z (abs(z) < 2), 'k');
end
if 2*x_dis(2) - x_dis(1) < t(k) && t(k) < 3*x_dis(2) - 2*x_dis(1)
u(k) = -r_dis(1)*r_dis(2)*(1 + r_dis(1))*sqrt(zeta(c)/zeta(2*(x_dis(1) - x_dis(2)) + c + t(k)));
stem6 = stem(t(k) - 2*x_dis(2) + 2*x_dis(1), u(k), 'filled', 'k');
set(stem6, 'ShowBaseLine', 'off');
plot4 = plot(x_dirac (abs(z) < 2), z (abs(z) < 2), 'k');
end
if 2*x_dis(2) - x_dis(1) < t(k)
u(k) = r_dis(2)*(1-r_dis(1)^2)*u_approx(2,3)*sqrt(zeta(c)/zeta(2*x_dis(2) - c - t(k)));
stem7 = stem(2*x_dis(2) - t(k), u(k) , 'filled', 'k');
set(stem7, 'ShowBaseLine', 'off');
end
if 3*x_dis(2) - 2*x_dis(1) < t(k)
u(k) = -r_dis(1)*r_dis(2)*(1 + r_dis(1))*(1 + r_dis(2))*u_approx(2,3)*sqrt(zeta(c)/zeta(2*(x_dis(1) - x_dis(2)) + c + t(k)));
stem8 = stem(t(k) + 2*x_dis(1) - 2*x_dis(2), u(k) , 'filled', 'k');
set(stem8, 'ShowBaseLine', 'off');
end
if 3*x_dis(2) - 2*x_dis(1) < t(k) && t(k) < 4*x_dis(2) - 3*x_dis(1)
u(k) = -r_dis(1)*r_dis(2)^2*(1+r_dis(1))*sqrt(zeta(c)/zeta(4*x_dis(2) - 2*x_dis(1) - c - t(k)));
stem9 = stem(4*x_dis(2) - 2*x_dis(1) - t(k), u(k) , 'filled', 'k');
set(stem9, 'ShowBaseLine', 'off');
plot5 = plot(x_dirac (abs(z) < 2), z (abs(z) < 2), 'k');
end
if 4*x_dis(2) - 3*x_dis(1) < t(k)
u(k) = -r_dis(1)*r_dis(2)^2*(1 - r_dis(1)^2)*u_approx(2,3)*sqrt(zeta(c)/zeta(4*x_dis(2) - 2*x_dis(1) - c - t(k)));
stem10 = stem(4*x_dis(2) - 2*x_dis(1) - t(k), u(k), 'filled', 'k');
set(stem10, 'ShowBaseLine', 'off');
end
if 4*x_dis(2) - 3*x_dis(1) < t(k) && t(k) < 5*x_dis(2) - 4*x_dis(1)
u(k) = (r_dis(1)*r_dis(2))^2*(1+r_dis(1))*u_approx(2,3)*sqrt(zeta(c)/zeta(4*x_dis(1) - 4*x_dis(2) + c + t(k)));
stem11 = stem(t(k) + 4*x_dis(1) - 4*x_dis(2), u(k), 'filled', 'k');
set(stem11, 'ShowBaseLine', 'off');
plot6 = plot(x_dirac (abs(z) < .5), z (abs(z) < .5), 'k');
end
plot7 = plot(x_dirac(x_dirac > t(k)), 0*z(x_dirac > t(k)), 'k');
% plotting reflection
time = t(1:2:k);
reflection = reflectedwave(y(1:2:k));
plot8 = plot(time (abs(reflection) < 2), reflection (abs(reflection) < 2) - y_shift , 'b');
stem12 = stem(time (time == 2*dis(1) - 2*delta | time == 2*dis(2) - 2*delta), 2*delta*reflection (time == 2*dis(1) - 2*delta | time == 2*dis(2) - 2*delta) - y_shift, 'filled', 'b', 'ShowBaseLine', 'off');
set(stem12, 'BaseValue', -y_shift, 'ShowBaseLine', 'off');
legend(sprintf('t = %.6f', t(k)));
grid on
xlim([c d]);
xlabel('x');
ylim([-2 2]);
pause(0);
hold off
end

Réponses (0)

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by