Trying to Import Excel Data using GUIDE push button

13 ビュー (過去 30 日間)
Tessa Aus
Tessa Aus 2016 年 6 月 3 日
コメント済み: Tessa Aus 2016 年 6 月 14 日
I am trying to create a GUI that contains a Push Button that finds an excel file, and then extracts the data and creates a .m file of the Data so that in the future rows can be selected and analyzed using the GUIDE GUI. I am able to find the file with the Push Button but once the file is selected and Open is pressed a series of errors come up.
Here is what I have ...
function pushbutton1_Callback(hObject, eventdata, handles)
path = 'c:\users\userName\my documents\matlab';
filter = '*.csv';
selectedFile = uigetfile(fullfile(path , filter));
num = xlsread(filename);
  3 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 6 月 3 日
Tessa - what are the errors?
Tessa Aus
Tessa Aus 2016 年 6 月 7 日
編集済み: Tessa Aus 2016 年 6 月 7 日
So I was able to manually find the file with the push button and then export it but now I need to find a way to instead find the file then take that file and import it into a .mat file. For example below is noted the InputInspectionFile.xlsx is manually entered and converted instead I want to grab the filename.xlsx that the user chose through file selection. Thanks guys!
% code
FilePath_Callback(hObject, eventdata, handles)
[filename pathname] = uigetfile({'.xlsx'},'File Selector');
fullpathname = strcat(pathname, filename);
text = fileread(fullpathname);
set(handles.FullPathName, 'String', fullpathname);
[num,txt,raw] = xlsread('InputInspectionFile.xlsx');
save('InputInspectionFile')
% code
end

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 6 月 8 日
Tessa - use fullfile rather than strcat to create the full file name from the path and name. If you want to save the data from the Excel file to a mat file, then why not just do
save('myData.mat','raw');
which will save the data extracted from your Excel file into a mat file named myData.mat.
  16 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 6 月 10 日
I can't help but wonder why the path to the file is not being prepended to the excelFullfilename. What is the pathname in
[filename pathname] = uigetfile({'.xlsx'},'File Selector');
Tessa Aus
Tessa Aus 2016 年 6 月 14 日
There was something indeed wrong with the file but was not recognizable unless the file was opened not from Matlab. Your code worked, thank you so so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by