app designerで、スライダーとplotの連動のさせ方が分かりません
Show older comments
App desingerにて、需要・供給曲線をplotするアプリを作成しております。
(1)スタートボタンを押したら、コールバックして、データをプロットする
(2)"y軸の価格"と"スライダの目盛"を連動させて、スライダーを動かしたら、需要曲線(青い方)の上にマークが出るようにする
(3)スライダーを動かすたびに、供給曲線のxの値と需要曲線のxの値を取得して、計算結果をスライダーの下に表示させる
という順番でアプリを作成しようと考えており、(1)の部分は出来たのですが、(2)で躓いております。スライダーのコールバックで、ValueChangedFunでコールバックはしてみたのですが、コールバックした際に、どうやったらスライダの目盛と需要曲線を連動させることが出来るでしょうか?Chat GPTに聞きながら試行錯誤をしているのですがうまく実装出来ず、何かアドバイスを頂けると大変ありがたいです。

(1)のコード
% Callback function: Button_5, Tab, UIAxes
function demandSupply(app, event)
% 価格、需要、供給のデータをテーブルとして定義
data = table([10000; 30000; 50000; 70000; 90000; 110000; 130000; 150000], ...
[4000; 3500; 3000; 2500; 2000; 1500; 1000; 500], ...
[700; 1400; 2100; 2800; 3500; 4200; 4900; 5600], ...
'VariableNames', {'Price', 'Demand', 'Supply'});
% プロット
blue = plot(app.UIAxes, data.Demand, data.Price, 'b-', 'LineWidth', 2, 'DisplayName', '需要曲線');
hold(app.UIAxes, 'on'); % UIAxesに対してholdを有効にする
red = plot(app.UIAxes, data.Supply, data.Price, 'r-', 'LineWidth', 2, 'DisplayName', '供給曲線');
xlabel(app.UIAxes,'数量(台)');
ylabel(app.UIAxes,'価格(万円)');
legend(app.UIAxes,'需要曲線','供給曲線');
% 軸の設定
ylim(app.UIAxes,[0 160000]); % y軸の範囲を設定
yticks(app.UIAxes,0:10000:160000); % y軸の刻みを設定
yticklabels(app.UIAxes,string((0:10000:160000) .* 1e-4)); % y軸の各刻みの表示文字(単位が万円なので1e-4倍)
xlim(app.UIAxes,[0 6000]); % x軸の範囲を設定
xticks(app.UIAxes,0:1000:6000); % x軸の刻みを設定
end
Accepted Answer
More Answers (1)
Hiro Yoshino
on 5 Nov 2024
1 vote
ValueChangedFun ではなくて、ValueChanngingFun でコールバックを設定すると良いかと思います
右クリックで call back の設定から選択可能です。
1 Comment
みち(プログラミング初心者)
on 6 Nov 2024
Categories
Find more on グラフィックス オブジェクトの識別 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!