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
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개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by