How can I delete variables whose name contains a specific word?
20 次查看(过去 30 天)
显示 更早的评论
Let's say that I have three variables: var_red, var_blue, var_green, var2_blue
How can I specify to delete all the variables containing the word "blue"?
Thank you very much
采纳的回答
更多回答(2 个)
Jan
2016-10-17
编辑:Jan
2016-10-17
Although the clear * methods works, consider that this is a bad programming pattern: Do not hide information in the names of variables. Data should be carried as value, not inside the name.
var(1).value = 123;
var(1).color = 'red';
var(2).value = 456;
var(2).color = 'blue';
toDelete = strcmp({'var.color'}, 'red');
var(toDelete) = [];
Then variables like "nabluencode" or "credentials" are not removed accidently.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!