# How to compute values using for loop then depending on time interval we plot the output?

1 view (last 30 days)
Commented: Peter Perkins on 13 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 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)
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)
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(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)
Peter Perkins on 13 Jun 2022
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.

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2018a

### Community Treasure Hunt

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

Start Hunting!