Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Error when i change value in slider

1 回表示 (過去 30 日間)
Kelsey Pettrone
Kelsey Pettrone 2020 年 11 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
An error comes up when i try to change the value of the slider in my app that says
"Error using bar (line 171)
When X is a scalar, Y must be a vector."
It works fine when i change the countries but when i change the year it doesnt work. I have attached the data that i am working off of, the app, and the full funtion file.
please let me know if you know why this error is coming up.
function deliverable1(app)
data = readtable('RiskFactorAnalysis (1).csv');
userinput = app.CountryDropDown.Value;
userinput2 = app.CountryDropDown_2.Value;
useryear = app.Slideryear.Value
ind = strcmp(data.Entity,userinput);
year = data.Year(ind);
deaths = data.Total_Deaths_per_100000(ind);
obesity = data.Obesity_Deaths_per_100000(ind);
Drug = data.Drug_Deaths_per_100000(ind);
Alcohol = data.Alcohol_Deaths_per_100000(ind);
smoking = data.Smoking_Deaths_per_100000(ind);
% Extract all info for userinput2
ind2 = strcmp(data.Entity,userinput2);
year2 = data.Year(ind2);
deaths2 = data.Total_Deaths_per_100000(ind2);
obesity2 = data.Obesity_Deaths_per_100000(ind2);
Drug2 = data.Drug_Deaths_per_100000(ind2);
Alcohol2 = data.Alcohol_Deaths_per_100000(ind2);
smoking2 = data.Smoking_Deaths_per_100000(ind2);
indY2 = year2==useryear; % again, use year2, not year
grid(app.Axes3,'on')
bpcombined = [obesity2, Drug2, Alcohol2, smoking2];
bar(app.Axes3,useryear,bpcombined(indY2,:),'grouped'); % Note that I am only plotting 1 row of bpcombined here
xlabel(app.Axes3,'year')
ylabel(app.Axes3,'deaths')
title(app.Axes3,userinput2)
legend(app.Axes3, 'Obesity', 'Drug', 'Alcohol', 'Smoking')

回答 (0 件)

この質問は閉じられています。

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by