How to collect data from text file and use it in the (mapping toolbox)
1 view (last 30 days)
Show older comments
Im trying to take data from text files and put them into a GUI of the USA map for a project. Its supposed to show various data involving prisons across states. How do I take the text file data and impliment it into my code below?
prisons = readtable('Prison_data.txt');
states = readtable('States_pops.xlsx');
state_names = readtable('Stateids.txt');
% this code is supposed to collect data^^^^^^^^^
figure;
ax1 = usamap('all');
ststaes = shaperead('usastatelo','UseGeoCoords', true);
geoshow(ax1, states, 'Facecolor',[0.5 0.5 0.5]);
ax2 = subplot(1,2,2);
plot(incarcerationData)
title('National incarceration data');
xlabel('year');
ylabel('incarceration rate');
textbox = uicontrol('Style', 'text', 'string', 'year:', 'Position', [20 20 50 20]);
dropdown = uicontrol('style', 'popupmenu', 'string',{'incarceration Rate', 'Prison population'},'position', [ 20 40 100 20]);
plotButton = uicontrol("Style","pushbutton", 'String', 'Plot', 'Position', [20 60 50 20], 'Callback', @plotData);
function plotdata(~, ~)
year = str2double(get(textbox, 'string'));
metric = get(dropdown, 'value');
if metric == 1
for i = 1:length(states)
geoshow(ax1, states(i), 'FaceColor',[incarcerationData(year, i) 0 0]);
end
else
for i = 1:length(states)
geoshow(ax1, states(i), 'FaceColor', [prisonPopulationData(year, i) 0 0]);
end
end
if metric == 1
plot(ax2, incarcerationData(:, year));
title(ax2, 'National incarceration over Time');
xlabel(ax2, 'year');
ylabel(ax2, 'Incarceration Rate');
else
plot(ax2, prisonPopulationData(:, year));
title(ax2, 'National Prison Population over Time');
xlabel(ax2, 'year');
ylabel(ax2, 'Prison population');
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!