input multi workspaces in function

조회 수: 1 (최근 30일)
Sung YunSing
Sung YunSing 2020년 1월 21일
편집: Stephen23 2020년 1월 21일
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
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
Jeremy 2020년 1월 21일
Put the data into one array, pass it into the function, and parse the array inside the function?

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by