Clear Filters
Clear Filters

listBoxの選択肢を変数から取得する方法

12 views (last 30 days)
SHromaneko
SHromaneko on 26 Jan 2024
Commented: SHromaneko on 29 Jan 2024
Matlab app designerにてListboxに表示する内容を変数から取得出来ますか?
エクセルファイルを読み込んでグラフを表示するアプリを作ろうと思います。
エクセルデータには大量のデータがあり、どのデータを表示するかを対話的に選択できるようにしたいです。
データの内容はエクセルファイルによって異なりますので、エクセルファイルの1行目に入っている計測データ名を取得し、それをリスト化することでどのデータを表示するかユーザーが選択できるようにしたいです。(下記のスクショのようなリスト変数txtを作成)
テキストの一行目の内容を変数に格納して、app.ListBox.Items = txtとすればいいのかと思いましたが、グレーの「編集不可」エリアになっているので出来なさそうです。
下記を実現する方法、もしくは代案何かありますでしょうか?
% Create ListBoxLabel
app.ListBoxLabel = uilabel(app.UIFigure);
app.ListBoxLabel.HorizontalAlignment = 'right';
app.ListBoxLabel.Position = [24 312 48 22];
app.ListBoxLabel.Text = 'List Box';
% Create ListBox
app.ListBox = uilistbox(app.UIFigure);
app.ListBox.Items = {'name1', 'name2'};
app.ListBox.Position = [87 262 100 74];
app.ListBox.Value = {};

Accepted Answer

Hiroshi Iwamura
Hiroshi Iwamura on 26 Jan 2024
Excelファイルを読み込む部分で、 app.ListBox.Items に、cell あるいは string 形式で入れれば大丈夫です
  2 Comments
Atsushi Ueno
Atsushi Ueno on 27 Jan 2024
自分で関数を作って(例えばstartupFcn)そこで処理をすれば良いです。これでうまくいきましたよ
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
[filename,path] = uigetfile('*.xlsx');
[num,txt,raw] = xlsread([path,filename]); % readtable, readmatrix, readcell 等に代えてね
app.ListBox.Items = txt;
end
end
SHromaneko
SHromaneko on 29 Jan 2024
できました、ありがとうございます!

Sign in to comment.

More Answers (0)

Categories

Find more on GUIDE アプリの移行 in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!