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
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 Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!