May I know
How to assign a zero to a NaN data in a infinitely long text data
how to plot a infitely long text data which contain NaN?

5 Kommentare

What does 'Infinitely long text data' mean? Is the data bounded? Periodic?
You can change the NaN values to zero by
data(isnan(data)=0;
John fredson
John fredson am 18 Mai 2022
how to plot textdata on subplot?
KSSV
KSSV am 18 Mai 2022
Use plot
John fredson
John fredson am 18 Mai 2022
The data plotted is textdata and this occured, how to solve it?
KSSV
KSSV am 18 Mai 2022
Attach your data nd show us your full code.

Melden Sie sich an, um zu kommentieren.

Antworten (5)

John fredson
John fredson am 18 Mai 2022

0 Stimmen

X = importdata('owid-covid-data_2020-21.csv');
d_tracked = X.textdata(1:32,5);
t_case = X.textdata(1:32,6);
t_death = X.textdata(1:32,7);
t_case = string(total_case);
t_death = string(total_death);
D_tracked = string(day_tracked);
figure
subplot(1,2,1)
plot(t_case,d_tracked,'b-')
set(gca, 'YScale', 'log')
xlabel('accumulated cases')
ylabel('tracked,')
title('ccumulated cases vstracked')
subplot(1,2,2)
plot(t_death,d_tracked,'r-')
set(gca, 'YScale', 'log')
xlabel('accumulated deaths')
ylabel('tracked,')
title('accumulated death vs tracked')

1 Kommentar

plot(t_death,d_tracked,'r-')
both of those variables are string arrays. What would it mean to plot one against the other?
Perhaps you want to categorical() and scatter()?

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 18 Mai 2022

0 Stimmen

Give up on reading the file that way. Use readable() instead.
KSSV
KSSV am 18 Mai 2022

0 Stimmen

Read about readtable.
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1002155/owid-covid-data_2020-21.csv');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
plot(T.Date,T.TotalCases)

2 Kommentare

John fredson
John fredson am 18 Mai 2022
bro how you generate this? can teach me?
Read csv fille into Table using readtable. Go through this function. It works well. As an example, check how I am plotting India data alone from the table.
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1002155/owid-covid-data_2020-21.csv');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
idx = strcmp(T.Location,'India') ; % get indices of India
T1 = T(idx,:) ; % data for India alone
plot(T1.Date,T1.TotalCases,'r')
hold on
plot(T1.Date,T1.TotalDeaths,'b')
legend('Total cases','TotalDeath')
title('India')

Melden Sie sich an, um zu kommentieren.

John fredson
John fredson am 19 Mai 2022

0 Stimmen

T = readtable('owid-covid-data_2020-21.csv');
id_a = strcmp(X.Location,'a');
T1 = T(id_a,:) ;
id_A = strcmp(X.Location,'A');
T2 = T(id_A,:) ;
id_E = strcmp(X.Location,'E');
T3 = T(id_E,:) ;
id_S = strcmp(X.Location,'S');
T4 = T(id_S,:) ;
id_N = strcmp(X.Location,'N');
T5 = T(id_N,:) ;
id_O = strcmp(X.Location,'O');
T6 = T(id_O,:) ;
plot(X1.DaysTracked, X1.TotalCases,'b-', X2.DaysTracked, X2.TotalCases,'r-', X3.DaysTracked, X3.TotalCases,'k-', X4.DaysTracked, X4.TotalCases,'g-', X5.DaysTracked, X5.TotalCases,'p-', X6.DaysTracked, X6.TotalCases,'m-')
Why this code cannot run

6 Kommentare

Walter Roberson
Walter Roberson am 19 Mai 2022
The Location in the data is country names such as 'Kenya', not single character codes such as 'E'
John fredson
John fredson am 19 Mai 2022
I know the variable I coded is in full form but due to policy I can't show the full code so I cut it a bit
John fredson
John fredson am 19 Mai 2022
can you guys suggest what's wrong with this code?
Your table is T (T1, T2, ...) but sometimes you refer to it as X (X1, X2, ...), but X (X1, X2, ...) is not defined.
T = readtable('owid-covid-data_2020-21.csv');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
id_a = strcmp(T.Location,'Afghanistan');
T1 = T(id_a,:) ;
id_A = strcmp(T.Location,'Angola');
T2 = T(id_A,:) ;
plot(T1.DaysTracked, T1.TotalCases,'b-', T2.DaysTracked, T2.TotalCases,'r-')
John fredson
John fredson am 19 Mai 2022
but data must take the continent
Voss
Voss am 19 Mai 2022
I plotted TotalCases vs DaysTracked, like you did.
How should Continent be taken into account?

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 19 Mai 2022

0 Stimmen

T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1002155/owid-covid-data_2020-21.csv', 'VariableNamingRule', 'preserve');
G = findgroups(T.Continent);
hold on
splitapply(@(dt, tc, cont) plot(dt, tc, 'DisplayName', cont(1)), T.('Days Tracked'), T.('Total Cases'), string(T.Continent), G);
hold off
xlim auto; ylim auto
legend show
Why do there appear to be a lot more than 6 lines? Well, you have a number of different locations within each continent, and each one of those has a full range of days tracked, so when you put the data for all those locations together as one line, the days information keeps resetting.
If this is not the output you were looking for, then you should be more specific. For example were you wanting to total over all locations within each continent ?

2 Kommentare

John fredson
John fredson am 20 Mai 2022
how to sum up variable variables in one column of the table read by readtable
Walter Roberson
Walter Roberson am 20 Mai 2022
I suggest that you look at groupsummary()

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 15 Mai 2022

Kommentiert:

am 20 Mai 2022

Community Treasure Hunt

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

Start Hunting!

Translated by