changing exponential value into float

I normalized 'area' data between zero and one. Then I write that values into xl sheet. But many values are exponential. I want to change that exponential values to float type. Please somebody help.
This is my code:
max_Ar=max(Ar);
min_Ar=min(Ar);
range=(max_Ar-min_Ar)+ eps(max_Ar-min_Ar);
for i=1:100
Area(i)=(Ar(i)-(min_Ar - eps(max_Ar-min_Ar)))/range;
ex = 10^(3-floor(log10(Area(i))));
Area(i)= round(Area(i) * ex) / ex;
end
xlswrite('Tomato_Yellow_Leaf_Curl_Virus.xlsx',Ar(:))
xlswrite('Tomato_Yellow_Leaf_Curl_Virus1.xlsx',Area(:))

댓글 수: 4

Walter Roberson
Walter Roberson 2020년 1월 31일
If for example one entry was 1.23e-8 then what float would you want? Do you want to just change it to have as many leading or trailing zeroes as needed, or do you want to round numbers with abs() value less than something to be 0?
Sajitha K.N.
Sajitha K.N. 2020년 2월 1일
No I want values between 0 and 1.
You did not answer my questions.
Sajitha K.N.
Sajitha K.N. 2020년 2월 1일
I want to just change it to have as many leading or trailing zeroes as needed.

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

답변 (2개)

Subhadeep Koley
Subhadeep Koley 2020년 2월 1일

0 개 추천

Hi Sajitha, Try the code below.
clc;
max_Ar = max(Ar);
min_Ar = min(Ar);
range = (max_Ar - min_Ar) + eps(max_Ar - min_Ar);
for i = 1:100
Area(i) = (Ar(i) - (min_Ar - eps(max_Ar-min_Ar))) / range;
ex = 10^(3-floor(log10(Area(i))));
Area(i) = round(Area(i) * ex) / ex;
Area(i) = str2double(sprintf('%f', Area(i)));
Ar(i) = str2double(sprintf('%f', Ar(i)));
end
xlswrite('Tomato_Yellow_Leaf_Curl_Virus.xlsx', double(Ar(:)));
xlswrite('Tomato_Yellow_Leaf_Curl_Virus1.xlsx', double(Area(:)));
Walter Roberson
Walter Roberson 2020년 2월 1일
편집: Walter Roberson 2020년 2월 1일

0 개 추천

dlmwrite with a precision of '%.1074f' should handle all of the cases.
Possibly with the processing you are doing you might be able to use a considerably smaller number than 1074. 1074 is needed for eps(realmin)

댓글 수: 2

Sajitha K.N.
Sajitha K.N. 2020년 2월 2일
My dataset is very big one. Is this code slow down the process?
Yes. Conversion of binary to characters is done in software, not in hardware. The more digits you convert, the more time it takes the software.
File i/o time mostly depends on the number of full blocks of data to be written; when you write more characters then it is going to take more time.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 1월 31일

댓글:

2020년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by