I want to loop for files in workspace
Show older comments
Dear all,
I have a lot of data that I imported into my workspace. Let's say I have data1, data2,... and dataN in my workspace. For example, I want to get length(data1), length(data2),... and length(dataN) automatically using a loop. Do I have any way to do that?
1 Comment
Stephen23
on 12 May 2022
"Let's say I have data1, data2,... and dataN in my workspace."
And that is the start of your problems: badly-designed data with pseudo-indices forced into the variable names. Accessing numbered variable names in a loop is one way that beginners force themselves into writing slow, complex, inefficient, buggy code that is difficult to debug:
Much better data design would use one array, then you could use simple and efficient indexing, just like MATLAB is designed for.
Accepted Answer
More Answers (1)
KSSV
on 12 May 2022
s = whos ;
for i = 1:length(s)
s(i).size
end
Categories
Find more on Workspace Variables and MAT Files 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!