Index exceeds array dimensions. Index value 7 exceeds valid range [1-6] for array 'u'. Error in 'control/MATLAB Function' (line 8) y=u(row,:);
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i would out of function is 0 in 6 out all time when theta_array is empty or first colloum is [0,0,0,0,0,0]
function y = fcn(u)
persistent row
if isempty(row)
row=0;
end
row=row+1;
y=u(row,:);
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1165653/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1165658/image.png)
0 Kommentare
Antworten (1)
Abhaya
am 16 Sep. 2024
Hi Ahmed,
It looks like you're facing an issue with a persistent variable in your Simulink simulation. The error arises because the value of the variable ‘row’ exceeds the allowable limit, specifically the size of the variable ‘u’, which is 6.
This happens because ‘row’ is declared as a persistent variable. In a typical Simulink simulation, the model runs 51 iterations within a given interval. The function block is called with each iteration, and the variable ‘row’ increases each time the function block is called. By the seventh iteration, 'row' becomes 7, which results in the error.
To resolve this, you can adjust your simulation to run according to the length of the input vector. This can be achieved by modifying the value of parameter ‘fixed step size’ in model configurations to align with the size of your data.
For further information about persistent variables, please follow the MATLAB documentation for persistent variables.
To know more about Simulink model configuration, please follow the given link to MATLAB documentation for 'Manage Configuration Sets for a Model'.
Hope this helps.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!