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

조회 수: 4 (최근 30일)
amakoba yim
amakoba yim 2021년 5월 7일
편집: Stephen23 2021년 5월 10일
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에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by