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

조회 수: 7 (최근 30일)
Hasan Kaan Tuna
Hasan Kaan Tuna 2023년 7월 21일
편집: Pratyush 2023년 7월 25일
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