My elseif condition is never checked. What to do?
Show older comments
Hello,
I want to ask a very noob question: My elseif condition is never checked. What to do?
Why do I ask this?
So, let me explain.
I got this piece of code:
A = [0.4 1.2 0.5 0.7 0.2 0.6];
S = [2.0 0.7 0.2 1.1 3.7 0.6];
in(1) = 0.4;
out(1) = in(1)+S(1);
list = 0;
%calculation of ins vector
for i = 2:6
in(i) = in(i-1)+A(i);
%calculation of outs vector
for j = 2:6
out(i) = max(out(i-1),out(i))+S(i);
end
end
So, this program simulates the inputs and outputs in/from a server
Inputs(in) and outputs(out) are already calculated in above for
The idea is simple: if an input is done in server, list will increment by 1, if an output is done from server it will decrement by 1
A way to do this is to compare if, on time axe, we have inputs in server or outputs from it and to increment and decrement accordingly
Here everything I think looks clear for me, I know how to make those ifs
But the big challenge for me is to see the evolution of the list on a plot
So, I wrote this piece of code
i = 1; %ins
o = 1; %outs
n = 1; %every for iteration
for r = 0:0.1:12
if r == in(i)
list = list + 1;
i = i + 1;
elseif r == out(o)
list = list - 1;
o = o + 1;
end
list1(n)=list;
n = n + 1;
end
plot(l1,'-r')
ylabel('list')
xlabel('time')
grid;
My plot looks like this:

Which is I intended, but it looks like the graph will never decrement, it will not go in elseif part.
What can I do in order to make my plot to go down ( to check that elseif as well ) in order to make it work on my plot?
List stores how many clients are not in server ( because one client is in there )
Time stores how much time did server had to take for each client
If I am unclear in what I am asking for, you can ask me to clear some things up.
Thank you for any kind of help.
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance 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!