Question regarding error occured

1 view (last 30 days)
John fredson
John fredson on 19 May 2022
Commented: Jan on 19 May 2022
X = importdata('owid-covid-data_2020-21.csv');
john_data = X.textdata;
X_s = string(john_data);
data =;
d = X_s(:,4);
A = zeros(4,396);
for i = 1:length(X_s)
for k = 1:length(data)
for j = 1:length(d)
if j < 396
n = n+1;
C = X_s(k);
s_d = d(n(1));
e_d = d(n);
N_r = sum((e_d:s_d));
A = [C, s_d,e_date,N_r]';
fprintf('%12s %13s %13s %13s\n','Country name', 'Record start date','Record end date','Number of records')
fprintf('%15f %15f %15f %15f\n',A)
The question asked us to pick data from the file which is country that has day tracked less than 396 and print to a table contains Country Name, Record start date, Record end date and number of records in the command window, how am I to find those data and print it to the screen? is my loop have any problem and it won't run
  1 Comment
Jan on 19 May 2022
You mention, that an error occurs. Please post a copy of the complete message.
n is a scalar. Then:
s_d = d(n(1));
e_d = d(n);
replies the same value. In consequence
N_r = sum((e_d:s_d));
is the same as:
N_r = e_d; % or s_d

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!