How to search for previous values in a table?
Show older comments

In the above table, I have GPS time inputs as well as sensor readout values. Every value in column 1 named '$GPRMC' has a year timestamp in column 10. And after that command there are a bunch of sensor readouts until the next GPS timestamp updates.
I want to pick out all of the values in column 5 that have a 'T' (column 3, 'sensor'). I also want to add the nearest year timestamp from the '$GPRMC' reading nearest every 'T' sensor value and append that year to a new arrray for every sensor value until a new '$GPRMC' value comes in. This way there are an equal number of year values and sensor values so I can plot them against each other.
I've managed to pick out all 'T' sensor values by using:
trows = data.sensor=='T';
But I have no idea how to search for the nearest row with column 1 value of '$GPRMC' and append to an array the year timestamp in column 10 for every row entry with 'T' in it.
I guess basically I want to find out how to search above in the file until it finds a '$GPRMC' entry.
How are some different ways I can achieve this?
6 Comments
Les Beckham
on 31 Aug 2022
Edited: Les Beckham
on 31 Aug 2022
You will have better luck getting a solution if you attach a sample of your table saved in a .mat file.
One thought: why not loop through the rows until you find a $GPRMC record and then start saving 'T' records (along with the latest timestamp) until you find another $GPRMC record, instead of searching from the location of the 'T' records?
Jackson Greaves
on 31 Aug 2022
Jackson Greaves
on 31 Aug 2022
Jackson Greaves
on 31 Aug 2022
dpb
on 31 Aug 2022
You can shorten the table considerably to start with before anything else --
>> data1=data1(data1.sep=='$GPRMC'|data1.sensor=='T',:)
tD =
11×10 table
sep VarName2 sensor time X Y Z VarName8 VarName9 VarName10
______ _________ ______ __________ ____ _____ ____ ___________ ________ __________
$GPRMC 171647.00 V NaN NaN NaN NaN <undefined> NaN 3.0082e+05
$PAAG DATA T 1.7165e+05 -128 -416 7424 A NaN NaN
$PAAG DATA T 1.7165e+05 224 -352 8320 A 7 NaN
$PAAG DATA T 1.7165e+05 -512 -1920 9664 A 11 NaN
$PAAG DATA T 1.7165e+05 256 -1152 7936 A 31 NaN
$PAAG DATA T 1.7165e+05 3904 -192 6880 A 39 NaN
$PAAG DATA T 1.7165e+05 352 288 6720 A 22 NaN
$PAAG DATA T 1.7165e+05 -128 -2496 8768 A 17 NaN
$PAAG DATA T 1.7165e+05 1664 -2432 9600 A 5 NaN
$PAAG DATA T 1.7165e+05 1696 -1856 8256 A NaN NaN
$GPRMC 171648.00 V NaN NaN NaN NaN <undefined> NaN 3.0082e+05
>> tD.Properties.VariableNames(end)={'Date'};
>> tD.Date(1)==tD.Date(end)
ans =
logical
1
>> whos tD
The date value in both '$GPRMC' records shown is the same so what does it mean to add the "nearest" date? What values are of interest and what would it mean to plot them all at the same time?
I don't understand why this little table is taking 10MB of memory, either, that seems really, really peculiar -- unless one of the categorical variables was defined for the entire file and contains as many different element values as elements (or close)?
Oh, well, we can test that...the categories will be imbedded even if not used...
>> numel(categories(tD.VarName2))
ans =
80459
>> numel(categories(tD.VarName8))
ans =
3238
>> numel(categories(tD.sensor))
ans =
5285
>>
Indeed; those probably would be better off NOT being categorical -- are the floating point values for the sensor an actual sensor ID or data? We seem to have mixed metaphors in the data file -- the same variable seems to mean different things???
What to do next would depend on answer to the first Q?; we'll definitely have to have more than just one set of data to work with and a better definition of the end objective to do anything specifically useful.
Jackson Greaves
on 31 Aug 2022
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!