필터 지우기
필터 지우기

Outputting imported files in Matlab App Designer

조회 수: 1 (최근 30일)
Lui
Lui 2019년 5월 10일
편집: Guillaume 2019년 5월 18일
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.

채택된 답변

Guillaume
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
Lui
Lui 2019년 5월 18일
Thank you all for the guidance. I realized I had not specified any file in my initial code. so for any other person in the same problem I did the following for the button Load
% Button pushed function: LoadM2002Button
function LoadM2002ButtonPushed(app, event)
%load file1
[filename, pathname] = uigetfile('*.txt','Please select txt files containing project code info...','MultiSelect','off');
Data=readtable([pathname,filename]);
Then afterwards I did modify my data as desrired
% Retrieve the table
Data=Data(2:end,1:40);
Data=table2array(Data(:,:)); % needed the data as a matruix
finally I strored it in my working directory
[file,path] = uiputfile('*.MAT','Please select or provide .MAT file filename for extracted project code info...');
writematrix(Data,'DataA');
That worked. But the file I got was not a Matlab file. It was a text file. So any help will still be appreciated.
Guillaume
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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by