필터 지우기
필터 지우기

Leave out dot notation in table variables

조회 수: 1 (최근 30일)
Dario Walter
Dario Walter 2019년 6월 19일
댓글: Walter Roberson 2021년 2월 14일
Hey guys,
I am using quite a lot of functions that require the variables from a table "D". Because of that, every function has the input parameter "D". Since I do not want to redefine the variables at the beginning of each function, my question is as follows:
When it comes to calculation, it currently requires me to write "D.Speed", "D.Time" etc. instead of "Speed", "Time". Is there a way to avoid the "D." notation. In VBA, for example, you can code
% With D
% Speed....
% Time...
% end
I could not find an equivalent method in Matlab.
Your help is highly appreciated!
  댓글 수: 5
Evan Droz
Evan Droz 2021년 2월 14일
Why are you trying to correct someone's use of code and wasting their time instead of answering their question, or better yet, not saying anything at all?
Walter Roberson
Walter Roberson 2021년 2월 14일
We have enough experience to know that the available methods to do what was asked, end up taking more time; and thus, the suggestions made to not do what was asked are suggestions aimed at having the poster not waste time.

댓글을 달려면 로그인하십시오.

답변 (2개)

madhan ravi
madhan ravi 2019년 6월 19일
편집: madhan ravi 2019년 6월 19일
I don’t know why it’s hard for you to use "D." , see https://in.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html to access table datas in different ways.

Walter Roberson
Walter Roberson 2019년 6월 19일
The closest MATLAB equivalent is import but it only applies for packages https://www.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html not for tables .
There are ways to do it dynamically, but those ways are error prone .
You should probably just do a bunch of search-and-replace to add in the table name.
  댓글 수: 3
Stephen23
Stephen23 2019년 6월 19일
"It simply makes the code hard do read beacause you always have to include the "D." notation."
To me that notation makes it clearer to read, because then I can tell immediately where each variable is defined (which in turn this makes code easier to write, debug, and maintain). And this advantage applies to the MATLAB JIT compiler just as much as it does to me!
What you are trying to do is certainly possible, but it would be complex, liable to bugs, and inefficient. Read this to know why:
"So you would leave it as it is?"
Yes, your code is fine just as it is.
Dario Walter
Dario Walter 2019년 6월 19일
Thank you Stephen!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by