Converting logical to cell array
10 views (last 30 days)
Show older comments
Lal Karaarslan
on 11 May 2020
Commented: Star Strider
on 12 May 2020
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.
0 Comments
Accepted Answer
Star Strider
on 11 May 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 Comments
Star Strider
on 12 May 2020
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.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!