Asked by Dario Walter
on 19 Jun 2019

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!

Answer by madhan ravi
on 19 Jun 2019

Edited by madhan ravi
on 19 Jun 2019

Sign in to comment.

Answer by Walter Roberson
on 19 Jun 2019

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.

Stephen Cobeldick
on 19 Jun 2019

Dario Walter's "Answer" moved here:

Thanks for your replies. @madhan ravi: It simply makes the code hard do read beacause you always have to include the "D." notation. A little excerpt from my code:

function D= Mode1_Calc(D)

D.Mode1_Outer_s=nan(height(D),1);

D.Mode1_Inner_s=nan(height(D),1);

for i=1:height(D)

%dbstop in Mode1_Calc at 16 if i>=31

InterSectLineX(i,:)=[D.Sinkrate_fpm(i) D.Sinkrate_fpm(i)];

InterSectLineY(i,:)=[D.RadioAlt_ft(i) 0];

end

end

@Walter Roberson: So you would leave it as it is?

Thanks a lot!

Stephen Cobeldick
on 19 Jun 2019

"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
on 19 Jun 2019

Thank you Stephen!

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Stephen Cobeldick (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/467843-leave-out-dot-notation-in-table-variables#comment_716278

## Dario Walter (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/467843-leave-out-dot-notation-in-table-variables#comment_716281

## Stephen Cobeldick (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/467843-leave-out-dot-notation-in-table-variables#comment_716290

Sign in to comment.