필터 지우기
필터 지우기

Data Store Memory to Global Workspace

조회 수: 1 (최근 30일)
Yusuf Selim KARATAS
Yusuf Selim KARATAS 2020년 1월 26일
답변: BhaTTa 2024년 6월 14일
Hello,
I am using a function that reads some values from a data storage memeory and writes back to data storage memory. What I want to do is writing one of these data to global workspace so that amplitude of the voltage source can be change. How can I do that?
Thanks.

답변 (1개)

BhaTTa
BhaTTa 2024년 6월 14일
To write data to the MATLAB global workspace from within a function, you can use the assignin function. This function allows you to assign a value to a variable in a workspace different from the one currently executing. In your case, you want to assign a value to a variable in the base (global) workspace, which is the workspace you interact with at the MATLAB command prompt or in scripts.
Here's a basic outline of how you can use assignin to achieve this:
Step 1: Define Your Function
Suppose you have a function that reads some values and you want to update the amplitude of a voltage source based on this data. Inside this function, after processing or reading the necessary value, you would use assignin to write this value to the global workspace.
function myFunction()
% Example of reading a value
amplitudeValue = 5; % Assume this is the value you read and want to write to the global workspace
% Write the value to a variable in the global workspace
assignin('base', 'voltageAmplitude', amplitudeValue);
end
In this example, voltageAmplitude is the name of the variable that will be created (or overwritten if it already exists) in the global workspace with the value of amplitudeValue.
Step 2: Call Your Function
You simply call your function from the command window, a script, or another function. When it executes, it will create (or update) the voltageAmplitude variable in the global workspace.
myFunction();
Step 3: Access the Variable
Now, you can access voltageAmplitude directly from the command window or any script/function that operates in the global workspace.
disp(voltageAmplitude);

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by