Error in Loop in a loop

1 次查看(过去 30 天)
liu James
liu James 2016-12-15
评论: liu James 2016-12-15
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

采纳的回答

KSSV
KSSV 2016-12-15
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 个评论
liu James
liu James 2016-12-15
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by