开发者

MATLAB weird output

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 a开发者_开发技巧llowed 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