Alternative for eval of dynamic variables
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
From what I understand from the online community is that the use of dynamic variables is not acceptable/accurate/buggy.
I have 11 meshgrids (xyz-grids; to make it easy e.g. A,B,...,K) laying next to each other. For each of these 11 grids I want to calculate changing volumes over the years using 17 datasets (= xyz-data through the years). (the meshgrids have different sizes, that's why I did not make an overall grid)
I already assigned the xyz-data to my grids with scatteredInterpolant, so right now I have 17 variables (98,00,...,17) containing the same xy-values but different z-values (through the years; in total 11x17=189 variables; e.g. A_98,A_00,...,A17,B_98,...,K_17).
Now I need to calculate the volumes (=(difference between z-value & reference level)*gridsize; e.g. 50x50 and ref level -20) for each dataset for each mesh grid (so 17x11 times); afterwards I'll compare the results to each other so no need to worry about that.
The reason I like to use dynamic variables is the fact that results can be interpreted (more?) easily and that I don't really understand the online solutions for this.
Is there an efficient way to make a function or adjust my method/grids/variables/names to calculate the volumes of at least all datasets of 1 meshgrid (so 17x times) or even a way this can be done for all meshgrids at once (so 17x11 times)? (In the past I wrote everything 11x17 times which was very inefficient/dangerous for mistakes)
Thanks in advance for reading this (& maybe even helping me)!
4 Commenti
Stephen23
il 4 Apr 2020
Modificato: Stephen23
il 4 Apr 2020
"Is there an efficient way..."
No.
You designed your data badly, which means you have forced yourself into writing inefficient code.
Bad data design cannot be fixed by patching it up afterwards via super-efficient magic commands that do not exist.
"The reason I like to use dynamic variables is the fact that results can be interpreted (more?) easily..."
Indexing is so simple and easy to understand that millions of programmers use indexing every day in countless different programming languages. Not using indexing is like cutting your feet off before running a race.
"In the past I wrote everything 11x17 times which was very inefficient/dangerous for mistakes"
Computers are really only good at one thing: doing simple tasks repeatedly in a loop. So whenever you copy-and-paste code like that you are just doing the computer's menial job for it (as well as increasing the risk of bugs, making code pointlessly complex, harder to maintain, etc.). The computer can repeat the task very efficiently when you use indexing.
Risposta accettata
Rik
il 3 Apr 2020
If you use a cell array you can store everything in a single array even if the size are different. Because you can index into the cell array you can use a simple for loop, removing any need to repeat your code.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Time Series Objects in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!