Filter löschen
Filter löschen

Using fmincon to optimize Simulink model for optimal trajectory

3 Ansichten (letzte 30 Tage)
Joshua Levin Kurniawan
Joshua Levin Kurniawan am 10 Mai 2024
Beantwortet: Nipun am 30 Mai 2024
Hello, so i want to search for optimal trajectory (by defining spline) position input to the Simulink Simscape Multibody model to minimize the total force input to the model. However, I encountered the following error in constraint function.
Error using chckxy
The first and second inputs must be of type double or single.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in GetStartedWithProblemBasedOptimizeLiveEditorTaskExample>constraintFcn (line 43)
dataStructure.signals(1).values=spline(nTime,locX,dataStructure.time);
Besides form that, when I try to exclude the constraint, the solution of the optimal trajectory is always the same with the initial points. Can anyone help me with the situation? Hereby I attach the folder.

Antworten (1)

Nipun
Nipun am 30 Mai 2024
Hi Joshua,
I understand that you want help with calculating how many hours of data fall within the current hour in MATLAB. Here is a concise approach to solve this:
% Sample data: timestamps as datetime array
timestamps = datetime(2024, 5, 30, randi([0, 23], [100, 1]), randi([0, 59], [100, 1]), randi([0, 59], [100, 1]));
% Current hour
currentHour = hour(datetime('now'));
% Extract hours from timestamps
dataHours = hour(timestamps);
% Count occurrences within the current hour
hoursInCurrentHour = sum(dataHours == currentHour);
disp(hoursInCurrentHour);
Replace timestamps with your actual data.
Hope this helps.
Regards,
Nipun

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by