Info

This question is closed. Reopen it to edit or answer.

Error when i change value in slider

1 view (last 30 days)
Kelsey Pettrone
Kelsey Pettrone on 10 Nov 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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')

Answers (0)

This question is closed.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!