Filter löschen
Filter löschen

Error in Loop in a loop

1 Ansicht (letzte 30 Tage)
liu James
liu James am 15 Dez. 2016
Kommentiert: liu James am 15 Dez. 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

Akzeptierte Antwort

KSSV
KSSV am 15 Dez. 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 Kommentar
liu James
liu James am 15 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by