Azzera filtri
Azzera filtri

Could not determine the size of this expression

16 visualizzazioni (ultimi 30 giorni)
Joseph
Joseph il 9 Mag 2024
Risposto: Hassaan il 9 Mag 2024
n_y = 2; Np = 7;
%% Output sequences
Yref=zeros(n_y*Np,1);
%Yref(1:2,1)=[Rr*real(Vo_xy_ref),Rr*imag(Vo_xy_ref)] ; % Construct output reference sequence
Yref(1:2,1)=Rr*Vo_xy_ref;
for k=n_y+1:n_y:n_y*Np
row_i=k;
row_f=k+n_y-1;
Yref(row_i:row_f,:)=Rr*Yref(row_i-n_y:row_f-n_y,:);
end
Error:Could not determine the size of this expression.
Function 'Model Predictive Control 1' (#39.4046.4065), line 157, column 33:
"row_i-n_y:row_f-n_y"
This portion of code works on its own as a .m file in matlab but when placed in a simulink model (matlab function block) gives this error any suggestions?

Risposte (1)

Hassaan
Hassaan il 9 Mag 2024
Try this:
function Yref = generateYref(n_y, Np, Rr, Vo_xy_ref)
% Define the size of the output explicitly
Yref = zeros(n_y * Np, 1);
% Make sure Vo_xy_ref is defined or passed as a parameter
% Assuming Rr is scalar and Vo_xy_ref is complex number or 2-element vector
if isreal(Vo_xy_ref)
Yref(1:2) = Rr * [real(Vo_xy_ref); imag(Vo_xy_ref)];
else
Yref(1:2) = Rr * Vo_xy_ref; % Adjust this based on the actual type of Vo_xy_ref
end
% Loop to propagate the values
for k = n_y + 1 : n_y : n_y * Np
row_i = k;
row_f = k + n_y - 1;
% Safeguard for bounds
if row_f <= n_y * Np
Yref(row_i:row_f) = Rr * Yref(row_i - n_y : row_f - n_y);
end
end
end
Suggestions for Debugging in Simulink:
  • Check Data Types and Sizes: Use the Model Explorer or other Simulink diagnostic tools to check data types and sizes. Make sure they are what you expect.
  • Simulink Configuration Parameters: Check your Simulink model configuration parameters for settings that might affect matrix operations, such as algebra simplifications and data type inheritance.
  • Simulink Diagnostic Viewer: When you run the simulation, Simulink provides detailed error messages and warnings in the Diagnostic Viewer, which can offer more insights into what might be causing the problem.
If you continue to encounter issues, consider breaking down the function into smaller parts to isolate which part specifically causes the error in Simulink. Additionally, review Simulink documentation on how to handle matrix operations and array indexing within MATLAB Function blocks, as there are often specific constraints and best practices to follow.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by