Azzera filtri
Azzera filtri

Error in Loop in a loop

1 visualizzazione (ultimi 30 giorni)
liu James
liu James il 15 Dic 2016
Commentato: liu James il 15 Dic 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

Risposta accettata

KSSV
KSSV il 15 Dic 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 Commento
liu James
liu James il 15 Dic 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by