colon expression to use integer operands
Show older comments
The following code does not work because the colon operands are not integer values
stepSize = (pi/512);
thRadDbl = (0:stepSize:(2*pi - stepSize));
Question :How to rewrite the colon expression to use integer operands ?
2 Comments
Life is Wonderful
on 28 Jan 2021
Edited: Life is Wonderful
on 28 Jan 2021
Life is Wonderful
on 4 Feb 2021
Accepted Answer
More Answers (2)
Image Analyst
on 28 Jan 2021
0 votes
Not true. That code runs fine.
Maybe you want to consider linspace though. Or if you're going to use it as indexes, then round the values.
1 Comment
Life is Wonderful
on 28 Jan 2021
Edited: Life is Wonderful
on 28 Jan 2021
Steven Lord
on 28 Jan 2021
Edited: Steven Lord
on 28 Jan 2021
Seems to work fine for me.
stepSize = (pi/512);
thRadDbl = (0:stepSize:(2*pi - stepSize));
thRadDbl(1:5)
There's no way you're going to be able to use thRadDbl as a vector of indices since arrays in MATLAB have neither an element 0 nor an element pi/512.
One thing you could do is to wait to multiply by pi until after you've constructed the vector.
step = (1/512);
v = pi*(0:step:(2-step));
v(1:5)
Or perhaps the sinpi and/or cospi functions would be of interest to you.
7 Comments
Life is Wonderful
on 28 Jan 2021
Edited: Image Analyst
on 28 Jan 2021
Life is Wonderful
on 28 Jan 2021
Edited: Image Analyst
on 28 Jan 2021
Image Analyst
on 28 Jan 2021
Edited: Image Analyst
on 28 Jan 2021
Both of your last two code snippets run without error. They do different things.
I don't know what variable type 'embedded.fi' is - there must be something you have not told us, like the entire error message. A complete error message will have additional information, like the actual line of code that threw the error as well as a traceback for all prior lines of code that you stepped into before you got to the line of code that threw the error. What is "init_data_fixpt Line: 13 Column: 15"?
Next time, include ALL the red text, not just some of it.
Your v will still be a floating point array with a starting value of 0.
FYI embedded.fi is a class in Fixed-Point Designer. Instances of that class are created using the fi function.
This seems to work when I tried it in release R2020b.
p = fi(pi)
step = (1/512);
v = 0:step:(2-step);
pv = p*v;
pv(1:5)
I don't know if this is exactly what you're looking for, but I don't work with Fixed-Point Designer really at all, mainly just occasionally reading its documentation to answer questions on Answers.
Life is Wonderful
on 28 Jan 2021
Edited: Life is Wonderful
on 28 Jan 2021
Steven Lord
on 28 Jan 2021
We've about exhausted my knowledge of the fi data type so I don't think I can provide any more assistance.
Image Analyst
on 29 Jan 2021
Call tech support.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
