Read only numerical value or seperate data using deliminater
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vijay Vythilingum
am 20 Jan. 2020
Kommentiert: Vijay Vythilingum
am 21 Jan. 2020
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}
Akzeptierte Antwort
Allen
am 20 Jan. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!