seek
This function requires Streaming Data Framework for MATLAB® Production Server™.
Description
offset = seek(
sets the read position of event stream stream
,position
)stream
to
position
. You can specify a numeric absolute position or a relative
position, such as "Beginning"
or "End"
for the start
or end of the stream, respectively. seek
returns the position from which
the next read operation occurs.
Examples
Seek to Beginning of Event Stream
Create a TestStream
object to read from and write events to an
event stream hosted by MATLAB.
ts = testStream;
Write sample timetable data to the event stream.
load indoors
writetimetable(ts,indoors)
Read data from the stream. The stream contains 60 events, but the stream by default
has a window size of 100. Therefore, readtimetable
reads the entire
stream in a single read. The read position is one position past the end of the
stream.
tt = readtimetable(ts);
Move the read position back to the first event.
seek(ts,"Beginning");
Seek to Position Relative to End of Event Stream
Create an InMemoryStream
object to read from and write events to
an event stream hosted by MATLAB. Configure the object to read 10 events at a time.
numRows = 10; is = inMemoryStream(Rows=numRows);
Write timetable data to the event stream.
load indoors
writetimetable(is,indoors)
Move the read position 10 rows back from the end position.
seek(is,-numRows + 1,"End");
Read the last 10 events from the stream.
tt = readtimetable(is)
tt = 10×2 timetable Time Humidity AirQuality ___________________ ________ __________ 2015-11-17 13:00:19 37 79 2015-11-17 14:13:31 37 80 2015-11-17 15:26:43 37 79 2015-11-17 16:39:55 37 77 2015-11-17 17:53:07 37 79 2015-11-17 19:06:19 37 79 2015-11-17 20:19:31 37 80 2015-11-17 21:32:43 37 81 2015-11-17 22:45:55 37 79 2015-11-17 23:59:07 35 79
Input Arguments
stream
— Object connected to event stream
KafkaStream
object | InMemoryStream
object | TestStream
object
Object connected to an event stream, specified as a KafkaStream
, InMemoryStream
, or TestStream
object.
position
— Position in event stream
integer | datetime scalar | "Beginning"
| "End"
| "Current"
Position in an event stream at which the next read starts, specified as an absolute or relative position.
Absolute Position
Specify one of these values:
A positive integer indicating the number of events from the start of the event stream that the read position moves to. You cannot specify an integer greater than the length of the stream. For example,
seek(stream,5)
moves the read position to the fifth event in the stream.A datetime scalar indicating the event timestamp that the read position moves to. If the stream contains no event corresponding to the specified date or time, the stream position moves to the first time after the specified time. For example,
seek(stream,datetime(2022,5,13,16,34,26))
moves the read position to the event that has a timestamp of13-May-2022 16:34:26
.
Relative Position
Specify one of these values:
"Beginning"
— First event available in stream. For example:seek(stream,"Beginning")
."End"
— Just past the last event in the stream. For example:seek(stream,"End")
."Current"
— Just past the current event in the stream. For example:seek(stream,"End")
.If you specify
origin
, a positive or negative integer indicating the number of events relative to that origin. For example,seek(stream,-10,"End")
moves the read position 10 positions from the last event in the stream.position
must not exceed either end of the stream relative toorigin
. Iforigin
is"End"
, thenposition
must be negative. Iforigin
is"Beginning"
, thenposition
must be positive.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| string
| datetime
origin
— Origin that read position is relative to
"Beginning"
| "End"
| "Current"
Origin that the read position specified by position
is relative
to, specified as one of these values:
"Beginning"
— Read position is relative to the first event available in stream."End"
— Read position is relative to the last event in the stream."Current"
— Read position is relative to the current event in the stream.
Data Types: string
| char
Version History
Introduced in R2022b
See Also
kafkaStream
| inMemoryStream
| testStream
| readtimetable
| writetimetable
| preview
| seek
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)