plot textdata with NaN
이전 댓글 표시
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
Dyuman Joshi
2022년 5월 15일
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
2022년 5월 18일
KSSV
2022년 5월 18일
Use plot
John fredson
2022년 5월 18일
KSSV
2022년 5월 18일
Attach your data nd show us your full code.
답변 (5개)
John fredson
2022년 5월 18일
댓글 수: 1
Walter Roberson
2022년 5월 18일
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()?
Walter Roberson
2022년 5월 18일
0 개 추천
Give up on reading the file that way. Use readable() instead.
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1002155/owid-covid-data_2020-21.csv');
plot(T.Date,T.TotalCases)
댓글 수: 2
John fredson
2022년 5월 18일
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');
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')
John fredson
2022년 5월 19일
댓글 수: 6
Walter Roberson
2022년 5월 19일
The Location in the data is country names such as 'Kenya', not single character codes such as 'E'
John fredson
2022년 5월 19일
John fredson
2022년 5월 19일
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');
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
2022년 5월 19일
Voss
2022년 5월 19일
I plotted TotalCases vs DaysTracked, like you did.
How should Continent be taken into account?
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
John fredson
2022년 5월 20일
Walter Roberson
2022년 5월 20일
I suggest that you look at groupsummary()
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




