Read only numerical value or seperate data using deliminater

1 次查看(过去 30 天)
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}

采纳的回答

Allen
Allen 2020-1-20
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by