MATLAB: Need Help plotting things from a table

appdatagroupinghelploadMATLABreadtablestrcmptable

I have attached the table i am working from. I want the user to input a country and then i want to plot the deaths for every year in that country.
I though strcmp might work but it isnt. this is all I have so far.
clear all
clc
data = readtable('RiskFactorAnalysis (1).csv');
userinput = input('Enter a Country: ','s');
Country = data(:,1);

Best Answer

Try this
clearvars
clc
data = readtable('RiskFactorAnalysis (1).csv');
userinput = input('Enter a Country: ','s');
Country = data(:,1);
CC = table2cell(Country)
CC1 = table2cell(data)
[R C] = size(data);
for i = 1:R
if strcmp((CC(i)),(userinput));
deaths(i) = cell2mat(CC1(i,4));
year(i) = cell2mat(CC1(i,3));
end
end
deaths(deaths == 0) = [];
year(year == 0) = [];
plot(year,deaths)
xlabel('year')
ylabel('deaths')
Related Question