Load array from .mat file in Matlab System

조회 수: 71 (최근 30일)
Jan Letmade
Jan Letmade 2022년 8월 1일
댓글: Jan Letmade 2022년 8월 1일
I am curently coding a Matlab System for use in Simulink. I want to load two large arrays from a .mat file to be used in the Matlab System. Because of that, I figured I could load the data like this in the resetImpl function.
function resetImpl(obj)
% ...
obj.arrays = load('arrays.mat');
% ...
end
However, this results in the error:
Function 'load' can only be used as the right-hand side of a simple assignment to a struct or array variable without subscripting.
How can I load a .mat file in a Matlab System?
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 8월 1일
편집: Walter Roberson 2022년 8월 1일
load() storing into a simple variable . Extract fields from the struct and store into obj.
Note that this requires that you be using System Objects https://www.mathworks.com/help/simulink/slref/matlabsystem.html
Jan Letmade
Jan Letmade 2022년 8월 1일
Thank you @Walter Roberson! It did the trick. If anyone finds this later, this was the solution:
function resetImpl(obj)
% ...
arrays = load('arrays.mat');
obj.array1 = arrays.array1;
obj.array2 = arrays.array2;
% ...
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Abderrahim. B
Abderrahim. B 2022년 8월 1일
Hi!
I believe you are building a model in Simulink! If this is the case, you don't need to write a function for loading data:
Other blocks to import data to simulin can be foudn here .
hope this helps
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 8월 1일
From File is restricted to creating signal objects . If you needed to do something such as load a covariance matrix for matrix multiplication then From File would not be suitable .

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by