Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I have this loop equation i want to execute into a cell, but i receive an indexing out of bonds error, can anyone point out my error pls thanks.

1 回表示 (過去 30 日間)
Franc
Franc 2019 年 3 月 2 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
for = 3:numel(TM.D);
if isfield(TM.D{j},s1{k})
TM.D{j}.s1{k} = [];
end
for k = 1:numel(s1)
if j< 4
TM.P{j}.(s1{k}) = TM.D{j}.(s1{k}).signals.values ;
else
TM.P{j}.(s1{k}) = [TM.D{j-1}.(s1{k}).signals.values;TM.D{j}.(s1{k}).signals.values];
end
end
end
  1 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 3 月 2 日
Franc - which line of code is throwing the error? Please copy and paste the full error message to this question. The error message is telling you that you are trying to access an element in an array using an index that is outside the bounds of the array. For example,
>> X = randi(12,1,4);
>> X(5)
Index exceeds matrix dimensions.
because the array is of dimension 1x4 and the code is trying to access the fifth element. Presumably this error message is the same as yours...

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 3 月 2 日
You should be assigning to TM.D{j}.(s1{k})
However, you are out of range because at that point k does not have a value. That statement is before the for k loop.
You are assigning empty to the field named by the content of s1{k}, but a moment later you try to access the signals.value sub-structure of that now-empty field.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by