I have a vector and I want to make a while condition for its error.
Show older comments
I want to make abs(z(i+1)-z(i))/abs(z(i))<0.0001 in every iteration, but I don't know how to make the iteration run all the numbers in the vector z!
Can you please help me?
Accepted Answer
More Answers (3)
Azzi Abdelmalek
on 2 Oct 2012
z=rand(10,1);
for i=1:length(z)-1
if abs(z(i+1)-z(i))/abs(z(i))<0.0001
res(k)=1 %for example
else
res(k)=0
end
end
David
on 2 Oct 2012
0 votes
David
on 2 Oct 2012
0 votes
1 Comment
Azzi Abdelmalek
on 2 Oct 2012
z=rand(200,1)
result = abs(diff(z)) ./ abs(z(1:end-1)) < 0.0001
Categories
Find more on Loops and Conditional Statements 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!