This is a static copy of a profile reportHome
importdata (4 calls, 10.810 sec)
Generated 05-Aug-2011 13:01:21 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/iofun/importdata.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
210 | [out, delimiter, headerlines] ... | 4 | 10.591 s | 98.0% |  |
132 | [FileType,~,loadCmd,descr] = f... | 4 | 0.219 s | 2.0% |  |
239 | end | 4 | 0 s | 0% |  |
238 | end | 4 | 0 s | 0% |  |
235 | elseif isempty(names) | 4 | 0 s | 0% |  |
All other lines | | | 0 s | 0% |  |
Totals | | | 10.810 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
importdata>LocalTextRead | subfunction | 4 | 10.591 s | 98.0% |  |
finfo | function | 4 | 0.208 s | 1.9% |  |
Self time (built-ins, overhead, etc.) | | | 0.011 s | 0.1% |  |
Totals | | | 10.810 s | 100% | |
Code Analyzer results
Line number | Message |
169 | WK1READ will be removed in a future release. There is no simple replacement for this. |
174 | AVIREAD will be removed in a future release. Use MMREADER instead. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 239 |
Non-code lines (comments, blank lines) | 99 |
Code lines (lines that can run) | 140 |
Code lines that did run | 59 |
Code lines that did not run | 81 |
Coverage (did run/can run) | 42.14 % |
Function listing
time calls line
1 function [out, delimiter, headerlines] = importdata(varargin)
2 %IMPORTDATA Load data from file.
3 %
4 % IMPORTDATA(FILENAME) loads data from FILENAME into the workspace.
5 %
6 % A = IMPORTDATA(FILENAME) loads data into A.
7 %
8 % IMPORTDATA(FILENAME, DELIM) interprets DELIM as the column separator in
9 % ASCII file FILENAME. DELIM must be a string. Use '\t' for tab.
10 %
11 % IMPORTDATA(FILENAME, DELIM, NHEADERLINES) loads data from ASCII file
12 % FILENAME, reading numeric data starting from line NHEADERLINES+1.
13 %
14 % [A DELIM] = IMPORTDATA(...) returns the detected delimiter character
15 % for the input ASCII file.
16 %
17 % [A DELIM NHEADERLINES] = IMPORTDATA(...) returns the detected number of
18 % header lines in the input ASCII file.
19 %
20 % [...] = IMPORTDATA('-pastespecial', ...) loads data from the system
21 % clipboard rather than from a file.
22 %
23 % Notes:
24 %
25 % If IMPORTDATA recognizes the file extension, it calls the MATLAB helper
26 % function designed to import the associated file format. Otherwise,
27 % IMPORTDATA interprets the file as a delimited ASCII file.
28 %
29 % When the helper function returns more than one nonempty output,
30 % IMPORTDATA combines the outputs into a structure array. For details,
31 % type "doc importdata" at the command prompt.
32 %
33 % For ASCII files and spreadsheets, IMPORTDATA expects to find numeric
34 % data in a rectangular form (that is, like a matrix). Text headers can
35 % appear above or to the left of numeric data. To import ASCII files
36 % with numeric characters anywhere else, including columns of character
37 % data or formatted dates or times, use TEXTSCAN instead of IMPORTDATA.
38 % When importing spreadsheets with columns of nonnumeric data, IMPORTDATA
39 % cannot always correctly interpret the column and row headers.
40 %
41 % Examples:
42 %
43 % 1) Import and display an image:
44 %
45 % nebula_im = importdata('ngc6543a.jpg');
46 % image(nebula_im);
47 %
48 % 2) Using a text editor, create an ASCII file called myfile.txt:
49 %
50 % Day1 Day2 Day3 Day4 Day5 Day6 Day7
51 % 95.01 76.21 61.54 40.57 5.79 20.28 1.53
52 % 23.11 45.65 79.19 93.55 35.29 19.87 74.68
53 % 60.68 1.85 92.18 91.69 81.32 60.38 44.51
54 % 48.60 82.14 73.82 41.03 0.99 27.22 93.18
55 % 89.13 44.47 17.63 89.36 13.89 19.88 46.60
56 %
57 % Import the file, and view columns 3 and 5:
58 %
59 % M = importdata('myfile.txt', ' ', 1);
60 % for k = [3, 5]
61 % disp(M.colheaders{1, k})
62 % disp(M.data(:, k))
63 % disp(' ')
64 % end
65 %
66 % See also LOAD, FILEFORMATS, TEXTSCAN, OPEN, LOAD, UIIMPORT.
67
68 % Copyright 1984-2009 The MathWorks, Inc.
69 % $Revision: 1.17.4.36 $ $Date: 2010/08/23 23:10:38 $
70
4 71 error(nargchk(1,4,nargin,'struct'));
4 72 error(nargoutchk(0,3,nargout,'struct'));
73
4 74 FileName = varargin{1};
75
4 76 if nargin > 1
4 77 delim.requested = varargin{2};
78 else
79 delim.requested = NaN;
80 end
81
4 82 if nargin > 2
4 83 requestedHeaderLines = varargin{3};
84 else
85 requestedHeaderLines = NaN;
86 end
87
4 88 out = [];
89
4 90 if nargout > 1
91 delim.printed = [];
92 delimiter = [];
93 end
94
4 95 if nargout > 2
96 headerlines = 0;
97 end
98
4 99 bFlatten = true;
4 100 if nargin > 3 && isfield(varargin{4}, 'Flatten')
101 FlattenInput = varargin{4}.Flatten;
102 if islogical(FlattenInput) && isscalar(FlattenInput)
103 bFlatten = FlattenInput;
104 end
105 end
106
4 107 if strcmpi(FileName,'-pastespecial')
108 % fetch data from clipboard
109 cb = clipboard('paste');
110 if isnan(delim.requested)
111 delim.printed = guessdelim(cb);
112 delim.requested = delim.printed;
113 else
114 delim.printed = sprintf(delim.requested);
115 end
116 %When importing data from clipboard, do not warn of format mismatches.
117 bWarn = false;
118 try
119 [out.data, out.textdata, headerlines] = parse(cb, ...
120 delim, requestedHeaderLines, bWarn);
121 catch %#ok<CTCH>
122 error(message('MATLAB:importdata:InvalidClipboardData'));
123 end
124 out = LocalRowColShuffle(out);
125 delimiter = delim.printed;
4 126 else
127
128 % attempt extracting descriptive information about file
4 129 warnState = warning('off', 'MATLAB:xlsfinfo:ActiveX');
4 130 warnState(2) = warning('off', 'MATLAB:avifinfo:FunctionToBeRemoved');
4 131 try
0.22 4 132 [FileType,~,loadCmd,descr] = finfo(FileName);
4 133 warning(warnState);
134 catch %#ok<CTCH>
135 warning(warnState);
136 error(message('MATLAB:importdata:FileNotFound'));
137 end
138
139 % Test success of FINFO call
4 140 if strcmp(descr,'FileInterpretError')
141
142 % Generate a warning that FINFO could not interpret data file
143 Message = 'File contains uninterpretable data.';
144 warning('MATLAB:IMPORTDATA:InvalidDataSection',Message)
145 out.data=[]; % return an empty matrix object
146 out.textdata={}; % return an empty cell object
147 return
148 end
149
4 150 delim.printed = NaN;
4 151 delimiter = delim.printed;
152 %Just in case we found incorrect command, i.e. the name was a
153 %coincidence, we'll try to load, but if we fail, we'll try to load
154 %using other means.
4 155 loaded = 0;
4 156 if ~isempty(loadCmd) && ~strcmp(loadCmd,'importdata')
157 try
158 out.data = feval(loadCmd, FileName);
159 loaded = 1;
160 catch exception %#ok<NASGU>
161 end
162 end
4 163 if (loaded == 0)
4 164 if (strncmp(FileType, 'xls', 3) > 0)
165 out = readFromExcelFile(FileName, descr, out, bFlatten);
4 166 else
4 167 switch FileType
4 168 case 'wk1'
169 [out.data, out.textdata] = wk1read(FileName);
170 out = LocalRowColShuffle(out);
4 171 case 'avi'
172 S = warning('off', 'MATLAB:aviread:FunctionToBeRemoved');
173 cleaner = onCleanup(@()warning(S));
174 out = aviread(FileName);
4 175 case 'im'
176 [out.cdata, out.colormap, out.alpha] = imread(FileName);
4 177 case {'au','snd'}
178 [out.data, out.fs] = auread(FileName);
4 179 case 'wav'
180 [out.data, out.fs] = wavread(FileName);
4 181 case 'mat'
182 wasError = false;
183 try
184 if ~isempty(whos('-file',FileName))
185 % call load with -mat option
186 out = load('-mat',FileName);
187 else
188 wasError = true;
189 end
190 catch exception %#ok<NASGU>
191 wasError = true;
192 end
193 if wasError
194 % call load with -ascii option
195 out = load('-ascii',FileName);
196 end
197 if isempty(out)
198 error(message('MATLAB:importdata:InvalidFile'));
199 end
4 200 otherwise
201 % try to treat as hidden mat file
4 202 try
4 203 out = load('-mat',FileName);
4 204 catch exception %#ok<NASGU>
4 205 out = [];
4 206 end
4 207 if isempty(out)
4 208 try
209 % file is an unknown format, treat it as text
10.59 4 210 [out, delimiter, headerlines] = LocalTextRead(FileName, delim, requestedHeaderLines);
211 catch myException
212 finalException = MException('MATLAB:importdata:UnableToRead', 'Unable to load file.\nUse TEXTSCAN or FREAD for more complex formats.\n%s');
213 finalException = finalException.addCause(myException);
214 throw(finalException);
215 end
4 216 end
4 217 end
4 218 end
4 219 end
4 220 end
221
4 222 if (length(out) == 1 && isstruct(out))
223 % remove empty fields from output struct
4 224 names = fieldnames(out);
4 225 for i = 1:length(names)
12 226 if isempty(out.(names{i}))
227 out = rmfield(out, names{i});
228 end
12 229 end
4 230 if ~isempty(out)
231 % flatten output struct if single variable
4 232 names = fieldnames(out);
4 233 if bFlatten && length(names) == 1
234 out = out.(names{1});
4 235 elseif isempty(names)
236 out = [];
237 end
4 238 end
4 239 end
Other subfunctions in this file are not included in this listing.