- load into an output argument (which is a scalar structure)
- loop over the fields of that structure (hint: use fieldnames)
- check if the field contains a double type array
- make the changes you want
- save the structure using the -struct option
Apply a change on all the double variables of a .mat file at once
1 view (last 30 days)
Show older comments
amakoba yim on 7 May 2021
Do you have any idea on how I can apply a change on all the double variables of a .mat file at once.
The change will be a shift of 4 elements, example:
(A, B and C are variables in the .mat file)
A_before = [1 2 3 4 5]; => A_after = [0 0 0 0 1 2 3 4 5];
B_before = [11 22 33 44 55]; => B_after = [0 0 0 0 11 22 33 44 55];
C_before = [111 222 333 444 555]; => C_after = [0 0 0 0 111 222 333 444 555];
The first .mat file contains a hundred variables, and another .mat file which contains a structure of 200 variables.
How to apply this recalibration to all the variables in the .mat file at once.
Stephen23 on 8 May 2021
"Do you have any idea on how I can apply a change on all the double variables of a .mat file at once."
Stephen23 on 10 May 2021
Edited: Stephen23 on 10 May 2021
"I didn't really understand on your answer what is the command that allows the change I want to do on all vectors can be done (at once)."
There is probably no one single "the command", most likely you will need multiple steps to convert multiple "vectors" to class double, something like my answer outlines. How to convert the class depends on what format/class the data currently has, which you did not describe. Possible double would help.
If you want more help with this, please upload some sample data by clicking the paperclip button.
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!