error using zeros in matlab

6 views (last 30 days)
JT
JT on 18 Nov 2015
Edited: Jan on 4 Oct 2017
er = zeros(1, .125*N); % eigth rest
qr = zeros(1, .25*N); % quarter rest
hr = zeros(1, .5*N); % half rest
tr = zeros(1, .75*N); % three-quarter rest
wr = zeros(1, N); % whole rest
I get the error Error using zeros Size inputs must be integers.
Error in pleasework (line 49) er = zeros(1, .125*N); % eigth rest
>>
  4 Comments
Akhil Sen Roy
Akhil Sen Roy on 4 Oct 2017
Edited: Akhil Sen Roy on 4 Oct 2017
so whats the final answer ?? did you manage to solve it ?
Jan
Jan on 4 Oct 2017
Edited: Jan on 4 Oct 2017
John's answer is clear enough. The solution is trivial: zeros creates an array, and therefore the number elements must be integers. It is not clear what zeros(1, 0.125*N) should do if N is not a multiple of 8.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 20 Nov 2015
Edited: John D'Errico on 20 Nov 2015
I wonder, what are the odds that N is not an integer multiple of 8?
Zeros requires integer arguments. READ THE ERROR MESSAGE! If N is not an integer multiple of 8, then when you multiply by 0.125, you get a non-integer. So you need to think about what size you really need for this vector. If I had to guess, you might want to round up or round down, but this is your code, so you are the one who knows what you wanted to do.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!