How Matlab access data in nested structures?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I use a nested structure in my program to store and organize variables:
struct.store1.var1 = var1;
struct.store1.var2 = var2;
struct.store1.var3 = var3;
struct.store1.var4 = var4;
struct.store2.var1 = var5;
struct.store2.var2 = var6;
And this going on for around 100 variables (mostly doubles and matrices). My question is should I reorganize struct in an unested structure (like herunder) to improve performances?
struct.store1Var1 = var1;
struct.store1Var2 = var2;
struct.store1Var3 = var3;
struct.store1Var4 = var4;
struct.store2Var1 = var5;
struct.store2Var2 = var6;
0 件のコメント
採用された回答
Neil Guertin
2018 年 1 月 4 日
For a situation like this, code readability and adaptability is much more important than performance. Even if one of these methods is slightly faster than the other, the compute time saved is not worth the extra time you will spend trying to make changes when the requirements for your project change.
If you have hundreds of variables, you also might want to think about completely restructuring your program. Use functions so that each variable is only defined and used where it needs to be, or use a different data structure that better matches your data.
Once the program is done, and if performance is still an issue, you can use the profiler to identify the bottlenecks. I guarantee it won't be the structures.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!