Converting entries from array to double from an entire column in a matrix for plotting

3 views (last 30 days)
I have this file which I want to analyse for temeprature fluctuations:
D=readtable('tempDataTrollhFlygpl.xlsx', 'NumHeaderLines', 10) % anger 10 rubrikrader slik at jeg kan ekstrahere kolonne entries mer effektivt
val = str2double(D{:,3});
val2 = str2double(D{:,4});
plot(D,'Var3','Var4')
So I triwed to convert all entries in table 3 and 4 to doubles, so that they can be plotted by calling their sets as "val" and "val2", but those names were not recognized by plot, so I used what MATLAB suggested, namely Var3 and Var4, for the 3d and 4th respective columns.
How can I can plot this, and also, how can I find the most recurring number in the column 4, that is the most recurring temperature over that period defined in column 3?
I was also trying to view the distribution of the temperatures as a histogram, so I did the following:
histogram(val2,val)
But also this didn't work.
Any ideas appreaciated!
Thanks

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 15 Feb 2024
Change the options for reading the data via detectImportOptions and use column numbers to plot -
opts = detectImportOptions('tempDataTrollhFlygpl.xlsx')
opts =
SpreadsheetImportOptions with properties: Sheet Properties: Sheet: '' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' Variable Import Properties: Set types by name using setvartype VariableNames: {'Tidsperiod_fr_o_m_', 'Tidsperiod_t_o_m_', 'H_jd_meter_verHavet_' ... and 4 more} VariableTypes: {'datetime', 'datetime', 'datetime' ... and 4 more} SelectedVariableNames: {'Tidsperiod_fr_o_m_', 'Tidsperiod_t_o_m_', 'H_jd_meter_verHavet_' ... and 4 more} VariableOptions: [1-by-7 matlab.io.VariableImportOptions] Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Range Properties: DataRange: 'A8' (Start Cell) VariableNamesRange: 'A7' RowNamesRange: '' VariableUnitsRange: '' VariableDescriptionsRange: '' To display a preview of the table, use preview
%Change the data type of column 4
opts.VariableTypes{4} = 'double';
%Assign the 10th row for variable names
opts.VariableNamesRange = '10:10';
%Assign the cell from which to start reading the data
opts.DataRange = 'A11';
D = readtable('tempDataTrollhFlygpl.xlsx', opts) % anger 10 rubrikrader slik at jeg kan ekstrahere kolonne entries mer effektivt
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.
D = 6786x7 table
Fr_nDatumTid_UTC_ TillDatumTid_UTC_ RepresentativtDygn Lufttemperatur Kvalitet Var6 Tidsutsnitt_ ____________________ _________________ __________________ ______________ ________ __________ _____________________________________________________________________________________________________________________________________________ 01-Jan-1961 00:00:01 02-Jan-1961 01-Jan-1961 0.1 {'Y'} {0x0 char} {'Kvalitetskontrollerade historiska data (utom de senaste 3 mån)' } 02-Jan-1961 00:00:01 03-Jan-1961 02-Jan-1961 0.7 {'Y'} {0x0 char} {'Tidsperiod (fr.o.m.) = 1961-01-01 00:00:00 (UTC)' } 03-Jan-1961 00:00:01 04-Jan-1961 03-Jan-1961 1 {'Y'} {0x0 char} {'Tidsperiod (t.o.m.) = 1979-08-01 23:59:59 (UTC)' } 04-Jan-1961 00:00:01 05-Jan-1961 04-Jan-1961 0.4 {'Y'} {0x0 char} {'Medelvärdet är beräknat för = 24 timmar' } 05-Jan-1961 00:00:01 06-Jan-1961 05-Jan-1961 0 {'Y'} {0x0 char} {0x0 char } 06-Jan-1961 00:00:01 07-Jan-1961 06-Jan-1961 0.2 {'Y'} {0x0 char} {'Kvalitetskoderna:' } 07-Jan-1961 00:00:01 08-Jan-1961 07-Jan-1961 0 {'Y'} {0x0 char} {'Grön (G) = Kontrollerade och godkända värden.' } 08-Jan-1961 00:00:01 09-Jan-1961 08-Jan-1961 -1.1 {'Y'} {0x0 char} {'Gul (Y) = Misstänkta eller aggregerade värden. Grovt kontrollerade arkivdata och okontrollerade realtidsdata (senaste 2 tim).' } 09-Jan-1961 00:00:01 10-Jan-1961 09-Jan-1961 -1.1 {'Y'} {0x0 char} {0x0 char } 10-Jan-1961 00:00:01 11-Jan-1961 10-Jan-1961 -0.8 {'Y'} {0x0 char} {'Orsaker till saknade data:' } 11-Jan-1961 00:00:01 12-Jan-1961 11-Jan-1961 -5.4 {'Y'} {0x0 char} {'stationen eller givaren har varit ur funktion.' } 12-Jan-1961 00:00:01 13-Jan-1961 12-Jan-1961 -6.8 {'Y'} {0x0 char} {'kvalitetskontrollerna har felmarkerat data (röd kvalitetskod). Efterföljande manuell granskning godkänner, rättar eller underkänner data.'} 13-Jan-1961 00:00:01 14-Jan-1961 13-Jan-1961 2.6 {'Y'} {0x0 char} {0x0 char } 14-Jan-1961 00:00:01 15-Jan-1961 14-Jan-1961 0.3 {'Y'} {0x0 char} {0x0 char } 15-Jan-1961 00:00:01 16-Jan-1961 15-Jan-1961 2.5 {'Y'} {0x0 char} {0x0 char } 16-Jan-1961 00:00:01 17-Jan-1961 16-Jan-1961 -2.7 {'Y'} {0x0 char} {0x0 char }
plot(D, 3, 4)

