to delete some rows frm cell
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    

this is a cell 'names ' in the workspace
i want to delete all the row whose having string data in 2 column 
i am doing this by using this code
for ii =1:333
   if isempty(names(ii,2))
       ii+1;
   else
       delete(names(ii,2))
       ii+1;
   end
but it gives error so plz tell me what will be the code for this 
my workspace has
   names 333*2 cell
0 Commenti
Risposte (1)
  Jan
      
      
 il 29 Mag 2021
        
      Modificato: Jan
      
      
 il 29 Mag 2021
  
      Please read the Getting Started chapters of the documentation and study Matlab's Onramp to learn the basics.
Do not increase the loop counter of a for loop manually. This is confusing only,because the loop ignores the changes.
isempty(names(ii,2)) does not, what you expect. names(ii,2) is a cell, which contains an empty char vector, so it is not empty. The contents is empty, so you need the curly braces: names{ii,2}
The delete command does not remove elements from an error, see:
doc delete
If you delete an element of an array, the rest of the array is shifted to the top. Then a loop would overse the following element.
A solution for your problem:
emptyElem = cellfun('isempty', names(:, 2));
names     = names(~emptyElem, :);
Or with a loop:
toDelete = false(1, 333);
for ii =1:333
   toDelete(ii) = isempty(names{ii,2});
end
names(toDelete, :) = [];
0 Commenti
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!