colon expression to use integer operands
显示 更早的评论
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 个)
Image Analyst
2021-1-28
0 个投票
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.
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 个评论
Life is Wonderful
2021-1-28
编辑:Image Analyst
2021-1-28
Life is Wonderful
2021-1-28
编辑:Image Analyst
2021-1-28
Image Analyst
2021-1-28
编辑:Image Analyst
2021-1-28
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
2021-1-28
编辑:Life is Wonderful
2021-1-28
Steven Lord
2021-1-28
We've about exhausted my knowledge of the fi data type so I don't think I can provide any more assistance.
Image Analyst
2021-1-29
Call tech support.
类别
在 帮助中心 和 File Exchange 中查找有关 Fixed-Point Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

