Load and save excel or txt with GUI

3 Ansichten (letzte 30 Tage)
LamaObecna
LamaObecna am 7 Mär. 2017
Bearbeitet: LamaObecna am 7 Mär. 2017
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 Kommentare
Adam
Adam am 7 Mär. 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.
LamaObecna
LamaObecna am 7 Mär. 2017
Bearbeitet: LamaObecna am 7 Mär. 2017
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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by