How to compute values using for loop then depending on time interval we plot the output?
1 次查看(过去 30 天)
显示 更早的评论
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 result should be like the one in the picture
The code is as follow ( it is not finished yet)
clear all
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
h=1
f=1
for time=0:k:TRot
Pressure_Out=Pressure_In1*time
f=1
for N=1:1:Holes
s=(alpha_rad/omega_rad)+N*(pi/Holes)
S(f)=s
f=f+1
end
Press(h)=Pressure_Out
t(h)=time
h=h+1
end
if time==S
Press=Pressure_In2
end
plot(t,Press)
1 个评论
Peter Perkins
2022-6-13
Mohammed, it's not clear what you are trying to do, so I have no concrete suggestion. You need to give a clear example of what you start with and what you want to compute.
It does appear that you can do this calculation without any loops at all.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!