colon expression to use integer operands
Afficher commentaires plus anciens
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 commentaires
Life is Wonderful
le 28 Jan 2021
Modifié(e) : Life is Wonderful
le 28 Jan 2021
Life is Wonderful
le 4 Fév 2021
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 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 commentaire
Life is Wonderful
le 28 Jan 2021
Modifié(e) : Life is Wonderful
le 28 Jan 2021
Steven Lord
le 28 Jan 2021
Modifié(e) : Steven Lord
le 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 commentaires
Life is Wonderful
le 28 Jan 2021
Modifié(e) : Image Analyst
le 28 Jan 2021
Life is Wonderful
le 28 Jan 2021
Modifié(e) : Image Analyst
le 28 Jan 2021
Image Analyst
le 28 Jan 2021
Modifié(e) : Image Analyst
le 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
le 28 Jan 2021
Modifié(e) : Life is Wonderful
le 28 Jan 2021
Steven Lord
le 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
le 29 Jan 2021
Call tech support.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

