Alternative for readable but slow Table dot notation

조회 수: 9 (최근 30일)
Julien MC
Julien MC 2022년 5월 27일
편집: Stephen23 2022년 5월 30일
Hi really like how legible the dot notation is for tables in Matlab... however it is just soooo slow to access and slows all my routines down.
I was wondering if there was an alternative to this?
Basically I was bundling up sets of data such as PhyProp, NumProp, GeomProp into tables and passing those to sub-functions.
At the top of each function I would unbundle the variables I needed:
say:
a = PhyProp.a
b = PhyProp.b
c = GeomProp.c
etc...
It made the function argument lists much more conscise and the code overall was still readable as all the unbundling always happened at the top of the function.
What I would like to avoid is to have to use indices, as it means you have to remember what they are before you can write new code.
for example if I had a cell array or something I could do something similar:
a = PhyProp{1}
b = PhyProp{2}
etc... but I have to remember that a is at index 1 etc...with tables it was just so much more readable.
I'll take any advice :)
  댓글 수: 5
Julien MC
Julien MC 2022년 5월 30일
HI @dpb, thanks for your comment. Agree with you here, that local copies are not required. I did run the profiler on the code and 'readtable' and associated table calls are definitely hogging a lot of computation time. I was super surprised as my table is no more than 20 entries in a row, which is much less than you have.
Stephen23
Stephen23 2022년 5월 30일
편집: Stephen23 2022년 5월 30일
"Why create local copies of the same data? Just use the table variables as is."
As long as the variables are not written to, then probably no local copies are made:
A local variable is just a handle to the existing data, without the repeating the indexing operation.

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

답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by