How do I assign a variable to be any whole number?

I want the "if" statement to check if t is an increment of 2*pi/w, so I want j to be any whole number but I have not been able to figure out a way to make j any whole number so that the "if" statement will check if t is an increment of 2*pi/w. Also you can ignore the plot3(move points), I know this is an error and I am planning on fixing this later.
for i=1:w/2
t{i} = (i-1)*e:pi/w:(n*2*pi)+e*(i-1); %t value for CCW helices
x{i} = r*sin(t{i});
y{i} = r*cos(t{i});
z{i} = (h/(n*2*pi))*t{1};
if t{i}==j*(2*pi)/w
plot3(move points)
else
plot3(x{i},y{i},z{i}, '.','MarkerSize',25,'MarkerFaceColor','yellow','MarkerEdgeColor','yellow') %plot CCW helices
hold on;
end
hold on;
end
hold on;

2 Comments

if t is an increment of 2*pi/w
t{i} is a vector of numbers. What does it mean for you for a vector to be an increment of something. Note that the difference between consecutive elements of t{i} is pi/w, since this is how you defined it.
I want to check the individual values of t not the entire vector.

Sign in to comment.

Answers (1)

You t{i} is a vector:
t{i} = (i-1)*e : pi/w : (n*2*pi)+e*(i-1);
Therefore if t{i}==j*(2*pi)/w would only be true, if all elements of the vector are exactly j*(2*pi)/w. Due to the rounding of IEEE754 values, this is very unlikely. Please read FAQ: Why is 0.3-0.2~=0.1 (link).
Do you want to text single elements of this vector, or is really an all() wanted?
Maybe you want:
if any(t{i} - j*(2*pi)/w < 100 * eps(t{i}))
or:
index = abs(mod(t{i}, (2*pi)/w)) < 1e-7;
and then use this logical index to address certain x{i}, y{i} and z{i}.
Please explain, what you want to do exactly. It is hard to fix the code, when its intention was not mentioned.

2 Comments

I want the if statement to check each individual t value. So it will start with the first t value and I want it to check if its an increment of 2*pi/w and then it will move on to the next t value and I want it to check if it is an increment of 2*pi/w and so on...Does that make the intention clearer?
Not really. Note that it is usually much easier and faster to check all the elements at once rather than each one individually.
It's still not clear what you mean by increment of. Do you mean multiple of 2*pi/w? If so, why don't you create your vector as multiple of 2*pi/w to start with? e.g:
t{i} = (1:100)*2*pi/w; %all elements are guaranteed to be multiple of 2*pi/w
Also note, t is a cell array. Individual elements of the cell array, i.e. t{i}, are vectors. Individual elements of these unnamed vectors would be t{i}(j).

Sign in to comment.

Categories

Products

Release

R2018a

Tags

Asked:

on 2 Jul 2018

Edited:

on 2 Jul 2018

Community Treasure Hunt

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

Start Hunting!