How to compute values using for loop then depending on time interval we plot the output?
1 view (last 30 days)
Show older comments
Answered: Mohammed Lamine Mekhalfia on 3 Jun 2022
Dear Matlab comunity.
I hope this post finds you well.
My problem is as the following
I have two input values (0,1), where the output is strictly attached to them.
for a t=0 to Tfin, the output would be 0 unless for some designated time interval calculated.
I hope I explained well, I am not good in that and my English is a bit at a biginner level.
The code is as follow ( it is not finished yest)
omega=1000 %rotation frequency (rpm)
omega_rad=(omega*2*pi)/60 %rotation frequency (rad/s)
TRot=(360*(pi/180))/omega_rad %Time of one rotation
Holes=15 %Number of holes in Cylinder
Pressure_In1=0 %Pressure Amplitude in Bar
Pressure_In2=1 %Pressure Amplitude in Bar
alpha=360/Holes %angles between holes (degree)
beta=11.20 %angles swept by 1 hole (degree)
alpha_rad=alpha*(pi/180) %angles between holes (rad)
beta_rad=beta*(pi/180) %angles swept by 1 hole (rad)
Alberto Cuadra Lara on 3 Jun 2022
Edited: Alberto Cuadra Lara on 3 Jun 2022
There is no need to use loops here. MATLAB works great with vectors and is designed for this purpose. I hope this example helps you. I have changed the definition of Pressure_Out, because Pressure_In1 is zero.
If you multiply vectors element by element you have to proceed like A .* B, don't forget the period.
omega = 1000; %rotation frequency (rpm)
omega_rad = (omega*2*pi)/60; %rotation frequency (rad/s)
TRot = (360*(pi/180))/omega_rad; %Time of one rotation
Holes = 15; %Number of holes in Cylinder
Pressure_In1 = 0; %Pressure Amplitude in Bar
Pressure_In2 = 1; %Pressure Amplitude in Bar
alpha = 360/Holes; %angles between holes (degree)
beta = 11.20; %angles swept by 1 hole (degree)
alpha_rad = alpha*(pi/180); %angles between holes (rad)
beta_rad = beta*(pi/180); %angles swept by 1 hole (rad)
k = TRot/100; %timestep
% Define vector variables [initial value:step:final value]
N = 1:1:Holes;
time = 0:k:TRot;
s = (alpha_rad / omega_rad) + N * (pi/Holes);
Pressure_Out = Pressure_In2 * time;
xlabel('Time [s]', 'fontsize', 16, 'Interpreter', 'latex');
ylabel('Pressure [bar]', 'fontsize', 16, 'Interpreter', 'latex');
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!