How to delete the nth element from all the variables in my workspace?

3 vues (au cours des 30 derniers jours)
Victor Lejona
Victor Lejona le 21 Oct 2015
Commenté : Victor Lejona le 21 Oct 2015
Hello
I would like to delete the nth element from all the variables in my workspace, which are all vectors of the same size. I tried playing with the "who" function but it didn't work, any ideas?
Many thanks in advance

Réponse acceptée

Thorsten
Thorsten le 21 Oct 2015
Modifié(e) : Thorsten le 21 Oct 2015
x = whos;
n = 2;
for i=1:numel(x)
eval([x(i).name '(' int2str(n) ')=[];'])
end
  4 commentaires
Thorsten
Thorsten le 21 Oct 2015
Modifié(e) : Thorsten le 21 Oct 2015
You could add a
if numel(x(i).name) >= n
to make the code more robust.
Victor Lejona
Victor Lejona le 21 Oct 2015
Good idea, thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by