Load data as structure in Matlab App Designer

11 ビュー (過去 30 日間)
Learning
Learning 2023 年 6 月 14 日
編集済み: Manash Sahoo 2023 年 6 月 15 日
Hi, still learning here: I am able to import .spc files into Matlab workspace using the tgspcread function. In Matlab I import the data first as a structure using dir(‘*spctrum.spc’) and then able to extract certain fields. I am trying to import the same data initially as structure in app designer. When I use uigetfile, it only import the file names and not the structure I am looking for. Is there a way to import data as structure in Matlab app designer? Thanks!

回答 (2 件)

Manash Sahoo
Manash Sahoo 2023 年 6 月 14 日
I don't have the tgspcread function, but I imagine that you are looking for something like this:
[file,path] = uigetfile();
data = tgspcread(strcat(path,file));
  2 件のコメント
Learning
Learning 2023 年 6 月 14 日
Thank you for your response. What if I want to load multiple files at the same time? Right now file is just a char with a single name in it.
Manash Sahoo
Manash Sahoo 2023 年 6 月 15 日
編集済み: Manash Sahoo 2023 年 6 月 15 日
If you want to load multiple files at the same time, then you can enable the 'multiselect' parameter in uigetfile. I believe it would be along the lines of this:
[files,path] = uigetfile('Multiselect','on');
data = {};
for i = 1:numel(files)
data{i} = tgspcread(strcat(path,files{i}));
end

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


Stephen23
Stephen23 2023 年 6 月 14 日
編集済み: Stephen23 2023 年 6 月 14 日
Here is a simple way to convert the output from UIGETFILE to a non-scalar structure similar to that returned by DIR:
[F,P] = uigetfile(..);
S = struct('name',cellstr(F));
[S.folder] = deal(P)
  2 件のコメント
Learning
Learning 2023 年 6 月 14 日
Thanks for your response. What is the ‘name’ in the code?
Stephen23
Stephen23 2023 年 6 月 15 日
編集済み: Stephen23 2023 年 6 月 15 日
"What is the ‘name’ in the code?"
You wrote in our question that "I import the data first as a structure using dir(‘*spctrum.spc’) and then able to extract certain fields. I am trying to import the same data initially as structure in app designer. When I use uigetfile, it only import the file names and not the structure I am looking for. Is there a way to import data as structure..."
From this I understood that you wanted to replicate the structure returned by DIR. The structure returned by DIR has several fields, the main ones used by most users are NAME and FOLDER, which also are the ones that can be defined by the output from UIGETFILE. And so my answer defines exactly those fields, first by calling STRUCT with appropriate input arguments, one of which is the NAME fieldname.
You can look at the outputs yourself, make small changes, see what happens... and read the documentation.

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

カテゴリ

Help Center および File ExchangeLive Scripts and Functions についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by