Plot multiple conditions in same figure using for and if loop.
Mostra commenti meno recenti
Hi,
I would like to plot the total cases against days tracked for the 6 countries mentioned in key_locations. The code currently only works and plots for a single country because strcmp can only compare two strings, but I would like to compare 6 strings (one for each country) to the cell data and plot the graphs all on the same figure. This is what I've written so far and a sample of the excel sheet is attached.
Thank you
covid_data = readtable('owid-covid-data.xlsx');
key_locations = ["Australia" "China" "India" "Indonesia" "Malaysia" "Vietnam"];
Location = covid_data(:,3);
CC = table2cell(Location); %converts table to cell array
CC1 = table2cell(covid_data);
[R C] = size(covid_data);
for i = 1:R
if strcmp(CC(i),key_locations(1));
totalcases(i)=cell2mat(CC1(i,6));
daystracked(i) = cell2mat(CC1(i,5));
newcases(i) = cell2mat(CC1(i,7));
end
end
totalcases(totalcases == NaN) = []; %NaN is currently undefined
daystracked(daystracked == NaN) = [];
newcases(newcases == NaN) = [];
figure(1)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

