How to perform arithmetic operation that would affect all variables in a folder at once
Mostra commenti meno recenti
There are 5 variables in a folder (crate1, crate2, crate3, crate4, crate5). Each of these variables have 3 sub-variables inside them. The 3 sub-variables have same names but different values, for all the variables. For example, crate1 has month, time, date. Crate2 also has month, time, date. And so on up to crate5... The task needed is to divide sub-variables (only month and time) by 0.5, for all the variables crate1 to crate5... Instead of doing it manually one after other, is there a way I could do for all at same time?
7 Commenti
"There are 5 variables in a folder..."
A folder is an abstract concept used in computer storage which contains links to file and/or other computer directories. In contrast a variable is an array within MATLAB memory. The two are completely unrelated.
If you are actually asking about five variables in a MATLAB workspace then the simple solution is to put them into one array (e.g. a cell array) and loop over that using basic indexing. Note that numbering variables is a sign that you are doing something wrong (in this case: that your data should be in one array).
Rik
il 28 Dic 2021
In this case it sounds like a struct array would be the best choice.
Ayobami Meadows
il 28 Dic 2021
Ayobami Meadows
il 29 Dic 2021
Stephen23
il 29 Dic 2021
"The task needed is to divide sub-variables (only month and time) by 0.5..."
Multiplying by two is probably clearer.
Ayobami Meadows
il 29 Dic 2021
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!