Cell contents reference from a non-cell array object.

조회 수: 2 (최근 30일)
mazari ahmed
mazari ahmed 2015년 3월 12일
댓글: mazari ahmed 2015년 4월 9일
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
Stephen23
Stephen23 2015년 3월 13일
편집: Stephen23 2015년 3월 13일
I have no idea what "it doesn't delete the values" means.
The setdiff documentation states "setdiff(A,B) returns the data in A that is not in B."
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
mazari ahmed 2015년 3월 13일
편집: mazari ahmed 2015년 3월 13일
l think the problem is in the last instruction it deletes the values but doesn't update the the neighbour_n when it displays.?
display(['Display new neighbour of ', num2str(i), ' are: ', num2str(neighbour_n{i})]);

댓글을 달려면 로그인하십시오.

채택된 답변

mazari ahmed
mazari ahmed 2015년 3월 14일
the answer is :
neighbour_n{i}= setdiff(neighbour_n{i},F);
problem solved

추가 답변 (1개)

Image Analyst
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
Image Analyst
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
mazari ahmed 2015년 4월 9일
Problem solved

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by