Apply a change on all the double variables of a .mat file at once

1 次查看(过去 30 天)
Hello,
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.
Thanks

回答(1 个)

Stephen23
Stephen23 2021-5-8
"Do you have any idea on how I can apply a change on all the double variables of a .mat file at once."
Easy:
  1. load into an output argument (which is a scalar structure)
  2. loop over the fields of that structure (hint: use fieldnames)
  3. check if the field contains a double type array
  4. make the changes you want
  5. save the structure using the -struct option
  2 个评论
amakoba yim
amakoba yim 2021-5-8
First of all I thank you for your well organized answer by steps.
As if I'm a beginner in matlab, 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).
I forgot to tell you that all this I do on app designer.
So to summarize I need to load the variables from a .mat file on my application and apply this change on a hundred variables (at once) before plotting them.
I thank you again
Stephen23
Stephen23 2021-5-10
编辑:Stephen23 2021-5-10
"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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by