How to repeat the graph many times using FOR loop

3 vues (au cours des 30 derniers jours)
azerty and qwerty
azerty and qwerty le 2 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
azerty and qwerty
azerty and qwerty le 2 Juin 2022
Okay .. so if u plot my code u will get this signal at the end :
I can make another signal like this by re-writing the same code again and changing the time ... but if i had to make it 50 more times, i will not write 50 times the same code over and over .. so i tried to make a for loop so i can get this signal as much as i want .. but i get errors everytime
azerty and qwerty
azerty and qwerty le 2 Juin 2022
i want to have something like this for example :
in this case i just repeated it 3 times so i just changed the time and rewrite it .. but if i had to repeat it infinit time here its a problem

Connectez-vous pour commenter.

Réponse acceptée

VINAYAK LUHA
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)

Plus de réponses (1)

azerty and qwerty
azerty and qwerty le 3 Juin 2022
Thats exactly what i wanted !! thank you so much

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by