More Answers (1)

Mathieu NOE
Mathieu NOE on 15 Feb 2024
hello
here you are
D=readtable('tempDataTrollhFlygpl.xlsx', 'NumHeaderLines', 10) % anger 10 rubrikrader slik at jeg kan ekstrahere kolonne entries mer effektivt
D = 6786x7 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 ____________________ ___________ ___________ ________ _____ ____ _____________________________________________________________________________________________________________________________________________ 01-Jan-1961 00:00:01 02-Jan-1961 01-Jan-1961 {'0.1' } {'Y'} NaN {'Kvalitetskontrollerade historiska data (utom de senaste 3 mån)' } 02-Jan-1961 00:00:01 03-Jan-1961 02-Jan-1961 {'0.7' } {'Y'} NaN {'Tidsperiod (fr.o.m.) = 1961-01-01 00:00:00 (UTC)' } 03-Jan-1961 00:00:01 04-Jan-1961 03-Jan-1961 {'1.0' } {'Y'} NaN {'Tidsperiod (t.o.m.) = 1979-08-01 23:59:59 (UTC)' } 04-Jan-1961 00:00:01 05-Jan-1961 04-Jan-1961 {'0.4' } {'Y'} NaN {'Medelvärdet är beräknat för = 24 timmar' } 05-Jan-1961 00:00:01 06-Jan-1961 05-Jan-1961 {'0.0' } {'Y'} NaN {0x0 char } 06-Jan-1961 00:00:01 07-Jan-1961 06-Jan-1961 {'0.2' } {'Y'} NaN {'Kvalitetskoderna:' } 07-Jan-1961 00:00:01 08-Jan-1961 07-Jan-1961 {'0.0' } {'Y'} NaN {'Grön (G) = Kontrollerade och godkända värden.' } 08-Jan-1961 00:00:01 09-Jan-1961 08-Jan-1961 {'-1.1'} {'Y'} NaN {'Gul (Y) = Misstänkta eller aggregerade värden. Grovt kontrollerade arkivdata och okontrollerade realtidsdata (senaste 2 tim).' } 09-Jan-1961 00:00:01 10-Jan-1961 09-Jan-1961 {'-1.1'} {'Y'} NaN {0x0 char } 10-Jan-1961 00:00:01 11-Jan-1961 10-Jan-1961 {'-0.8'} {'Y'} NaN {'Orsaker till saknade data:' } 11-Jan-1961 00:00:01 12-Jan-1961 11-Jan-1961 {'-5.4'} {'Y'} NaN {'stationen eller givaren har varit ur funktion.' } 12-Jan-1961 00:00:01 13-Jan-1961 12-Jan-1961 {'-6.8'} {'Y'} NaN {'kvalitetskontrollerna har felmarkerat data (röd kvalitetskod). Efterföljande manuell granskning godkänner, rättar eller underkänner data.'} 13-Jan-1961 00:00:01 14-Jan-1961 13-Jan-1961 {'2.6' } {'Y'} NaN {0x0 char } 14-Jan-1961 00:00:01 15-Jan-1961 14-Jan-1961 {'0.3' } {'Y'} NaN {0x0 char } 15-Jan-1961 00:00:01 16-Jan-1961 15-Jan-1961 {'2.5' } {'Y'} NaN {0x0 char } 16-Jan-1961 00:00:01 17-Jan-1961 16-Jan-1961 {'-2.7'} {'Y'} NaN {0x0 char }
time = D{:,3};
temp = str2double(D{:,4});
figure(1)
plot(time,temp)
figure(2)
histogram(temp)
  3 Comments
Star Strider
Star Strider on 15 Feb 2024
The ‘y’ values are not degrees. They are the number of times a particular degree value (x-axis) appears in the ‘Var4’ data.

Sign in to comment.

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!