How to pick a value inside of a .mat file?

1 次查看(过去 30 天)
Hey all,
I have .mat file that contains 14k double variables and their values. Also, I have a workspace that contains some of those signals and more. I want to change values of the workspace variables with the ones in the .mat file. So, how can I check if my workspace has a copy of the singal in the .mat file and change its value? And, apply it for all 14k variables respectively?
Thanks.
  5 个评论
Hasan Kaan Tuna
Hasan Kaan Tuna 2023-7-23
Can I use ismember like: ismember(MatFileWith14kVariables, ws) ? In this example ws stands for workspace. If answer is no; let's say my .mat file with 14k variables is named as FKV and, it is defined in workspace. How can I check if a variable defined in FKV is also defined in workspace? Also, how can I change that specific variable's value in workspace with the one in FKV?
Stephen23
Stephen23 2023-7-23
"Can I use ismember like: ismember(MatFileWith14kVariables, ws) ? In this example ws stands for workspace."
I see nothing in the ISMEMBER documentation to suggest that it supports a "workspace" as an input argument (whatever that means). The ISMEMBER documentation states what input arguments it supports:
But given that the word "workspace" has a very specific meaning in MATLAB:
which contradicts your explanation given here, we can only conclude that either your explanations are inaccurate or you are using standard terms to mean other things. That makes it very hard for us to help you.

请先登录,再进行评论。

采纳的回答

Pratyush
Pratyush 2023-7-25
编辑:Pratyush 2023-7-25
Hi Hasan,
I understand that you have some variables defined in the workspace and you want to update the variables from thier value stored in a .mat file. You only want to update those variables of your workspace which are present in your .mat file. You can use "load" function to do this. Use the following command.
% make an array of variables in your workspace
varNames = who;
% Load the specific variables from the .mat file
load('your_file.mat', varNames{:});
This would update the variables of your workspace with their value present in the .mat file and leave the variables that are not present in the .mat file unmodified.Refer to the documentation for more detail: Load variables from file into workspace.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by