input multi workspaces in function
1 次查看(过去 30 天)
显示 更早的评论
hi
I am working on input several data from workspace to a function.
However, I need to deal with hundreds of data.
Instead of input data one by one, I am wondering whether there is a way to input all workspace.
For example: I imagine I can name the datas as data1 to data10, then I can input data1 to data10 into the function by for loop.
or is there other way can solve this problem.
Thanks
2 个评论
Stephen23
2020-1-21
编辑:Stephen23
2020-1-21
"I imagine I can name the datas as data1 to data10, then I can input data1 to data10 into the function by for loop."
What you imagine is one of the slowest, buggiest, most complex way of accessing your data.
Putting numbers into variable name means that you are doing something wrong.
Accessing variable names dynamically is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:
"or is there other way can solve this problem."
Yes: store the data in one array (using indexing), then your task is trivial.
回答(1 个)
Jeremy
2020-1-21
Put the data into one array, pass it into the function, and parse the array inside the function?
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!