Cell contents reference from a non-cell array object.
显示 更早的评论
How to delete an element k in a cell array in a for loop? l have a set called neighbour_n{i} where i varies from 1 to n
But it returns me this error :
??? Cell contents reference from a non-cell array object.
Error in ==> @(d)setxor([d{:}],[k])
Error in ==> broadcastelimination at 118 cellfun(fun, neighbour_n, 'UniformOutput', false)
neighbour_n=cell(N,1);
N = numel(neighbour_n);
for i=1:N
if (ismember(k, neighbour_n{i}));
idx = find(cell2mat(neighbour_n{i}) == k);
neighbour_n{i}(idx) = [];
end
end
8 个评论
This is a follow-up to your previous question:
You are using the code that the cyclist provided, but have not taken into account their edit and minor change of code. Put simply: you need to try the other code that they provided. They even explains this in their comment.
Instead of asking new questions, you should post a comment to their answer if you have any questions about what they are doing, or if it does not work as you expect it to.
mazari ahmed
2015-3-12
The code above includes this:
cellfun(@(x) x(~ismember([x{:}], F)), neighbour_n, 'uniformoutput', 0)
whereas the cyclist's (current) final answer was this:
cellfun(@(x)setdiff(x,8),stated_n,'UniformOutput',false)
The first assumes that the elements are cell arrays, the second assumes that they are numeric arrays.
This means that you did not use the cyclist's latest answer: if they fixed their code in their answer then you need to include this change in your code too.
mazari ahmed
2015-3-12
mazari ahmed
2015-3-12
编辑:mazari ahmed
2015-3-12
I have no idea what "it doesn't delete the values" means.
This means if you still have values in the output that you do not expect to have then the you need to check that the input values are correct. If an element of A is not in B then it will be in the output.
And I note that the cyclist is also giving advice on your original question here:
Which is a good example of why I said at the start of this thread that you should not ask new questions about the same topic, but you should keep communicating on the same thread until the topic is resolved.
mazari ahmed
2015-3-13
编辑:mazari ahmed
2015-3-13
采纳的回答
更多回答(1 个)
Image Analyst
2015-3-13
Not sure what's going on in your parallel discussion, but if you have a cell array called neighbour and you want to delete the k'th cell from that cell array, you can do this:
neighbour_n(k) = []; % Note parentheses, not braces.
You don't need to put it in a loop. See the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F to get a better intuitive feeling for cell arrays.
3 个评论
mazari ahmed
2015-3-13
Image Analyst
2015-3-13
Sorry - it's too late at night for me to delve into all that. I suggest you keep at it with your original thread.
mazari ahmed
2015-4-9
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!