Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
32 views (last 30 days)
Show older comments
i was trying to make a predictive code algorithm however i recieve the same error every time .
code below.
function [Sa,Sb,Sc] = control(T_ref,sflux_ref,wm,i_meas)
% Variables defined in the parameters file
global Ts Rs Lr Lm Ls p tr kr r_sigma t_sigma lambda v states
persistent x_opt Fs %Fsp1 Tp1 g
if isempty(x_opt), x_opt = 1; end
if isempty(Fs), Fs = 0 + 0i*1; end
T_ref = T_ref(1) + 1j*T_ref(2);
sflux_ref = sflux_ref(1) + 1j*sflux(2);
i_meas = i_meas(1) + 1j*i_meas(2);
wm = wm(1) + 1j*wm(2);
% Stator flux estimate
Fs = Fs + Ts*(v(x_opt) - Rs*i_meas);
% Rotor flux estimate
Fr = Lr/Lm*Fs+i_meas*(Lm-Lr*Ls/Lm);
g_opt = 1e10;
for i = 1:8
% i-th voltage vector for current prediction
v_o1 = v(i);
% Stator flux prediction at instant k+1
Fsp1 = Fs + Ts*v_o1 - Rs*Ts*i_meas;
% Stator current prediction at instant k+1
Isp1 = (1+Ts/t_sigma)*i_meas+Ts/(t_sigma+Ts)*(1/r_sigma*((kr/tr-kr*1i*wm)*Fr+v_o1));
% Torque prediction at instant k+1
Tp1 = 3/2*p*imag(conj(Fsp1)*Isp1);
% Cost function
g = abs(T_ref - Tp1)+ lambda*abs(sflux_ref-abs(Fsp1));
if (g<g_opt)
g_opt = g;
x_opt = i;
end
end
18 Comments
akram amri
on 8 Feb 2024
Hello, I have the same problem Did you solve the code? Could you please give me the corrected code?
Answers (1)
Gayathri
on 3 Feb 2025
This error occurs because, in "MATLAB Function" block, global declarations are not mapped to the MATLAB global workspace. To use global data in your "MATLAB Function" block, you must:
- Declare a global variable in your MATLAB Function block.
- Register a Data Store Memory block that has the same name as the global variable as in the "MATLAB Function" block.
- In the Ports and Data Manager you may need to manually create the data entry, and change the name to match the Data Store Memory block, and set the scope to Data Store Memory.
- You will need to specify Dimensions, Signal type (real/complex), and Data type (e.g. double) for the variable in the corresponding Data Store Memory block.
For reference please run the below command in the command window to get the release specific documentation.
web(fullfile(docroot, 'simulink/ug/using-global-data-with-the-matlab-function-block.html'))
You can also refer to the below documentation link for more information.
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!