from workspace to MATLAB FUNCTION BLOCK in simulink unable to fetch data in scope

3 次查看(过去 30 天)
i have a variable name A in Workspace containing time and data value,as this data with time or anything..i am trying this in my MATLAB Function block,I unable to get data value after simulation in scope..as this i tried in basic only.
error is coming invalid matrix variable ,asking time and data value both,i given both ,still getting error.
can anyone help....

回答(1 个)

Abhas
Abhas 2024-8-1
Hi Sangeeta,
For importing data from the MATLAB Workspace, processing it using a MATLAB Function Block, and visualizing it using a Scope Block, follow the steps below:
  • Define the Variable in MATLAB Workspace:
% Example data
time = 0:0.1:10; % Time vector from 0 to 10 seconds with 0.1s intervals
data = sin(time); % Example data, sine wave
A = [time' data']; % Combine time and data into a single matrix
  • Create a Simulink Model: Add and Configure a "From Workspace Block" and set the "Data" parameter to variable "A".
  • Add and Configure a MATLAB Function Block:
function y = processData(u)
% Example processing: Just pass the input through
y = u;
end
  • Add a Scope Block: Connect the output of the "From Workspace" block to the input of the "MATLAB Function" block and the output of the "MATLAB Function" block to the input of the "Scope" block..
You may refer to the following MathWorks documentation link to have a better understanding on "From Worspace" block: https://www.mathworks.com/help/simulink/slref/fromworkspace.html

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by