display result (numbers)

조회 수: 2 (최근 30일)
Nadya
Nadya 2020년 6월 30일
댓글: Nadya 2020년 7월 2일
Hello,
I have a problem in displaying result.
I have this equation :
ps1=((max(max(X1))-mean(mean(X2)))/ (std2(X2)));
Normally, the result is for example '7.473958' but it is displayed '8' !!!
what is the problem please ?

채택된 답변

Steven Lord
Steven Lord 2020년 6월 30일
When you take the max of an integer array, the result is of the same integer type.
When you take the mean of an integer array, the result is (by default) double precision.
When you perform arithmetic on an integer array and a scalar double precision value, the result is of the integer type. See the "Arithmetic Operations on Integer Classes" section on this documentation page.
Convert the output of max from an integer type to double using the double function before you subtract the mean from it.
  댓글 수: 1
Nadya
Nadya 2020년 7월 2일
Thank you so much ! problem solved !

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

추가 답변 (1개)

Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020년 6월 30일
intent with the format command
format long
  댓글 수: 1
Nadya
Nadya 2020년 6월 30일
Thank you for your answers
I tried this, but this is not the problem, because in the same program, I calculated other parameters, and they are displayed with the real long format. Just for this parameter, the results are converted and displayed in integer numbers (uint8).

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by