How to get consistent import data outputs
3 views (last 30 days)
Show older comments
Im my program I am attempting to import multiple xcel files in a for loop. Then storing the results in a struct with dynamically named fields which I can evaluate later. However, when the for loop is done I get what is in the screenshot below the code.
for i=1:sizeOfSel
j = num2str(i);
fieldName = strcat('data_' , j);
stmfile = temp(i,:)
pathname = handles.A.dir;
tic
handles.A.data.(fieldName) = importdata(fullfile(pathname, stmfile));
toc
end
Ideally, I need every field to contain a structure that import data is outputting. But because only one or two of the files being processed actually fit the format, I can only process those files. The image shows the output of two identical xcel files.
0 Comments
Accepted Answer
Tim Tobias
on 29 Jun 2015
4 Comments
Walter Roberson
on 29 Jun 2015
The only thing about pattern that importdata() cares about is that it looks at the file extension to figure out how to handle the file. If your copy ended up without the .xls extension then it would have been treated as ASCII data. There is no provision to override that behaviour to tell it which helper to call. If you need to have it handle filenames with unexpected extension as if they were a particular type, then you should use the appropriate helper function such as xlsread()
More Answers (1)
Walter Roberson
on 29 Jun 2015
Are they really identical, or have some of them been saved in csv (Comma Separated Value) format, and some of them in binary format (.xls)? And possibly some of them are in .xlsx structured text format?
You will probably need to switch to xlsread() instead of importdata()
0 Comments
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!