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
Life is Wonderful
2021년 1월 28일
편집: Life is Wonderful
2021년 1월 28일
Life is Wonderful
2021년 2월 4일
채택된 답변
추가 답변 (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.
댓글 수: 1
Life is Wonderful
2021년 1월 28일
편집: Life is Wonderful
2021년 1월 28일
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!

