Error indexing usig logicals

Hi there, I have an issue while using logicals for change the size of a vector: here's a simple code test:
rad = 0.3;
A = linspace(0,1,51);
nn = A(A <= 3*rad);
n2 = A(A <= 0.9);
Normally size(nn) has to be equal to size(n2), but nope... I'm kind of lost. Does anyone have an idea what's going on here?

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 17 de Mayo de 2018

0 votos

This is really a floating point data precision issue. Run this to find out and deal with it based on whatever your use case.
isequal(3*0.3, 0.9)

La pregunta está cerrada.

Productos

Etiquetas

Preguntada:

el 17 de Mayo de 2018

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by