Doubt in a product erro

조회 수: 1 (최근 30일)
Nélio Dias
Nélio Dias 2021년 4월 2일
댓글: Sulaymon Eshkabilov 2021년 4월 4일
Hi, I have wrinting a code e get a 1×0 empty double row vector error
So, what I wrote:
t1 = 0:0.01:300;
pmenor = 25*0.9;
pmaior = 25*(1.1);
idx1 = find(t1== pmenor);
idx2 = find(t1 == pmaior);
I got
idx2 =
1×0 empty double row vector
But, if I write:
idx2 = find(t1 == 27.5);
idx2 =
2751
So I dont understand the error since idx1 gives me the correct answer, because we know that 25*1.1 = 27.5.
Thanks for reading.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 4월 2일
편집: Sulaymon Eshkabilov 2021년 4월 2일
Here is a small correction to obtain the correct answers in your exercise:
t1 = 0:0.01:300;
N = 2; % Number of decimal digits to be rounded, e.g.: N = 2 or 3 or 5, etc.
pmenor = round(25*0.9, N);
pmaior = round(25*(1.1), N);
idx1 = find(t1== pmenor);
idx2 = find(t1 == pmaior);
  댓글 수: 2
Nélio Dias
Nélio Dias 2021년 4월 4일
Thanks for the help.
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 4월 4일
You are welcome - it is a pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2021년 4월 2일
The reason has to do with the accuracy of floating-point math on a binary computer. I suggest you read this question and answer, to get a better understanding of what is going on.
  댓글 수: 1
Nélio Dias
Nélio Dias 2021년 4월 4일
Thanks for the sugestion

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by