How can I show equality in cell arrays?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have an array like this:
P = cell (50 , 5);
each cell in the first column of this array is a 4x960 matrix with 0/1 elements. I used a function like this:
for i = 1:50
F{i,2} = f(P{i,1})
end
in order to use 'f' function for each cell of column '1'. Now the 'f' function is like this:
function b = f ( a )
b = cell(4,16);
j=0;
for i = 1:4
for k = 1:960
jp=j;
j= ceil (k/60);
if j~=jp
counter=2;
end
if a(i,k) == 1
b{i, j}(counter) = k;
counter = counter + 1;
end
b{i,j}(1) = counter - 2;
end
counter = 2;
end
in this function, 'a' is one cell from column '1' in 'P'. It start to check each element in 'a' and return the distance between two consecutive '1' values, and also puts the returned values of each block of 1x60 in one cell in b array. So 'b' would be a 4x16 cell array and each cell hase undefined length.
the code and the function work correctly but when I want to use this function in different iterations, in the second iteration I get this error:
??? Undefined function or method 'eq' for input arguments of
type 'cell'.
Error in ==> f at 14 if a(i,k) == 1
Would you please help me with this?
0 个评论
采纳的回答
Walter Roberson
2016-10-29
If you are getting that error, the implication is that there is some P{i,1} which is a cell instead of being a numeric array. You must have constructed P incorrectly, such as if you had
P{i,1} = cellfun(..., 'Uniform', 0)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!