Why I the data processed by the matlab is wrong, it reports three wrong results,what is the reason?All the data and .m files are included ,who can help me?

6 views (last 30 days)
Why I the data processed by the matlab is wrong, it reports three wrong results,what is the reason?All the data and .m files are included ,who can help me?
  5 Comments
huazai2020
huazai2020 on 25 Jun 2020
You see the yellow word, the left are the primary data,the right are the process data, you see they are different, what is the reason?

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 25 Jun 2020
The display looks a little different but that's probably just due to the third column not being wide enough to show the same number of digits. Grab the divider line between the columns and widen it. It should look the same after that.
  1 Comment
huazai2020
huazai2020 on 25 Jun 2020
No, the value are not the same, the left is 0.58(Decimal), the right is 58469706(interger), they cannot be the same.You can use my data to have a try, you can find my problem.

Sign in to comment.


Fangjun Jiang
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.
  12 Comments
huazai2020
huazai2020 on 5 Jul 2020
Can I updata it directly to r2020a, or I should download a new one and setup it again.
What is the difference of importdata() or csvread() or dlmread()? Thank you.
Image Analyst
Image Analyst on 5 Jul 2020
csvread() reads only comma separated values. dlmread() can have other delimiters in addition to commas. importdata() tries to be a smarter function than either of those two in that the data can be more complicated and it will try to figure it out.

Sign in to comment.


Stephen23
Stephen23 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
  13 Comments

Sign in to comment.

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!