Read only numerical value or seperate data using deliminater

1 visualizzazione (ultimi 30 giorni)
I have a data file with data, shown below. I would only like to read the time and Resistance value (around 606 in data), and put his into a matrix. Is there any way I can separate the data by a ' ' or '|' deliminater or just read the time and resistance value
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.21}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|607.40}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|605.62}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.21}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.21}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|607.40}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|605.62}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|607.40}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}
2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}

Risposta accettata

Allen
Allen il 20 Gen 2020
Assuming that you ultimately want to extract the date/time and resistance values, and assign them to separate variables, the following should work. I am also making the assumption that your data is a cell-array of strings or character vectors.
C = {'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.21}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|607.40}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|605.62}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.21}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.21}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|607.40}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|605.62}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|607.40}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'
'2020-01-20 12:56:42: {TIMEPLOT|DATA|Resistance|T|606.81}'};
% Extracts the date and time portion of the character vectors and convert them to a datetime class.
Time = cellfun(@datetime,regexp(C,'(.*)(?=:)','match'));
% Time = regexp(C,'(.*)(?=:)','match'); % This will leave them as a cell-array of character vectors.
% Extracts the resistance values and convert them to a double class.
R = cellfun(@str2double,regexp(C,'(?,=.*|)(\d+\.\d+)','match'));
% R = regexp(C,'(?,=.*|)(\d+\.\d+)','match'); % This will leave them as a cell-array of character vectors

Più risposte (0)

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by