MATLAB Answers

Index in position 1 is invalid. Array indices must be positive integers or logical values.

4 views (last 30 days)
Long Nguyen
Long Nguyen on 15 May 2021
Edited: Rena Berman on 29 Jun 2021 at 15:19
clear;
clc;
%importing table
vac = readtable('covid19vaccinesbycounty');
% importing cali population
pop = readtable('cali_county_pop.csv');
%import states vaccines
ship =readtable('cdc-vaccination-state-totals');
% Bookkeeping
% Dates
day_range = unique(vac.administered_date);
most_recent = max(day_range);
start_date = min(day_range);
% Week Define
week = -7;
weeks = day_range(length(day_range):week:1);
weeks(20,1) = start_date;
weeks = sort(weeks,'ascend')';
% Strings
pop.County = string(pop.County);
vac.county = string(vac.county);
most_recent = string(most_recent);
% Initialize arrays
county_ind = cell(1,length(pop.County));
perc_vac = NaN(length(day_range),length(pop.Population));
%Define
top= 15; % define the top 15
week=-7;
%% Bar Graph
for i = 1:length(pop.County) % length of the counties
% find the county indicies
county_ind{i}= find(vac.county == pop.County(i));
% get the max number of indicies of that specific counties
max_county(i) = max((vac.cumulative_fully_vaccinated(county_ind{i})));
% Find percentages of cumulative doses over population
percentage(i)= max_county(i)/pop.Population(i) *100;
end
[sortrows,descend]= sort(percentage ,'descend'); % sort in descend
vac_sort= sort(sortrows([1:top]),'descend'); % Sort data for top 15% Plot
sort_for_vac= (pop.County(descend)); % Find the top counties using descend
top15= sort_for_vac(1:top); % Sort from 1 to 15
figure('visible','off')
bar(vac_sort)
ytickformat('percentage')
xticklabels(top15)
xtickangle(45)
most_recent=max(vac.administered_date);
title(['Percent of Population Fully Vaccinated up to ' datestr(max(vac.administered_date)) ...
' Sorted by Top ' num2str(top) ' Most Vaccinated Counties'])
%% Heatmap
%1b
for a = 1:length(pop.County)
% Date Indicies for each county
vac_dates = find(ismember(day_range, vac.administered_date(county_ind{a})));
% Percent Vaccinations
perc_vac(vac_dates,a) = vac.cumulative_fully_vaccinated(county_ind{a}) ...
/ pop.Population(a) * 100;
% Percent Vaccinations week by week
vac_over_time = perc_vac(length(day_range):week:1 , :);
vac_over_time(20,:) = sortrows(perc_vac(1,:),'ascend')';
overtime= sortrows(overtime,'ascend')';
end
figure('visible','on')
heatmap(weeks, pop.County, overtime, 'Colormap', turbo)
caxis([0 100])
  3 Comments

Sign in to comment.

Accepted Answer

DGM
DGM on 16 May 2021
You are using sortrows as both a variable name and as a function. Rename the variable so that it doesn't overload the function you need to use.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by