フィルターのクリア

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

1 回表示 (過去 30 日間)
Mike Jam
Mike Jam 2022 年 12 月 19 日
コメント済み: Mike Jam 2022 年 12 月 20 日
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!

採用された回答

Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 19 日
編集済み: Bora Eryilmaz 2022 年 12 月 19 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by