Converting logical to cell array

My code works with data extracted by a different code. Here it is:
for i=1:length(TrialTimestamps) %loop through trials
start1=TrialTimestamps(i);finish1=LightOnTimestamps(i); %trial onset to light on
temp1=(start1<=PokeTimestamps)&(PokeTimestamps<=finish1);% counts the nose pokes in this epoch
if temp1 == 0
temp1(i) = 0;
end
numpokes1(1,i)=temp1;
end
This is the error I receive: Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 61-by-1.
If I don't have numpokes, then temp1 only has logical, which cannot be used by the rest of the code. I need it to be in cell. I don't know how to turn it into a cell, but also preserve the entirety of the data.

 Respuesta aceptada

Star Strider
Star Strider el 11 de Mayo de 2020
I do not understand if ‘PokeTimeStamps’ changes its size (only that it appeasrs to be a column vector), or for that matter, what your code is doing.
One possibility:
numpokes1{:,i}=temp1;
That puts it in the column of cell array ‘numpokes’.
See if that does what you want.

2 comentarios

Lal Karaarslan
Lal Karaarslan el 11 de Mayo de 2020
It gives out this error: Unable to perform assignment because brace indexing is not supported for variables of this type.
What the code is supposed to do is, go through all the trials in one session of an experiment and then count the 'nose pokes' during a particular period that recurs each trial. And if there are none present then I want it to have 0 rather than an empty set. Afterwards I will graph this.
When I tested that approach with this code:
temp1 = rand(10,1)>0.5;
numpokes{:,1} = temp1;
it ran without error.
The sort error my code threw when you used it usually means that ‘numpokes’ (here) already exists as something other than a cell array. The same error appears with:
numpokes = zeros(10);
temp1 = rand(10,1)>0.5;
numpokes{:,1} = temp1;
However this runs without error:
numpokes = cell(1,1);
temp1 = rand(10,1)>0.5;
numpokes{:,1} = temp1;
as does this:
numpokes = cell(1,1);
for i = 1:5
temp1 = rand(10+i,1)>0.5;
numpokes{i,:} = temp1;
end
Preallocate it as a cell array and my code should run without error.
That should work.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 11 de Mayo de 2020

Comentada:

el 12 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by