views:

40

answers:

1

I wonder if matlab has set restriction on variable's name.

fixnb21=0;

for fix=1:200
    if fixdur(fix)>MIN_FIX_DUR && fixdur(fix)<MAX_FIX_DUR
        fixnb21              =fixnb21+1
        fixdur21(fixnb21)    =fixdur(fix) % I wonder if we are not allowed to add 21 at the end of variables or array name
        ...
    end
end

The fixnb21output is 113, which mean the total number of row of fixdur21 should be 113. But when I checked the number of rows of fixdur21, it was 1023, which is totally wrong. This only happen when I put the number 21 at the end of fixdur21. The output seems right when I don't use the number 21. this is so confusing.

+1  A: 

try starting with fixdur21=[].

if that doesnt work post the rest of your code! - you must be changing it somewhere else

variables names can contain any digits you like (except at the start) though if you have several numbered variables, you are probably better off using a list or cell array (so you can iterate over them).

also, your whole code simplifies to:

fixdur21 = fixdur((fixdur(1:200) > MIN_FIX_DUR) & (fixdur(1:200) < MAX_FIX_DUR));
fixnb21  = length(fixdur21);

and you can omit the 1:200 if fixdur is always 200 items long

don't iterate if you don't have to.

Sanjay Manohar
Thanks Sanjay ... by adding the fixdur21=[] in the beginning of the code solved my problem.
Jessy