Using fmincon to optimize Simulink model for optimal trajectory
조회 수: 4 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Nipun
2024년 5월 30일
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!