[789] | 1 | % read_lvm: read data from the output files of labview (file extension .lvm) |
---|
| 2 | function Data=read_lvm(filename) |
---|
| 3 | Data.ListGlobalAttribute={'FileName','Experiment','DateTime'}; |
---|
| 4 | [Path,Data.FileName] = fileparts(filename);% record the file name |
---|
| 5 | [tild,Data.Experiment]=fileparts(Path);% record the experient name |
---|
| 6 | |
---|
| 7 | %% read the full text of the file as a char string txt |
---|
| 8 | txt = fileread(filename); |
---|
| 9 | |
---|
| 10 | %% get time string (date and time of the experiment) |
---|
| 11 | |
---|
| 12 | Date_pos=regexp(txt,'Date\s','once');%find the char string 'Date' followed by a blank |
---|
| 13 | txt(1:Date_pos+length('Date'))=[]; %remove the header until 'Date'; |
---|
| 14 | DateString=txt(1:regexp(txt,'\n','once')-1);% read char until the next line break |
---|
| 15 | r1=regexp(DateString,'(?<DateDat>\S+)','names');% keep the non blank string |
---|
| 16 | Time_pos=regexp(txt,'Time\s','once');%find the char string 'Time' followed by a blank |
---|
| 17 | txt(1:Time_pos+length('Time'))=[]; %remove the header until 'Time'; |
---|
| 18 | TimeString=txt(1:regexp(txt,'\n','once')-1);% read char until the next line break |
---|
| 19 | r2=regexp(TimeString,'(?<TimeDat>\S+)','names');% keep the non blank string |
---|
| 20 | TimeString=regexprep(r2.TimeDat,',','.');% replace ',' by '.' |
---|
| 21 | Dot_pos=regexp(TimeString,'\.'); |
---|
| 22 | TimeString=TimeString(1:Dot_pos+2); % round to 1/100 s |
---|
| 23 | Data.DateTime=[r1.DateDat ' ' TimeString];%insert date to the time string (separated by a blank) |
---|
| 24 | |
---|
| 25 | %% remove header text |
---|
| 26 | Header_pos=regexp(txt,'***End_of_Header***','once');%find the first '***End_of_Header***' |
---|
| 27 | txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header |
---|
| 28 | Header_pos=regexp(txt,'***End_of_Header***','once');%find the second '***End_of_Header***' |
---|
| 29 | txt(1:Header_pos+length('***End_of_Header***')+1)=[];%remove header |
---|
| 30 | title_pos=regexp(txt,'\S','once');% find the next non blank char |
---|
| 31 | txt(1:title_pos-1)=[];% remove the blank char at the beginning |
---|
| 32 | |
---|
| 33 | %% get the list of channel names |
---|
| 34 | Break_pos=regexp(txt,'\n','once');%find the line break |
---|
| 35 | VarNameCell=textscan(txt(1:Break_pos-1),'%s');% read list of variable names (until next line break) |
---|
| 36 | Data.ListVarName=VarNameCell{1}; |
---|
| 37 | Data.ListVarName(end)=[]; %remove last name (Comment) |
---|
| 38 | Data.ListVarName{1}='Time'; %replace first name ('X_Value') by 'Time') |
---|
| 39 | NbChannel=numel(Data.ListVarName); |
---|
| 40 | for ivar=1:NbChannel |
---|
| 41 | Data.VarDimName{ivar}='nb_sample'; |
---|
| 42 | end |
---|
| 43 | |
---|
| 44 | %% get the data |
---|
| 45 | txt(1:Break_pos-1)=[];%removes line of channel names |
---|
| 46 | txt=regexprep(txt,',','.');%replace comma by dots (French to English notation) |
---|
| 47 | txt=textscan(txt,'%s');% transform txt in a cell of strings |
---|
| 48 | txt=reshape(txt{1},NbChannel,[]); |
---|
| 49 | txt=cellfun(@str2double,txt);% transform char to a matrix of numbers |
---|
| 50 | txt=txt'; %transpose matrix |
---|
| 51 | for ivar=1:NbChannel |
---|
| 52 | Data.(Data.ListVarName{ivar})=txt(:,ivar); |
---|
| 53 | end |
---|
| 54 | |
---|
| 55 | %% calculate position in case of a non-zero motor signal |
---|
| 56 | % To plot profiles(e;g.for C5): plot(Data.Position(Data.Speed<0),Data.C5(Data.Speed<0)) |
---|
| 57 | SpeedDown=-1; %motot speed 1 cm/s |
---|
| 58 | SpeedUp=1; %motot speed 1 cm/s |
---|
| 59 | if isfield(Data,'Motor_profile')% Motor_profile signal =0 (no motion), -5 (down), +5(up) |
---|
| 60 | Data.ListVarName=[Data.ListVarName' {'Position','Speed'}]; |
---|
| 61 | Data.VarDimName=[Data.VarDimName {'nb_sample','nb_sample'}]; |
---|
| 62 | Speed=zeros(size(Data.Motor_profile)); |
---|
| 63 | if ~isempty(find(Data.Motor_profile>2.5|Data.Motor_profile<-2.5)) |
---|
| 64 | Speed(Data.Motor_profile>2.5)=SpeedUp;% threshold at 2.5 to avoid noise effects |
---|
| 65 | Speed(Data.Motor_profile<-2.5)=SpeedDown; |
---|
| 66 | Data.Speed=Speed; |
---|
| 67 | Speed(end)=[]; |
---|
| 68 | Data.Position=[0; cumsum(Speed.*diff(Data.Time))]; |
---|
| 69 | end |
---|
| 70 | end |
---|
| 71 | |
---|