How to repeat the graph many times using FOR loop
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
azerty and qwerty
le 2 Juin 2022
Réponse apportée : azerty and qwerty
le 3 Juin 2022
Hello guys, i want to put a FOR loop in my code to plot my signal as much as i want but i still cant make it
my code below :
clc;
clear all;
close all;
%% Declaration of initial variables
fs = 5000; % Sampling Frequency in Hz
t1 = linspace(0,2000,fs) ; % Period in ms
f = 50; % Frequency in Hz
U1=230; % Supply voltage
FontSize = 10;
%% For VOLTAGE
MyVoltage = U1*sin(2*pi*f*t1); % Sine wave generation
subplot(5,1,1);
plot(t1,MyVoltage)
grid on;
xlabel('My Voltage', 'FontSize', FontSize)
ylabel('Tension (V)', 'FontSize', FontSize)
title ('Generation of voltage dips of 70%', 'FontSize', FontSize);
%% Declaration of initial variables
fs = 5000; % Sampling Frequency in Hz
t2 = linspace(2000,2500,fs) ; % Period in ms
f = 50; % Frequency in Hz
P=0.7; % disturbance percentage
U2=230*P; % Perturbation
%% For PERTURBATION
MyPerturbation = U2*sin(2*pi*f*t2); % Sine wave generation
subplot(5,1,2);
plot(t2,MyPerturbation)
grid on;
xlabel('My Perturbation', 'FontSize', FontSize)
ylabel('Tension (V)', 'FontSize', FontSize)
%% For VOLTAGE DIPS
signal = MyVoltage+MyPerturbation; % Voltage dips generation
subplot(5,1,3);
plot(t1,MyVoltage, 'r', t2, MyPerturbation, 'b')
hold on
grid on;
xlabel( 'My Voltage Dip', 'FontSize', FontSize)
ylabel('Voltage (V)', 'FontSize', FontSize)
%% Declaration of initial variables
fs = 5000; % Sampling Frequency in Hz
t3 = linspace(2500,3500,fs) ; % Period in ms
f = 50; % Frequency in Hz
U1=230; % Supply voltage
FontSize = 10;
%% For VOLTAGE
MyVoltage = U1*sin(2*pi*f*t3); % Sine wave generation
subplot(5,1,4);
plot(t3,MyVoltage)
grid on;
xlabel('My Voltage', 'FontSize', FontSize)
ylabel('Tension (V)', 'FontSize', FontSize)
%% For FINAL VOLTAGE DIPS
signal = MyVoltage+MyPerturbation; % Voltage dips generation
subplot(5,1,5);
plot(t1,MyVoltage, 'r', t2, MyPerturbation, 'b', t3, MyVoltage, 'g')
hold on
grid on;
xlabel( 'My Voltage Dip', 'FontSize', FontSize)
ylabel('Voltage (V)', 'FontSize', FontSize)
In fact i want to plot the last signal many times using a FOR loop. I tried many times but i couldnt make ...
3 commentaires
Réponse acceptée
VINAYAK LUHA
le 2 Juin 2022
Hi ,
As per my understanding ,
"You wish to plot a periodic signal of time period (T=3500ms) with known amplitude variations within the first time period ."
SOLUTION
Plot the same amplitude variation in successive time periods using for loop.
%% Declaration of initial variables
fs = 5000; % Sampling Frequency in Hz
t1 = linspace(0,2000,fs) ; % Period in ms
f = 50; % Frequency in Hz
U1=230; % Supply voltage
FontSize = 10;
%% For VOLTAGE
MyVoltage = U1*sin(2*pi*f*t1); % Sine wave generation
subplot(5,1,1);
plot(t1,MyVoltage)
grid on;
xlabel('My Voltage', 'FontSize', FontSize)
ylabel('Tension (V)', 'FontSize', FontSize)
title ('Generation of voltage dips of 70%', 'FontSize', FontSize);
%% Declaration of initial variables
fs = 5000; % Sampling Frequency in Hz
t2 = linspace(2000,2500,fs) ; % Period in ms
f = 50; % Frequency in Hz
P=0.7; % disturbance percentage
U2=230*P; % Perturbation
%% For PERTURBATION
MyPerturbation = U2*sin(2*pi*f*t2); % Sine wave generation
subplot(5,1,2);
plot(t2,MyPerturbation)
grid on;
xlabel('My Perturbation', 'FontSize', FontSize)
ylabel('Tension (V)', 'FontSize', FontSize)
%% For VOLTAGE DIPS
signal = MyVoltage+MyPerturbation; % Voltage dips generation
subplot(5,1,3);
plot(t1,MyVoltage, 'r', t2, MyPerturbation, 'b')
hold on
grid on;
xlabel( 'My Voltage Dip', 'FontSize', FontSize)
ylabel('Voltage (V)', 'FontSize', FontSize)
%% Declaration of initial variables
fs = 5000; % Sampling Frequency in Hz
t3 = linspace(2500,3500,fs) ; % Period in ms
f = 50; % Frequency in Hz
U1=230; % Supply voltage
FontSize = 10;
%% For VOLTAGE
MyVoltage = U1*sin(2*pi*f*t3); % Sine wave generation
subplot(5,1,4);
plot(t3,MyVoltage)
grid on;
xlabel('My Voltage', 'FontSize', FontSize)
ylabel('Tension (V)', 'FontSize', FontSize)
%% For FINAL VOLTAGE DIPS
signal = MyVoltage+MyPerturbation; % Voltage dips generation
subplot(5,1,5);
plot(t1,MyVoltage, 'r', t2, MyPerturbation, 'b', t3, MyVoltage, 'g')
hold on
grid on;
xlabel( 'My Voltage Dip', 'FontSize', FontSize)
ylabel('Voltage (V)', 'FontSize', FontSize)
%------------------------------------------------------------------------------------------
%figure
%times is the number of Times you want to replicate the wave
times=4;
time_period=3500;
for i=1:times
hold on
plot(t1,MyVoltage, 'r', t2, MyPerturbation, 'b', t3, MyVoltage, 'g');
t1=t1+time_period;
t2=t2+time_period;
t3=t3+time_period;
end
xlabel( 'My Voltage Dip', 'FontSize', FontSize)
ylabel('Voltage (V)', 'FontSize', FontSize)
0 commentaires
Plus de réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


