Creating Graphs from Data in a .csv Files

88 views (last 30 days)
Tangeni Ferdinand
Tangeni Ferdinand on 31 May 2022
Answered: Voss on 31 May 2022
The file Windhoek_temp_01_2022.csv contains temperature information for the month of January 2022. For each day of the month, the average temperature [C], minimum temperature [C], maximum temperature [C] are tabulated.
After loading the data, create a graph visualizing the temperatures (all in the same graph). Choose visually pleasing intervals to be shown for the abscissa and ordinate. Follow all guidelines regarding the creation of "proper" graphs. Don't forget to provide a meaningful title for your graph.
Note: You will receive at most 5 points if you manually copy and paste the data into the Jupyter Notebook.
Reference: Data was retrieved from http://www.sasscalweathernet.org/
This are the codes i have so far but they don't bring up any graph
my_csv=readtable('Windhoek_temp_01_2022.csv'); %Reading the data
disp(my_csv); % Displaying the data just to confirm
% Creating a path for the headers
Temperature = my_csv(:,1);
Average_Temperature =my_csv(:,2);
Minimum_Temperature =my_csv(:,3);
Maximum_Temperature =my_csv(:,4);
plot(Temperature,Average_Temperature);
plot(Temperature,Minimum_Temperature);
plot(Temperature,Maximum_Temperature);
shg()

Answers (1)

Voss
Voss on 31 May 2022
Subscripting a table with ( ) gives you another table. To get the data out of a table, subscript with { }
my_csv=readtable('Windhoek_temp_01_2022.csv'); %Reading the data
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.
disp(my_csv); % Displaying the data just to confirm
x_Day x2022AvgTemp_C_ x2022MinTemp_C_ x2022MaxTemp_C_ _____ _______________ _______________ _______________ 1 24.7 15.1 33.1 2 26.6 20.4 33.1 3 26.1 18.9 32.6 4 25.8 18.3 32.7 5 25.1 16 32.5 6 26.6 19.1 33.6 7 27 19.4 34.4 8 24.3 20.3 30.9 9 23.8 20.5 28.5 10 23.6 15.6 30.5 11 23.2 14.8 30.2 12 25.2 16.9 32.8 13 25.9 20.1 31.9 14 22.9 19 28.2 15 20.8 16.6 27 16 18.8 15.2 25.1 17 21.8 17.2 28.9 18 21.4 16.7 28.4 19 20 16.1 27.2 20 20.3 16.1 25.8 21 21 16.7 27.3 22 21.7 17.1 27.1 23 22.3 17.9 26.2 24 22.3 16.2 28 25 23.5 17.7 28.4 26 24.8 19.5 30.4 27 26.1 19.5 31 28 26 22.3 31 29 24.4 19.7 28.9 30 22 18 28 31 20.4 17.4 26.3
% Creating a path for the headers
Temperature = my_csv{:,1};
Average_Temperature =my_csv{:,2};
Minimum_Temperature =my_csv{:,3};
Maximum_Temperature =my_csv{:,4};
plot(Temperature,Average_Temperature);
plot(Temperature,Minimum_Temperature);
plot(Temperature,Maximum_Temperature);
shg()

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!