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 天)
显示 更早的评论
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
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
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.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!