listBoxの選択肢を変数から取得する方法
    2 次查看(过去 30 天)
  
       显示 更早的评论
    
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 = {};

0 个评论
采纳的回答
  Hiroshi Iwamura
      
 2024-1-26
        Excelファイルを読み込む部分で、 app.ListBox.Items に、cell あるいは string 形式で入れれば大丈夫です
2 个评论
  Atsushi Ueno
      
 2024-1-27
				自分で関数を作って(例えば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

更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 スプレッドシート 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

