You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
36 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
17 Comments
Walter Roberson
on 19 May 2022
okay, and did you register each of the global variables as a datastore using the Port Manager?
amr makhlouf
on 22 May 2022
i have tried couple of things one of which to use the data store memory block , and i have tried to register the variables in the port manager but it's not shown @Walter Roberso@Walter Roberson
Walter Roberson
on 22 May 2022
You might be interested in my discussion at https://www.mathworks.com/matlabcentral/answers/1653710-global-variable-in-simulink#comment_2009495
amr makhlouf
on 24 May 2022
i have read the full discussion over there but there are some point that i don't understand :-
1- where i shoud add the first part of the code starting from % Variables required by the control algorithm
% Sampling time of the predictive algorithm [s]
Ts_value = 4e-5; till
SS.InitialValue = mat2str(value);
end .. i quite belive this should be in the intial function call backs .
2- in the main function function [sa,sb,sc] = control(T_ref,sflux_ref,wm,i_meas,kr,Lm,p,r_sigma,t_sigma,tr) you have included multiple of inputs starting from Kr to tr which is not included in the refrence paramters from the induction motor paramters
Walter Roberson
on 24 May 2022
That code all involved a specific model the user provided, in which that script was responsible for initializing variables and parameters, and then using sim() to run the model.
Adding additional parameters to the function was the cleanest way of importing Simulink parameters.
amr makhlouf
on 24 May 2022
well fourtunately , am trying the same exact model that the user was trying to do actually the full model is being illustrated in the predictive control book . i mean have you tried to run the model and it worked ? am using matlab version 2016a so idon't know if there's a comptability problem.
so my question is does the first part of the code has to be implment in the call backs and i have to change all the given variables to somthing_value e.g. sf_nom has to be sf_nom_value to work with the code ??
and when i add the additional paramters to the model it has to get a signal from somewhere which i don't know ?
i have alos attached my model so you can see we are working almost on the same thing. . i even have tried the data store memory thing which you mentioned in your explantion then i find our that Simulink.Signal Object is better for multiple global data but still recieve no result .
Walter Roberson
on 24 May 2022
I got the parameters and global variables working when I was helping the person. The overall code could not be run because of the unexpected 2x1 vector that I discussed in that Answer. (There is a bus that is being split into two entities instead of into three, so one ends up as a vector.)
amr makhlouf
on 24 May 2022
alright so my question is i have to make a simulink signal to all global variables that includes : Ts Rs Lr Lm Ls p tr kr r_sigma t_sigma lambda v states ?? in the model explorer >> model workspace.
then i have to intialize the model variables till sim () in the call backs then rest of the codes in the matlab function , please correct me if am wrong ?
Walter Roberson
on 26 May 2022
I have attached the editted models I created in that linked Question.
When you run this, you will quickly get an error. It will say
Error using run_MPC (line 67)
Errors occurred during parsing of MATLAB function 'MPC_DTC_IM/MATLAB Function'
This is because
Incorrect dimensions for matrix multiplication.
Check that the number of columns in the first matrix matches the number of rows in the second matrix.
To perform elementwise multiplication, use '.*'.
Function 'MATLAB Function' (#64.1097.1116), line 38, column 18: "(kr/tr-kr*1i*wm)*Fr"
The reason for this is what I explained in the previous question, about the bus with 3 elements being split into two locations, leading to a vector in an unexpected place. Which is outside of the domain of the question about how to set parameters and global variables.
amr makhlouf
on 27 May 2022
unfourtantely i have matlab 2016a , i cannot run it . i understand the matrix problem but my question is do i have to put the first part of the code in the intial function in call backs or just put all of the code in the m file , excuse me am way to new to matlab and am trying to learn
Walter Roberson
on 27 May 2022
This is specifically about using matlab to set up parameters and globals, and then use sim() to run the model. This code is not designed to be put into initfcn. It is potentially possible that some of it could be moved to initfcn callbacks, but it was not designed around that possibility.
amr makhlouf
on 28 May 2022
i have attached the final matlab file i have made following all the steps in this thread :
1- define a signal and data store memory for global variables.
2- defining all the code inside the m file and the intial function in call backs
3- checked that every blocks work just fine sattrting from the induction motor model to lc filter that i have made
4- i even get an outside space vector modulation controller to make sure that my model is working . however i still recieve errors regarding data type could you plese let me know how can i fix this . thank you so much
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 (0)
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)