Load and save excel or txt with GUI

3 次查看(过去 30 天)
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 个评论
Adam
Adam 2017-3-7
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.
LamaObecna
LamaObecna 2017-3-7
编辑:LamaObecna 2017-3-7
Every file will be filled just with numbers in one column. I think problem with file.txt is that numbers are like 0,1636 and matlab thinks comma is seperating columns, not decimal number.
So If I load file.xls I have to use xlsread, for csv csvread etc.?
I tried this:
data=uiimport('-file');
assignin('base','data',data)
and now I can just choose column separator but desired data are saved in struct, not in matrix. How to save it into matrix?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by