function to import varying size text file automatically ? - one step beyond the Import Data Wizard

1 view (last 30 days)
The Import Data Wizard is a great little tool to use on one file, say "Customers_1.txt" ... then the user gets presented with 3 options:
1) Import Data 2) Import Script 3) Import Function
Now ... question: WHY would you want to generate a Function if not to automate a process? Why would you want to automate a process if not for dynamically import various other similar files to "Customers_1.txt"? Another fair assumption: Why would the the {Import Wizard -> Generate a Function} developer think that "Customers_N.txt" file which will be imported further down the line as part of an automated process (using this generated function), is similar in size (as in Number of Columns) as "Customers_1.txt" that was used to generate the function? They all may be similar in syntax, types and logic but some files might have more columns than other (where new columns is new data, not new features).
This is the default: any function generated is hard-coded on the initial file in terms of nr of columns such as in the below:
%%Initialize variables.
delimiter = ',';
if nargin<=2
startRow = 1;
endRow = inf;
%%Format for each line of text:
% column1: double (%f)
% column2: double (%f)
% column8550: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%f%f%f%f...
Which to me, is half as useful. This might easily translate into a feature enhancement on the way import functions are generated, but meanwhile:
QQQ: Is it possible to generate a function from GUI to dynamically load files larger (in terms of nr or columns) than the original one? If not, how would you approach modifying the resulted function to make it more general?

Answers (0)


Find more on Data Type Conversion in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!