3 views (last 30 days)

Image Analyst
on 25 Jun 2020

Fangjun Jiang
on 25 Jun 2020

This is probably the limitation of the smartness of the importdata() function.

If you look at filec.textdata, you will get a clue. It tries to separate the data based on 'line-10'. 'line-10' is read in correctly. All the lines below, either the digit "0" or "0." are treated and included in as the text data.

So for 'line-20', "0" is truncated but ".5474641" is still read in as "0.5474641"

for "line-30', "0." is truncated thus "59778373" is read in as "59778373"

For your input file text format, it's better to use textscan(), although it can't be done with one line of code.

For this particular file "'tem-009.out'", I tried A=readmatrix(filename,'filetype','text') and it does give correct result.

Image Analyst
on 5 Jul 2020

Image Analyst
on 5 Jul 2020

Stephen Cobeldick
on 25 Jun 2020

opt = {'CollectOutput',true };

[fid,msg] = fopen('tem-009.out','rt');

assert(fid>=3,msg)

str = '';

while ~strncmp(str,'-',1)

str = fgetl(fid);

end

C = textscan(fid,'line-%f%f',opt{:});

fclose(fid);

M = C{1};

Giving:

>> M

M =

10.0000 0.7539

20.0000 0.5475

30.0000 0.5978

50.0000 0.3828

70.0000 0.5847

90.0000 0.1664

110.0000 0.2465

130.0000 0.5116

150.0000 0.3211

160.0000 0.3744

170.0000 0.6611

Fangjun Jiang
on 6 Jul 2020

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912109

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912109

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912142

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912142

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912421

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912421

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912802

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_912802

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_913108

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/554101-why-i-the-data-processed-by-the-matlab-is-wrong-it-reports-three-wrong-results-what-is-the-reason-a#comment_913108

Sign in to comment.