How to retrieve first 4 digits after decimal point?

조회 수: 16 (최근 30일)
Abdul Gaffar
Abdul Gaffar 2019년 12월 4일
댓글: Star Strider 2019년 12월 4일
I have to retrieve first 4 digits after decimal point in HH band of the following code:
img = imread('cameraman.tif');
a = img(1:8,1:8);
[LL,LH,HL,HH] = dwt2(a,'db4');
Moreover, how can I fetch more than 4 digits (after decimal) in the same HH band ?

채택된 답변

Star Strider
Star Strider 2019년 12월 4일
One approach:
x = pi
AfterDecimal = rem(x,1)
FirstFour = fix(AfterDecimal*1E+4)*1E-4
producing:
x =
3.141592653589793
AfterDecimal =
0.141592653589793
FirstFour =
0.141500000000000
  댓글 수: 2
Abdul Gaffar
Abdul Gaffar 2019년 12월 4일
Thanks, and how to retrieve last 4 digits?
Star Strider
Star Strider 2019년 12월 4일
The easiest way to do that is to convert it to a character array and index the last four digits, then convert it back to a numerical variable:
xstr = num2str(AfterDecimal,15);
LastFour = str2double(xstr(end-3:end))
producing:
LastFour =
9793
Experiment to get different results.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by