Effacer les filtres
Effacer les filtres

Why am I receiving multiple database errors for a simple line of code?

1 vue (au cours des 30 derniers jours)
Mike Jam
Mike Jam le 19 Déc 2022
Commenté : Mike Jam le 20 Déc 2022
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!

Réponse acceptée

Bora Eryilmaz
Bora Eryilmaz le 19 Déc 2022
Modifié(e) : Bora Eryilmaz le 19 Déc 2022
Your for loop index, i, goes up to
size(ALPI01.time)
and you are trying to index into the (i+1)th entry of the variable ALPI01.time within the for loop. When i == size(ALPI01.time) at the end of the for loop, the (i+1) entry of that variable does not exist in the expression:
if day(ALPI01.time(i+1)) == day(ALPI01.time(i))
You can make your for loop go up to:
for i=1:size(ALPI01.time)-1
to fix the issue.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by