Hello , i am a lil bit confused. I did an experiment and now i am trying to read the time in seconds. MY experiment was pretty long . I needed to know the time spent by subjects in particular instances.
For example: From the start of a particular instance and the end , i am having this :
start: 3.026100e+01
.
.
.
Stop: 5.975300e+01
I spent at least 15 -20 min here. When substracting , it does not make sense. I have attached an excel file
how can i calculate the total time in seconds from the first row (1 )- to the (153) for example
function varargout = franck_guide(varargin)
% FRANCK_GUIDE MATLAB code for franck_guide.fig
% FRANCK_GUIDE, by itself, creates a new FRANCK_GUIDE or raises the existing
% singleton*.
%
% H = FRANCK_GUIDE returns the handle to a new FRANCK_GUIDE or the handle to
% the existing singleton*.
%
% FRANCK_GUIDE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FRANCK_GUIDE.M with the given input arguments.
%
% FRANCK_GUIDE('Property','Value',...) creates a new FRANCK_GUIDE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before franck_guide_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to franck_guide_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help franck_guide
% Last Modified by GUIDE v2.5 22-Feb-2022 13:54:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @franck_guide_OpeningFcn, ...
'gui_OutputFcn', @franck_guide_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before franck_guide is made visible.
function franck_guide_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to franck_guide (see VARARGIN)
% Choose default command line output for franck_guide
handles.output = hObject;
% Plot patch on uiaxes
%hold on
% Read experiment data from a CSV file
[~,~,data] = xlsread('excel_data_final.xlsx');
data(1,:) = []; % remove the header line
% randomly permute the rows of data without repeating the value:
data = data(randperm(size(data,1)),:);
numeric_data = cell2mat(data(:,[1 2 3 4 6]));
handles.v_thickness_1 = numeric_data(:,1); % numeric
handles.v_thickness_2 = numeric_data(:,2);
handles.h_thickness_1 = numeric_data(:,3);
handles.h_thickness_2 = numeric_data(:,4);
handles.amplitude = data(:,5); % cell array of char vectors
handles.v_or_h_array = numeric_data(:,5);
handles.f_df = data(:,7);
handles.exp_counter = 1;
set(handles.text_exp_counter,'String',num2str(handles.exp_counter));
handles.region1 = [];
% Create the Arduino serial object
handles.arduinoObj = serialport('COM3', 38400);
configureTerminator(handles.arduinoObj,'CR/LF');
%
for i=1:8
handles.message = readline(handles.arduinoObj);
disp(handles.message)
end
create_patch(handles);
% Update handles structure
%guidata(hObject, handles);
% UIWAIT makes Hapticfinal wait for user response (see UIRESUME)
% uiwait(handles.finger);
function create_patch(handles)
if ishandle(handles.region1)
delete(handles.region1);
end
v_or_h = handles.v_or_h_array(handles.exp_counter);
if v_or_h == 0 % Vertical line
v_thick1 = handles.v_thickness_1(handles.exp_counter);
v_thick2 = handles.v_thickness_2(handles.exp_counter);
handles.region1 = patch( ...
'Parent',handles.axes1, ...
'XData',[v_thick1 v_thick2 v_thick2 v_thick1], ...
'YData',[-10 -10 10 10], ...
'FaceColor','red');
set(handles.axes1,'XLim',[-5 0],'YLim',[-10 10]);
% set(handles.axes1,'XLim',[-10 10],'YLim',[-10 10]);
else % Horizontal line
h_thick1 = handles.h_thickness_1(handles.exp_counter);
h_thick2 = handles.h_thickness_2(handles.exp_counter);
handles.region1 = patch( ...
'Parent',handles.axes1, ...
'XData',[-10 10 10 -10], ...
'YData',[h_thick1 h_thick1 h_thick2 h_thick2], ...
'FaceColor','red');
set(handles.axes1,'YLim',[0 5],'XLim',[-10 10]);
% set(handles.axes1,'XLim',[-10 10],'YLim',[-10 10]);
end
set(handles.axes1,'XGrid','on','YGrid','on');
axis(handles.axes1,'equal');
% Update handles structure
guidata(handles.finger,handles);
% call the button motion fcn to update the new patch's color:
finger_WindowButtonMotionFcn(handles.finger);
% UIWAIT makes franck_guide wait for user response (see UIRESUME)
% uiwait(handles.finger);
% --- Outputs from this function are returned to the command line.
function varargout = franck_guide_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VAR ARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Start_button.
function Start_button_Callback(hObject, eventdata, handles)
% hObject handle to Start_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.fileID = fopen('Start_Stop.txt','w');
handles.t = timer('ExecutionMode', 'fixedRate', ...
'Period', 0.5, ...
'TasksToExecute', Inf, ...
'TimerFcn', {@timerCallback, handles.finger});
start(handles.t);
set(handles.Start_button,'Enable','off'); % -> Disable the button
guidata(hObject,handles);% -----> do this to save the updated handles object
function timerCallback(~,~,f)
handles = guidata(f);
%fprintf(fileID,'(X, Y, time) = (%g, %g, %s)\n', get(0, 'PointerLocation'), datetime('now'));
fprintf(handles.fileID,'(X, Y, time) = (%g, %g, %s, %s, %s)\n', get(0, 'PointerLocation'), second(datetime('now')), ...
handles.amplitude{handles.exp_counter},handles.f_df{handles.exp_counter});
%fprintf('calling timer callback\n');
% --- Executes on button press in Next_button.
function Next_button_Callback(hObject, eventdata, handles)
% hObject handle to Next_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)uiconfirm(handles.UIFigure,'Are You sure?','Confirm Close',...
handles = guidata(hObject);
new_counter = handles.exp_counter + 1;
if new_counter > numel(handles.v_thickness_1)
msgbox('Experiment is Done!','DONE');
return
end
f = msgbox('Operation Completed','NEXT');
set(handles.text_exp_counter,'String',num2str(new_counter));
% drawnow();
handles.exp_counter = new_counter;
% delete the old patch and create a new one:
create_patch(handles);
% --- Executes on button press in Yes_button.
function Yes_button_Callback(hObject, eventdata, handles)
% hObject handle to Yes_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
answer = questdlg('Did You Feel it?', ...
'Vibration Feeling', ...
'YES','NO','CANCEL ','CANCEL ');
% Handle response
switch answer
case 'YES'
fileID= fopen('Vibr_ans.txt2','a');
YES = "I FEEL IT";
fprintf (fileID, "(%s,%s)\n",YES,handles.f_df{handles.exp_counter});
fclose(fileID);
%disp([answer ' yes i feel it.'])
%Yes_answer = 1;
case 'NO'
fileID= fopen('Vibr_ans.txt2','a');
NO = "I DON'T FEEL IT";
fprintf (fileID, "(%s,%s)\n",NO,handles.f_df{handles.exp_counter});
fclose(fileID);
%disp([answer ' no i don''t feel it.'])
%No_answer = 2;
case 'CANCEL'
disp('cancel')
Cancel = 0;
end
% --- Executes on button press in Stop_button.
function Stop_button_Callback(hObject, eventdata, handles)
% hObject handle to Stop_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
stop(handles.t) %whenever we want to stop.
fclose(handles.fileID);
set(handles.Start_button,'Enable','on'); % -> Enable the button
guidata(hObject,handles);
% --- Executes on mouse motion over figure - except title and menu.
function finger_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to finger (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
pos = get(hObject, 'currentpoint'); % get mouse location on figure
global x;
global y;
x = pos(1);
y = pos(2); % assign locations to x and y
set(handles.xloc, 'string', ['x loc:' num2str(x)]); % update text for x loc
set(handles.yloc, 'string', ['y loc:' num2str(y)]); % update text for y loc
% Determine if mouse is within the region
p_x = get(handles.region1,'XData');
p_x = p_x([1 2]);
p_y = get(handles.region1,'YData');
p_y = p_y([1 3]);
ax_xl = get(handles.axes1,'XLim');
ax_yl = get(handles.axes1,'YLim');
ax_units = get(handles.axes1,'Units');
if ~strcmp(ax_units,'pixels')
set(handles.axes1,'Units','pixels')
end
ax_pos = get(handles.axes1,'Position'); % axes1 position in pixels
if ~strcmp(ax_units,'pixels')
set(handles.axes1,'Units',ax_units);
end
% convert the patch XData and YData from axes coordinates to figure coordinates in pixels
p_x = (p_x-ax_xl(1))/(ax_xl(2)-ax_xl(1))*ax_pos(3)+ax_pos(1);
p_y = (p_y-ax_yl(1))/(ax_yl(2)-ax_yl(1))*ax_pos(4)+ax_pos(2);
if x >= p_x(1) && x <= p_x(2) && y >= p_y(1) && y <= p_y(2)
set(handles.region1,'FaceColor','g');
writeline(handles.arduinoObj, handles.amplitude{handles.exp_counter})
else
set(handles.region1,'FaceColor','r');
writeline(handles.arduinoObj, '0&1!')
end

21 Kommentare

That's quite a complicated workbook with multiple sheets. Can you give us the code to read in the x and y and times into arrays? Make it easy for us to help you by reading this:
@Image Analyst my bad. I am talking about the first sheet as an example. The "Moussa sheet".
You will see multiples rows like the line below . Don't take into consideration the position but just the time.
The format is: (X, Y, time) = (1127, 597, 2.137000e+01, 2&1!, BB2+İİİ)
For instance, 2.137000e+01 should just be taken into consideration. It represents the time in seconds.
So my question is from the moussa sheet , from the 1st row to the 153th row (represent the start and the end of a particular experiment), how many seconds do we have in total? When i substract,it gives me value that is incorrect.
Do you have code using textscan or sscanf to read in or parse the cells into separate MATLAB matrices?
data=readcell('Yasmin_data.xlsx','Range','A:A','Sheet',1);
t=strtrim(extractAfter(string(data),'='));
xyt=extractBetween(t(~ismissing(t)),'(',')');
xyt=split(xyt,',');
t=str2double(xyt(:,3));
For the lines in question,
>> t(153)-t(1)
ans =
16.00
>>
I've got format bank on, hence the two decimal places in display.
>> format short, format compact
>> [t(1) t(153) t(153)-t(1)]
ans =
21.3700 37.3680 15.9980
>>
Visual inspection of the file confirms the two time values are correct.
I'd STRONGLY suggest rewriting the file format to make parsing it easier; this is really tough sledding as is and doesn't seem to be any reason for it other than visually prettifying the file -- but nobody's going to be looking at the file in raw form, anyway.
@Image Analyst can you be more explicit? Are you suggesting me to use textscan or sscanf?
@Image Analyst the problem i am having is that after 59 s , everything goes back to 0... So basically it is from 0 to 59s ...I was expecting to have maybe sth like 59 , 60, 61s...
dpb
dpb am 30 Mai 2022
"...after 59 s , everything goes back to 0... "
Well, that's what you wrote into the file -- if you just wrote the clock seconds, then that's what you would expect.
If you want elapsed time from the beginning or from some particular point(s), you have to keep the time at that origin location and then subtract the origin from the time observations to get the duration.
If you don't know the start points until after the collection is over, then write the absolute datetime value (timestamp) into the file instead.
I'd still strongly recommend a revamping of that data file to make it easier to read back, though; IA is asking for you to provide the code to read the file as it's a lot of bother to parse as is and he clearly wasn't feeling motivated to spend the time just fixing that problem.
@dpb thank you for your prompt answer. Concerning the clock seconds,yes i messed up . İ did not know where my mind was.
From the data sheet, i know when a particular event start and when it ends. The only issue i am having is that it is not continuous lıke 59 s 60s as i mentıonned before. İt is my fault on thta.
Since i have messed up already , is there any way i can use that same sheet and find out a solution, İt is quite hectic
secondly what do you mean by the real code to read that file? This one below?
[~,~,data] = xlsread('excel_data_final.xlsx');
data(1,:) = []; % remove the header line
% randomly permute the rows of data without repeating the value:
data = data(randperm(size(data,1)),:);
numeric_data = cell2mat(data(:,[1 2 3 4 6]));
handles.v_thickness_1 = numeric_data(:,1); % numeric
handles.v_thickness_2 = numeric_data(:,2);
handles.h_thickness_1 = numeric_data(:,3);
handles.h_thickness_2 = numeric_data(:,4);
handles.amplitude = data(:,5); % cell array of char vectors
handles.v_or_h_array = numeric_data(:,5);
handles.f_df = data(:,7);
@dpb İ have used the example you gave me. Unfortunately it does not work for everytıng.İ took a specific example where the subject spent 20 mın, using your strategy it gives me 34 s
Yes, because as noted above, you didn't save the actual elapsed time. I just read the file and converted what was there.
You'll have to find the locations in the vector where the clock turned over a new minute and add that many minutes to the difference --
iEnd=153;
nMin=sum(diff(t(1:iEnd))<0);
tElapsed=60*nMin+t(iEnd)-t(1);
is the time field minutes and fractions of a minute?
dpb
dpb am 31 Mai 2022
@Walter Roberson -- no, it's just the wall clock seconds. See the Answer posted probably while you were writing this.
"I spent 15-20 minutes here" would be consistent with the posted numbers being minutes and fraction of minutes.
dpb
dpb am 31 Mai 2022
Bearbeitet: dpb am 31 Mai 2022
Excepting the data increase linearly in the range 0-60 which is indicative of wall time clock seconds -- but there's only one wrapping in the time interval given between recording 1 and 153 which is consistent with only one minute plus.
If had written minutes field instead, then it would indicate something over an hour, not twenty minutes.
Would need to see the actual code that created the data file to figure out just what OP actually did; it isn't consistent with either supposition but we don't have enough information to be able to decipher precisely from the information available.
OP didn't disagree with me when I allowed as how it appeared had just written wall clock seconds; but if it really was 20 minutes; that doesn't match up with the content.
ADDENDUM:
But---
>> sum(diff(t)<0)
ans =
34
>>
There were 34 resets in the total 4000+ record set OP provided, though...
>> duration(0,0,sum(diff(t)<0)*60+t(end)-t(1))
ans =
duration
00:34:30
>>
That would comprise 34.5 minutes.
Who knows??? Only OP can elucidate methinks.
>> duration(0,1,t(153)-t(1))
ans =
duration
00:01:15
>>
An hour and 15 minutes, maybe??? If were minutes instead of seconds...
@Image Analyst @dpb @Image Analyst i have edited the question and i have added the code related to it
start: 3.026100e+01
.
.
.
Stop: 5.975300e+01
I spent at least 15 -20 min here
subtract and we get about 29.5. If that were minutes and fraction of minutes then that would match the number of minutes you indicated. But if the field is in seconds and the span still represents about 29 minutes, then considering the values in the file, we would have to conclude very heavy aliasing if the times and that you just happen to have recorded at increasing seconds relative to each minute.
None of this makes sense unless the 15-20 minutes reference is wrong or irrelevant.
Referring to the 15 -20 min .
see attached file. Data sheet 3 "Hassen"
From the 2142 to 5799 , this is where i spend 15-20 min around that time.
OK, I dug into the code rather than just reading the output -- the timer callback function contains--
fprintf(handles.fileID,'(X, Y, time) = (%g, %g, %s, %s, %s)\n', ...
get(0, 'PointerLocation'), second(datetime('now')), ...
which shows that indeed, the file contains the seconds from the wall clock at the time the callback function was executed as surmised. The time was set with a repeat of
handles.t = timer('ExecutionMode', 'fixedRate', 'Period', 0.5, ...
and we indeed see that the difference between recorded times is within a few msec+/- of 500 excepting where the clock rollover occurs and get ~-60.
However, the code that wrote the "Start/Stop" values isn't posted so it's not clear where it came from.
>> (5799-2142)/2/60
ans =
30.4750
>>
would be about the time in minutes for 3675 records to have been written to the file at ~2/sec; closer to 30 minutes.
So what was the range of 1-153 in the original file asking about?
NB: the code in the Answer I posted will convert those times from the time callback to total elapsed time between whatever segments are selected.
The only mystery left is the code in the Start and Stop callbacks that wrote those two values to see what they really, really are/were.
The above approximation is pretty close to the difference; I didn't download and convert/read the last file to compute the actual delta from the record timestamps, but looks like @Walter Roberson's conjecture is spot on for those. That would be essentially the same code as in the timer callback except using something like
>> tnow=datetime('now'),minutes(minutes(minute(tnow))+seconds(second(tnow)))
tnow =
datetime
31-May-2022 14:45:36
ans =
45.6059
>>
@dpb i have edited the code. I have pasted the whole code
dpb
dpb am 1 Jun. 2022
There's nothing there that would write the 'Start' and 'Stop' unless the start(handles.t) and stop(handles.t) function calls do it as part of their functionality. If so, would have to know the internals there to know what, specifically it's writing.
I've never used GUiDE so I've no idea what's in the user data or what those functions actually do...or are they part of Arduino stuff--I've never had one of them, either...

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

dpb
dpb am 31 Mai 2022
Bearbeitet: dpb am 2 Jun. 2022
OK, I couldn't stand the suspense... :)
tT=readtable('EXPERİMENT_SU8.xlsx','Sheet',3,'Range','A2142:A5799','ReadVariableNames',0);
tT.Var1=strtrim(extractAfter(tT.Var1,'='));
tT.Var1=strtrim(extractBetween(tT.Var1,'(',')'));
T=split(tT.Var1,',');
T=str2double(T(:,3));
nMin=sum(diff(T)<0);
tElapsed=duration(0,0,60*nMin+T(end)-T(1));
results in
>> tElapsed
tElapsed =
duration
00:30:30
>>
which is expected simply by counting records.

15 Kommentare

@dpb you have saved my life. So i just have to use the code above right? You need a bottle of wine ahahah.
dpb
dpb am 31 Mai 2022
No problem -- once discovered what the problem was! :)
As the above shows, you can be very close simply by counting records and using the average sample rate, but the above will give you the actual elapsed time recorded, yes.
It would still be interesting to see how the Start, Stop time values were obtained -- of course, they don't answer the question re: elapsed within an area within the file.
Writing stuff as you did with the enclosed fields an with string data really makes parsing the file a lot more work than needs be -- why not write separate data as plain deleted text with a header for variable ID if wanted? Then it's a straight readmatrix or the like.
dpb
dpb am 31 Mai 2022
Yes, the code in the Answer is generic for the defined region selected.
You'll want to package that as a function and pass the start/stop indices as variables instead of the fixed numbers and starting from the beginning, of course.
As noted, you'll probably be within a 10 msec window or less of the answer by just counting records, though.
@dpb i am having an error.
The end operator must be used within an array index expression.
Error in Untitled2 (line 7)
tElapsed=duration(0,0,60*nMin+t(end)-t(1));
%this is the code i used
tT=readtable('EXPERİMENT_SU8.xlsx','Sheet',1,'Range','A9:A87','ReadVariableNames',0);
tT.Var1=strtrim(extractAfter(tT.Var1,'='));
tT.Var1=strtrim(extractBetween(tT.Var1,'(',')'));
T=split(tT.Var1,',');
T=str2double(T(:,3));
nMin=sum(diff(T)<0);
tElapsed=duration(0,0,60*nMin+t(end)-t(1));
@Franck paulin Ludovig pehn Mayo: the variable t is not defined in your code, but you try to index into it.
dpb
dpb am 1 Jun. 2022
Uppercase 'T" in last line, not lowercase 't'...
@dpb okay thank you . It is working with some milliseconds off . But it is great
dpb
dpb am 1 Jun. 2022
It's returning what's in the file for the indices given -- if it's off, it's either an indexing issue on the records selected range (500 msec or more) or resolution of the timer (<500 msec).
@dpb hello, hope you are doing great. An issue came up later . I am very confused the previous element and the element they are talking about have almost litteraly the same syntax.
Until this element, i was not having any issue.
Error using extractBetween (line 79)
Element 2289 of the text contains 0 substrings while the previous elements have 1. All elements must contain the same
number of substrings.
Error in Untitled2 (line 3)
tT.Var1=strtrim(extractBetween(tT.Var1,'(',')'));
%the code in question
tT=readtable('EXPERİMENT_SU8.xlsx','Sheet',1,'Range','A2142:A5799','ReadVariableNames',0);
tT.Var1=strtrim(extractAfter(tT.Var1,'='));
tT.Var1=strtrim(extractBetween(tT.Var1,'(',')'));
T=split(tT.Var1,',');
T=str2double(T(:,3));
nMin=sum(diff(T)<0);
TElapsed=duration(0,0,60*nMin+T(end)-T(1))
dpb
dpb am 2 Jun. 2022
Bearbeitet: dpb am 2 Jun. 2022
There's a malformed record -- "...the text contains 0 substrings"
I've forgotten the details of how the file was structured, but seems like I recall start/stop sections included a blank record in the sample file. Maybe you've passed in a set of index points that covers the end/beginning of an experiment?
The Q? is whether this is indicative of a fatal error of the above type or other case that needs to be addressed or whether it is safe to simply ignore the record and go on.
It's easy enough to clean the input such that any records not containing a delimiter are silently ignored; the Q? only you can answer is whether that's the right thing to do or not.
You'll need to look at the file content around that record number (counting from the beginning of the index passed, not from the file beginning, of course) and see what the cause is before can decide what the proper solution is.
@dpb the "ok i couldnt stand the suspense answer you gave". I am having that mistake from the same value, that's why i am very confused. I cannot get the answer. I am having the error. So it looks like it is not a mistake from the file since you were able to find an answer.
Secondly, i was also confused why i have to change the "t" into the capital "T" whereas it was working for you but not for me.
results in:
>> tElapsed
tElapsed =
duration
00:30:30
>>
dpb
dpb am 2 Jun. 2022
Bearbeitet: dpb am 2 Jun. 2022
As said, I'm pretty sure I recall I removed a blank record -- just thought it an aberration in the test case and to illustrate the logic to find the overall time, just did it and went on without showing had done explicitly.
As for t vs T, the code you copied had a typo I didn't catch -- I edited it from lower-case t to the capital T and missed that last line. I thought the uppercase T was a little more legible and distinguised from the lowercase since I had used the tT for the table variable.
Sorry for the confusion...I hadn't noticed that was still in the original until now.
You'll still need to look at the input files and ascertain the cause of empty records as whether are indicative of a break between experiments and therefore a real artifiact that shouldn't be ignored or whether it's a case where something went wrong in the acquisition/recording and some other corrective action needs to be taken -- like finding a bug in the callback function that writes the file or the timer hiccuped or whatever.
I'm still not sure who actually writes those "Start/Stop" entries into the file; nothing in the code I've seen so far shows such a output to the output file -- unless they are inherent in those two functions of that name that I don't have source for.
So the answer still is "I don't know what it's supposed to be; it's your experiment and data; I can't reliably interpret its meaning/correctness, only read what's in the file."
>> tT=readtable('EXPERİMENT_SU8.xlsx','Sheet',3,'Range','A2142:A5799','ReadVariableNames',0);
>> tT.Var1=strtrim(extractAfter(tT.Var1,'='));
>> tT.Var1=strtrim(extractBetween(tT.Var1,'(',')'));
>> T=split(tT.Var1,',');
>> T=str2double(T(:,3));
>> nMin=sum(diff(T)<0)
nMin =
30
>> tElapsed=duration(0,0,60*nMin+T(end)-T(1))
tElapsed =
duration
00:30:28
>>
I just redid that sample case and indeed, the lowercase t was left over from a prior case/test...the actual time for that file section turns out to be 28 seconds instead of 30 after the minutes.
But, that section of that file doesn't have a missing separator; it works as is -- that doesn't mean there isn't one missing somewhere else in the file -- or that you won't have a similar symptom if you get a wrong set of indices; I've not tried to do anything else in that file.
dpb
dpb am 3 Jun. 2022
So the answer still is "I don't know what it's supposed to be; it's your experiment and data; I can't reliably interpret its meaning/correctness, only read what's in the file."
That didn't come out as I really intended -- what I'm getting at is that I don't know which file nor what range you passed that produced the problem so I can't see what the content of the file is at that point -- as noted earlier, you need to go open the file you used and look at the area pointed out to by the error message and see what that content is -- if it's a bad record or whether you just passed a set of indices that encompass a break in the file.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 31 Mai 2022
The discussion of the file format aside, I thought that was the issue in converting to times initially and didn't notice the issue about having just used clock seconds.
You'll have to find the locations in the vector where the clock turned over a new minute and add that many minutes to the difference --
iEnd=153;
nMin=sum(diff(t(1:iEnd))<0);
tElapsed=60*nMin+t(iEnd)-t(1);

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by