Trying to add a range slider that control the range from the given years in app.year but everything I had tried doesn't work

3 ビュー (過去 30 日間)
function LoadDataButtonPushed(app, event)
SJBS= 'SolarJobsbyState.csv';
app.JBS = readtable(SJBS);
app.year= app.JBS{52, 2:7};
app.stateDropDownLabel.Visible = 'on';
app.stateDropDown.Visible = 'on';
app.YearsSliderLabel.Visible = 'on';
app.YearsSlider.Visible = 'on';
app.YearsSlider.Limits = [min(app.year), max(app.year)];
app.YearsSlider.Value = [min(app.year), max(app.year)];
app.YearsSlider.MajorTicks = app.year;
app.LoadDataButton.Visible ='off';
end
% Value changed function: stateDropDown
function stateDropDownValueChanged(app, event)
State = app.stateDropDown.Value;
switch State
case 'Alabama'
hold(app.UIAxes, "off")
plot(app.UIAxes,app.year,app.JBS{1,2:7},'ob')
%ployfit- provies coefficients for the regression
%equation
plot(app.UIAxes,app.year,app.JBS{1,2:7},'-o')
ALAcoef= polyfit(app.year,app.JBS{1,2:7},1);
% IPDcoef= [m,b]
m= ALAcoef(1);
b= ALAcoef(2);
%function handle
ALAFUNC= @(x) m*x+b;
%regression equation
hold(app.UIAxes,"on")
fplot(app.UIAxes,ALAFUNC,[min(app.year),max(app.year)],'-r')
function YearsSliderValueChanged(app, event)
selectedyr = app.YearsSlider.Value;
end
%i want to be able to change the range of app.year using the range slider but everything i have tried doing work, please set me on the right path

採用された回答

Divyajyoti Nayak
Divyajyoti Nayak 2024 年 10 月 19 日
編集済み: Divyajyoti Nayak 2024 年 10 月 19 日
I assume you just want to change the limits of the x axis using the slider and are not able to do so. The "XLim" property of the "UIAxes" object can be used for this. Here's the documentation to help you out:
Here's how it can be implemented:
function YearsSliderValueChanged(app, event)
selectedyr = app.YearsSlider.Value;
%Need integers from slider, hence change slider step to 1
app.UIAxes.XLim = selectedyr;
app.UIAxes.XTick = selectedyr(1):1:selectedyr(2);
end
Results:
Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by