delete empty timetables from workspace by condition
2 次查看(过去 30 天)
显示 更早的评论
Hello My problem is the following:
I have several different timetables and other variables in my workspace. Some timetables contain data and others are empty. I want to clear the timetables from my workspace having the following conditions:
- timetable name begins with tt_* (i.e. tt_k_1, tt_n_1, tt_m_2)
- timetable size 0xnn (--> nn varies but timetable is empty)
I already found:
vars = whos('-regexp','tt_') % find timetables beginning with tt_
The problem is now to get into the structure and choose the files having the size 0xnn and delete them. I tried to build a loop but i just get errors. Does anyone have an idea ? Thanks falamanki
1 个评论
Stephen23
2018-10-29
"Does anyone have an idea ?"
Yes: Do NOT do this! Magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
The simplest solution is to not get into this situation in the first place. Most likely you did not sit there are type all of those names out by hand, so the correct place to fix your code is where those variables were first created in the workspace. For example, if they were load-ed from a .mat file, then simply load them into output variables (which are structures):
S = load(...)
If you tell us how those variables got into your workspace, then we can show you how to write simpler, neater, more robust code to process them all.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!