hi,i want to select year in Pr_anno using range in TR
anno=load('matlab_ANNO.mat')
anno = struct with fields:
PR_Anno: [2x1 timetable]
tr=load('matlab_TR.mat')
tr = struct with fields:
TR: [1x1 timerange]
PR_anno:
01/01/2024 -1.356250000000000e+03
01/01/2025 0
TR:
Starting at, including: 01-Sep-2024 00:00:00
Ending at, but excluding: 29-Nov-2024 00:00:00
The interval in TR is from 01-Sep-2024 00:00:00 to 29-Nov-2024 00:00:00 then i want to selet only 2024 (not 2025)
result:
01/01/2024 -1.356250000000000e+03

3 comentarios

Stephen23
Stephen23 el 30 de Nov. de 2024
Note that TR does not include any of the dates shown in the the timetable PR_anno. Why do you expect to get a date returned that is outside the TIMERANGE that you specified?
shamal
shamal el 30 de Nov. de 2024
Tr does not contain the Pr_Year range.. But I want to select the years in Pr_Year using the range of of Tr
shamal
shamal el 30 de Nov. de 2024
Yes, it's true, the PR_Year is not needed
How do I get the list of years in TR?

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 30 de Nov. de 2024
Editada: dpb el 30 de Nov. de 2024
"How do I get the list of years in TR?"
A timerange object is opaque; there are no user functions to query one; it can only directly be used as a subscript into a timetable. Therefore, one has to go at it indirectly...
load('matlab_TR.mat')
S=struct(TR) % create a struct of the object's internals
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
S = struct with fields:
first: 01/09/2024 last: 29/11/2024 type: 'openright' first_matchTimeZone: 0 last_matchTimeZone: 0 unitOfTime: '' hasEventFilters: 0 version: 1.4000
yrsTR=year(S.first)
yrsTR = 2024
So, we query and dsplay the piece of interest in the struct to determine what the field names inside the object are and then extract the piece of data of interest.
"But I want to select the years in Pr_Year using the range of of Tr"
Create a new timerange with that year range--
TRyr=timerange(S.first,'years')
TRyr =
timetable timerange subscript: Select timetable rows with times in the half-open interval: Starting at, including: 01-Jan-2024 00:00:00 Ending at, but excluding: 01-Jan-2025 00:00:00
Note that even knowing the name of the TR object isn't enough--
TRyr=timerange(TR.first,'years')
No public property 'first' for class ''timerange''.
fails. You're not allowed to ask the object itself and there are no associated methods to allow a direct query...that would seem to be a reasonable enhancement if TMW wouldn't want to go so far as to make the internals visible.

Más respuestas (0)

Categorías

Preguntada:

el 30 de Nov. de 2024

Editada:

dpb
el 30 de Nov. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by