creating App design control buttons programmically

3 ビュー (過去 30 日間)
Stetson Spencer
Stetson Spencer 2018 年 11 月 21 日
回答済み: Kojiro Saito 2018 年 11 月 21 日
I'm trying to create an app design that would read an xls spreadsheet and create a new button if someone was to go in and add an extra column of data.
Initially I thought of doing a "for loop" statement, but I don't know the code that would generate a new button for how ever many columns that are added in the spreadsheet.

採用された回答

Kojiro Saito
Kojiro Saito 2018 年 11 月 21 日
I have two ideas.
  • Idea 1: Creates buttons from the first but make the button invislble in a startup function.
% Code that executes after component creation
function startupFcn(app)
app.Button.Visible = 'off';
end
Then, make the button visible at the timing when you want.
app.Button.Visible = 'on';
I think this approach is bettter than idea 2 because you can control the layout and
  • Idea 2: Create a button programmically
You can create a button by "uibutton". But you need to locate a new button properly by setting Postion.
The following example will create a button 120px right to the existing Button1.
% Button pushed function: Button
function ButtonPushed(app, event)
pos = app.Button.Position;
app.Button1 = uibutton(app.UIFigure, 'push');
app.Button1.Position = [pos(1)+120 pos(2) pos(3) pos(4)];
app.Button1.ButtonPushedFcn = {@mybuttondown,app};
% Button push function for a new button
function mybuttondown(src,eve,app)
msgbox('Hello')
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by