Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code but I got ERROR: %% Initialize variables. filename = 'TempTable.csv'; delimiter = ','; startRow = 3; %% Format for each line

This is the code but I got ERROR:

image text in transcribedimage text in transcribed

%% Initialize variables.

filename = 'TempTable.csv';

delimiter = ',';

startRow = 3;

%% Format for each line of text:

formatSpec = '%f%f%f%f%C%f%s%f%C%[^ ]';

%% Open the text file.

fileID = fopen(filename,'r');

%% Read columns of data according to the format.

dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', ' ');

%% Close the text file.

fclose(fileID);

%% Create output variable

temptable = table(dataArray{1:end-1}, 'VariableNames', {'Year','Month','Day','MaxTempC','MinTempC','MeanTempC'});

%% Clear temporary variables

clearvars filename delimiter startRow formatSpec fileID dataArray ans;

%% HERE YOU CAN ADD A FOR LOOP AND GET THE INFO FOR OTHER MONTHS

i=1; % January

idx_months = find(temptable.Month == i & temptable.Year == 1983);

meanmonthly = mean(temptable(idx_months,:).MeanTempC(~isnan(temptable(idx_months,:).MeanTempC)));

minmonthly = min(temptable(idx_months,:).MeanTempC(~isnan(temptable(idx_months,:).MeanTempC)));

maxmonthly = max(temptable(idx_months,:).MeanTempC(~isnan(temptable(idx_months,:).MeanTempC)));

>> Temp Error using table All table variables must have the same number of rows. Error in Temp (line 19) temptable table(dataArray{1: end-1}, 'VariableNames', {'Year', 'Month', 'Day', 'MaxTempC', 'MinTempC', 'MeanTempC'}); - A B D E F 2 Year Min Temp (-00) Mean Temp (-00C) Day 1 Max Temp ---C) 1 3 4 Month 1983 1983 1983 1983 1 29.8 13.9 21.85 5 6 1 1 2 3 4 22.4 14.8 18.6 7 1 5 1983 1983 8 1 6 22.5 22.3 12.6 15.5 OOO 17.55 18.9 9 1 7 1 8 10 11 1 9 12 1 1983 1983 1983 1983 1983 1983 1983 1983 10 11 12.9 13.3 14.1 13 1 14 1 23.3 21.7 20.1 21.3 20.5 22.3 25.1 9.6 18.1 17.5 17.1 15.45 15.25 15.75 18.05 12 13 14 1 15 16 10 9.2 1 1 11 17 18 1983 1983 1983 1 19 1 20 1983 1 21 1 22 1983 1983 1983 1983 1 1 20.7 24.9 27.3 22.1 18.6 19.9 22.2 23.9 9.5 8.3 13.5 13 13.5 13.8 10.4 23 24 1 1983 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 1983 1 25 26 27 28 29 12 15.1 16.6 20.4 17.55 16.05 16.85 16.3 17.95 17 16.85 16.1 15.2 15.95 16.25 15.75 19.6 1983 1983 1983 1 1 1 19.6 20 20.6 20.4 30 1983 1 14.4 14.1 12.2 9.8 11.5 14 13.6 31 1983 1 32 1983 18.5 1 1 33 17.9 1983 1983 34 2 1 >> Temp Error using table All table variables must have the same number of rows. Error in Temp (line 19) temptable table(dataArray{1: end-1}, 'VariableNames', {'Year', 'Month', 'Day', 'MaxTempC', 'MinTempC', 'MeanTempC'}); - A B D E F 2 Year Min Temp (-00) Mean Temp (-00C) Day 1 Max Temp ---C) 1 3 4 Month 1983 1983 1983 1983 1 29.8 13.9 21.85 5 6 1 1 2 3 4 22.4 14.8 18.6 7 1 5 1983 1983 8 1 6 22.5 22.3 12.6 15.5 OOO 17.55 18.9 9 1 7 1 8 10 11 1 9 12 1 1983 1983 1983 1983 1983 1983 1983 1983 10 11 12.9 13.3 14.1 13 1 14 1 23.3 21.7 20.1 21.3 20.5 22.3 25.1 9.6 18.1 17.5 17.1 15.45 15.25 15.75 18.05 12 13 14 1 15 16 10 9.2 1 1 11 17 18 1983 1983 1983 1 19 1 20 1983 1 21 1 22 1983 1983 1983 1983 1 1 20.7 24.9 27.3 22.1 18.6 19.9 22.2 23.9 9.5 8.3 13.5 13 13.5 13.8 10.4 23 24 1 1983 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 1983 1 25 26 27 28 29 12 15.1 16.6 20.4 17.55 16.05 16.85 16.3 17.95 17 16.85 16.1 15.2 15.95 16.25 15.75 19.6 1983 1983 1983 1 1 1 19.6 20 20.6 20.4 30 1983 1 14.4 14.1 12.2 9.8 11.5 14 13.6 31 1983 1 32 1983 18.5 1 1 33 17.9 1983 1983 34 2 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Debunked An Auditor Reviews The 2020 Election And The Lessons Learned

Authors: Joseph Fried

1st Edition

1645720756, 978-1645720751

More Books

Students also viewed these Accounting questions