I think the problem is that you have
COUNTER=[counterA counterB counterC counterWaste]
but counterA counterB counterC counterWaste
are, as you say, random values, so in your first example
counterA is 1
counterB is 2
counterA is 1
counterB is 2
you have, I imagine COUNTER=[1 2 1 2]
And you use a swich case on the values inside COUNTER, but you have counterA = counterC = 1
here for example, so your switch case is used like that
for n=1:size(COUNTER,2)
switch COUNTER(1,n)
case counterA % counterA = counterC = 1 go there
disp(['counterA is ' , num2str(counterA)])
case counterB % counterB = counterWaste = 2 go there
disp(['counterB is ' , num2str(counterB)])
case counterC % counterC = 1 but never used because counterC go to case counterA
disp(['counterC is ' , num2str(counterC)])
case counterWaste % same as case counterC
disp(['counterWaste is ' , num2str(counterWaste)])
end
end
Actually I think every case
should have a different value (case
are evaluating the values, not the var name) because if two case have the same value (It is possible here because your values are random) only the first one is evaluated (:
The problem is the same for:
counterA is 4
counterB is 1
counterB is 1
counterWaste is 0
You have COUNTER=[4 1 1 0]
so case counterC
is never evaluated because case counterB
is, for both counterB
and counterC
.
But I may be wrong, long time not used MatLab
I think this should work:
for n=1:size(COUNTER,2)
switch n
case 1
disp(['counterA is ' , num2str(counterA)])
case 2
disp(['counterB is ' , num2str(counterB)])
case 3
disp(['counterC is ' , num2str(counterC)])
case 4
disp(['counterWaste is ' , num2str(counterWaste)])
end
end
Note that there are many other ways to do so. This one is quite complicated for nothing ^^