Clear Filters
Clear Filters

delete empty timetables from workspace by condition

4 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 29 Oct 2018
"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.

Sign in to comment.

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!