Clear Filters
Clear Filters

Error in Loop in a loop

1 view (last 30 days)
liu James
liu James on 15 Dec 2016
Commented: liu James on 15 Dec 2016
I'm getting this error
Cell contents reference from a non-cell array object.
Error in setParam (line 86)
N{i}=((19*(TR{i}(t-1,1)))+TR{i}{t,1})/20;
After trying to run this for loop.
for i=1:length(TR)
for t=length(TR{i})
if t<21
N{i}=mean(TR{i}(1:t,1));
else
N{i}=((19*(TR{i}(t-1,1)))+TR{i}{t,1})/20;
end
end
end

Accepted Answer

KSSV
KSSV on 15 Dec 2016
Try
N{i}=((19*(TR{i}(t-1,1)))+TR{i}(t,1))/20;
Instead of
N{i}=((19*(TR{i}(t-1,1)))+TR{i}{t,1})/20;
  1 Comment
liu James
liu James on 15 Dec 2016
Although this works and doesn't give me the error. The answer that it provides isn't what I'm looking for. I'm trying to index each cell and calculate and spit it out. Do you know how I can achieve it?
for i=1:length(TR)
for t=length(TR{i})
if t<21
N{i}{t,1}=mean(TR{i}(1:t,1));
else
N{i}{t,1}=((19*(TR{i}(t-1,1)))+TR{i}(t,1))/20;
end
end
end
I tried this, but the answer provided becomes 0 for all cells.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!