In a matrix, to remove the columns in which the element of the first line is 0, we can use:
ind2remove = (A(1,:) == 0);
A(:,ind2remove) = [];
How do I do that if A is a cell? I want to remove the columns in which the element of the first row is 0.
I tried:
ind2remove = (A{1,:} == 0);
A{:,ind2remove} = [];
but I got the error message:
??? Error using ==> eq
Too many input arguments.
Error in ==> ind2remove = (A{1,:} == 0);
Indexing using
{ }gives you the contents of the cell, whereas indexing using( )returns the same type as the original object i.e., ifAis a cell,A{i,j}will return what it’s holding, andA(i,j)will always return a cell. You need the latter.So in your case, you can do the following to eliminate all columns where the first row has a
0.The assumption here is that each cell in the first row holds only a single numeric element, as per your comment.