Info

This question is closed. Reopen it to edit or answer.

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 view (last 30 days)
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 Comment
Geoff Hayes
Geoff Hayes on 2 Mar 2019
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...

Answers (1)

Walter Roberson
Walter Roberson on 2 Mar 2019
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.

This question is closed.

Community Treasure Hunt

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

Start Hunting!