Write arrays with exact values from .txt files with scientific notation

조회 수: 3 (최근 30일)
teasy
teasy 2020년 9월 12일
댓글: teasy 2020년 9월 13일
Hello together,
i read values from .txt files. The values are in scientific notation and have the form
0.7553396358543418E-01
0.7553483893557424E-01
.....
My suggestion for this:
folder = ['foldername'];
filename_t = fullfile(folder, sprintf('%dHz_t_LS_%d.txt', f_sim, LS));
fileID_t = fopen(filename_t, 'rt');
t_total = textscan(fileID_t, '%sf,'HeaderLines',0);
t_total = t_total{1};
But unfortunately it never gives the correct value. I only get values in the form 0.0750, which is much too low accuracy.
i have already experimented with %16.8f etc., but did not reach my goal
Many greetings
  댓글 수: 2
Stephen23
Stephen23 2020년 9월 12일
"My suggestion for this"
will not work because the syntax is not valid:
t_total = textscan(fileID_t, '%sf,'HeaderLines',0);
% ^ ^ ^
teasy
teasy 2020년 9월 13일
this was a copy error, so the correct command would be
t_total = textscan(fileID_t, '%f','HeaderLines',0);
but even this does not give the desired result

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

채택된 답변

Star Strider
Star Strider 2020년 9월 12일
I suspect you have the format set at:
format short
Setting it to
format long
may be the solution,.
  댓글 수: 9
Mario Malic
Mario Malic 2020년 9월 13일
Well, That's why the context is important in the question.
teasy
teasy 2020년 9월 13일
The problem was that I looked at the variable in the workspace and the workspace display was short.
Sorry for the circumstances but thanks for the help!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by