Outputting imported files in Matlab App Designer
5 次查看(过去 30 天)
显示 更早的评论
I have created a file import dialogue from on my app Designer. The file I have imported are generally .txt files which I need to do two tasks with.
Firstly, I need to read the output (the imported file) and save it in its .txt format.
Secondly I would like to import the same into Matlab as a table and save the same as such.
Below is the code that I have managed to write on the same
value = app.Select_DLRDropDown.Value;
[file,path]=uigetfile;
DLR_siteA=fullfile(path,file);
site_A =DLR_siteA; % the app runs succesfully upto this point when I press the Select_DLR button but it does not open the file site_A
open("site_A"); % returns 'The variable site_A does not exist'.
How can I be able to save the file that has been imported by this tool? And is it possible to convert it directly to a Mat table first then output it as a table?
Any support is appreciated.
0 个评论
采纳的回答
Guillaume
2019-5-10
At no point does your code attempt to import anything.
DLR_siteA=fullfile(path,file);
Ok, this store the full path of the file selected in the DLR_siteA variable.
site_A = DLR_siteA;
As always in matlab, when you do A = B, you copy the content of the B variable into the A variable. In your case, B (DLR_siteA) is the full path of the file, so you've just copied the full path of the file into variable site_A
open("site_A");
As documented, open opens a file in the appropriate application. On windows a text file, will typically be opened in notepad. open does not do import. In any case, what you're passing to open is the filename "site_A" (I'd wager that file doesn't exist), not the content of the site_A variable.
Assuming the file you want to import is a text file. There are many ways you can use. Which one is more appropriate depends on the format of your text file. So if you want more help attach an example file. For well formatted text files, the simplest way to import them is with readtable which would give you the table you desire.
I'm a bit confused by that sentence: I need to read the output (the imported file) and save it in its .txt format. The output of what? And why would you save back the file in the same format it started as?
9 个评论
Guillaume
2019-5-18
编辑:Guillaume
2019-5-18
1) You ask the user for a file name and path for the mat file, then completely ignore it and use DataA as the file name.
2) The function to save data as mat file is save. Indeed writematrix only writes text or excel files.
So:
save(fullfile(path, file), 'Data'); %Save Data in the mat file specified by the user.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!