How to retrieve first 4 digits after decimal point?
16 ビュー (過去 30 日間)
古いコメントを表示
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 ?
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!