How can i delate the same values in a vector ?

Hi
To find the zeros of the following equation, i have done the following program but sometimes it displays a repeated solution. So i want to do a program that delate the same solutions to obtain a vector that content the different solutions.
f = @(x) cos(x) * cosh(x) + 1;
for i= 1:40
k(i)= fzero (f, i)
end

Respuestas (1)

the cyclist
the cyclist el 20 de En. de 2017
Do you mean you want
unique_k = unique(k)
?

9 comentarios

Mallouli Marwa
Mallouli Marwa el 20 de En. de 2017
No, i mean how delate the repitition in in k ?
Guillaume
Guillaume el 20 de En. de 2017
and what do you think unique does?
You could assign back to k:
k = unique(k)
to "get rid of the duplicates". Is that what you mean?
Try this:
f = @(x) cos(x) * cosh(x) + 1;
for i= 1:40
% Get root for just this value of i.
iRoots(i) = fzero (f, i);
end
% Throw out duplicates.
uniqueRoots = unique(iRoots)
Mallouli Marwa
Mallouli Marwa el 21 de En. de 2017
I obtain this result
1.8751 4.6941 4.6941 7.8548 10.9955 10.9955 14.1372 17.2788 20.4204 23.5619 26.7035 29.8451 29.8451 32.9867
I want to eliminate the repeated values.
Stephen23
Stephen23 el 21 de En. de 2017
@Mallouli Marwa: You can use uniquetol.
Mallouli Marwa
Mallouli Marwa el 21 de En. de 2017
I have this error
Undefined function 'uniquetol' for input arguments of type 'double'.
I think because i have matlab 2012a
Can you send me a loop of for that eliminate the repeated values in k.
Please help me
Stephen23
Stephen23 el 21 de En. de 2017
You could download John D'Errico's excellent FEX submssion consolidator.
Mallouli Marwa
Mallouli Marwa el 21 de En. de 2017
I download it and then what could i do ?

Iniciar sesión para comentar.

Categorías

Más información sobre Downloads en Centro de ayuda y File Exchange.

Preguntada:

el 20 de En. de 2017

Comentada:

el 21 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by