Load and save excel or txt with GUI
3 views (last 30 days)
Show older comments
I want to load and save numeric data file (excel, csv, txt) with push button in GUI. I need to save that file into .mat file in main workspace. File will always have one column and several hundred rows. Files can have different paths and will not be in same folder.
I have tried variations of uigetfile and uiimport, but with no success. Can you please tell me what code should be in push button callback?
I dont know how to load, read and save that data files (just numbers) properly into workspace as matrix.
Thank you.
If I use it like this:
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, filepath]=uigetfile({'*.txt';'*.xls';'*.csv';'*.xlsx'},'Select your file');
data=load([filepath filename]);
I get error
Error using load
Number of columns on line 421 of ASCII file C:\path\file.txt must be the same as previous lines.
If I use
data=uiimport('-file');
I can select data, adjust columns etc. but nothing saves into variable "data".
2 Comments
Adam
on 7 Mar 2017
If you want code that will read .xls, .txt or .csv you need to understand the formats of the files you want to read in each. We don't know what is in file.txt, but the error message you got is quite self-explanatory on what the problem was with that file. Maybe you need to write your own code to read in that file rather than use a generic load functionality that doesn't work with your file format.
Answers (0)
See Also
Categories
Find more on Data Import from MATLAB 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!