Borrar filtros
Borrar filtros

Error in Loop in a loop

1 visualización (últimos 30 días)
liu James
liu James el 15 de Dic. de 2016
Comentada: liu James el 15 de Dic. de 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

Respuesta aceptada

KSSV
KSSV el 15 de Dic. de 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 comentario
liu James
liu James el 15 de Dic. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by