Try this:
function Yref = generateYref(n_y, Np, Rr, Vo_xy_ref)
Yref = zeros(n_y * Np, 1);
Yref(1:2) = Rr * [real(Vo_xy_ref); imag(Vo_xy_ref)];
Yref(1:2) = Rr * Vo_xy_ref;
for k = n_y + 1 : n_y : n_y * Np
Yref(row_i:row_f) = Rr * Yref(row_i - n_y : row_f - n_y);
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.