Need Help plotting things from a table

조회 수: 1 (최근 30일)
Kelsey Pettrone
Kelsey Pettrone 2020년 10월 21일
댓글: Rik 2020년 10월 23일
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);

채택된 답변

VBBV
VBBV 2020년 10월 22일
편집: VBBV 2020년 10월 22일
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')
  댓글 수: 3
VBBV
VBBV 2020년 10월 23일
bpcombined = [obesity; Drug; Alcohol; smoking];
yearall = [year.' year.' year.' year.'];
bar(yearall,bpcombined.')
xlabel('year')
legend('Obesity','Drug','Alcohol','Smoking')
Rik
Rik 2020년 10월 23일
I suspect the variable names are tripping the spam filter. I had to remove both of the prior comments from the spam filter.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by