Why am I receiving multiple database errors for a simple line of code?
Show older comments
I've been trying to find the time a machine fails during a defined period. The latter is defined as the time difference between a 'False' true_false indicator and the following 'True' indicator. However, there is a limitation that if the time exceeds one day, 8 hours must be deducted (the time the virtual plant closes). This is an example of the tables I am analyzing labeled as ALPI01.
time state failure true_false
'PI01' '15.12.2022 13:09:29.784' 'state' 'PI01_Failed01' 'True'
'PI01' '15.12.2022 13:16:35.541' 'state' 'PI01_Failed01' 'False'
'PI01' '15.12.2022 13:37:33.189' 'state' 'PI01_Failed01' 'True'
'PI01' '15.12.2022 13:39:28.332' 'state' 'PI01_Failed01' 'False'
'PI01' '16.12.2022 11:34:29.726' 'state' 'PI01_Failed01' 'True'
'PI01' '16.12.2022 11:45:15.327' 'state' 'PI01_Failed01' 'False'
'PI01' '16.12.2022 19:43:42.487' 'state' 'PI01_Failed01' 'True'
'PI01' '16.12.2022 19:45:15.908' 'state' 'PI01_Failed01' 'False'
The code I wrote to serve my request is the following:
z =1;
for i=1:size(ALPI01.time)
if isequal(cell2mat(ALPI01.true_false(i)),'False')
if day(ALPI01.time(i+1)) == day(ALPI01.time(i))
FPI01(z) = seconds(ALPI01.time(i+1) - ALPI01.time(i));
z = z+1;
else
FPI01(z) = seconds(ALPI01.time(i+1) - ALPI01.time(i)) -28800;
z = z +1;
end
end
end
I used the day function before and it worked like a charm. I even used the same code but with few alterations to the repair time which is just the opposite of what I am finding now, and it worked pretty fine. Whenever I run this code I get the following error:
Error in matlab.internal.datatypes.parenReference_1D (line 12)
data = data(rowIndices);
Error in datetime/parenReference (line 19)
obj.data = parenReference_1D(obj.data, rowIndices);
Error in tabular/dotParenReference (line 114)
b = b(rowIndices);
Error in MTTF_MTTR1 (line 144)
if day(ALPI01.time(i+1)) == day(ALPI01.time(i))
As you can notice I am a noob when it comes to MATLAB, but I am working on myself.
Any help or clarification would be appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!