unpreditable behavior of importdata
9 ビュー (過去 30 日間)
古いコメントを表示
I have a data file consisting of 5 headerlines
% Model: Test
% Version: Software
% Date: May 31 2022, 17:12
% Table: Table 2 - Global Evaluation 5
% Time (s) gesamte Drucknderung im Wasser (Pa)
followed by datalines, each dataline consisting of two numbers separated by spaces, looking like
0 -2.5760650371409015E-5
0.1 -0.015952065077219565
0.2 -0.004477893850765524
0.30000000000000004 -0.011908521809613106
0.4 -0.0073951747614778305
.....
If I use the command
A = importdata(filename);
I usually get automaticely the variables A.data and A.textdata
But in some cases the import just creates the variable A (not A.data), with A containing the numbers and ignoring the headerlines.
Finally importdata always works correctly if I use the full command with the option headerlines 5
A = importdata(filename,' ',5);
What I do not understand is:
Why does importdata mostly automaticely creates A.data and A.textdata, but at some importfiles of the identical structure it only puts the numbers into the variable A.
Of course that leads to error messages while importing a number of datafiles in a loop, when after 16 files correctly suddenly the import of datafile number 17 puts the data into a variable A instead of A.data-
12 件のコメント
Walter Roberson
2022 年 6 月 1 日
Though we do put up with uigetfile returning three different datatypes:
- numeric if user canceled
- cell array of character vectors if multiselect and user selected multiple files
- character vector otherwise
Also, some of the lower level i/o operations can return a different data type at end of file.
There are also a number of functions that can return [], the empty double precision array, instead of an expected datatype.
... but all of those are relatively easy to deal with, whereas importdata can return valid data in different datatype and when it returns struct, fields are missing when they do not apply, instead of being present but empty.
dpb
2022 年 6 月 1 日
編集済み: dpb
2022 年 6 月 1 日
"Though we do put up with uigetfile..."
That's thanks to Bill G and company FileOpen dialog isn't it, Walter? TMW has made the MATLAB interface to match on all platforms; I don't know the other OS native API well enough to know their returns as to whether they were written to be more regular or not..and that there's really no alternative but to create something totally independently(*). With file i/o in MATLAB, one now has pretty good control over what one's going to get albeit that comes at a "veritable plethora" of choices that makes the startup for the new user tougher.
find and the empty return is one often overlooked "gotcha!"
(*) ADDENDUM: One could, of course, write oneself a wrapper function around the builtin dialog function that preprocesses the output to regularize it for the calling code. Haven't really thought about how that might actually look to be simpler to use...
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!