Category: Matlab
Category Archives: Matlab
Why is Answers Now Showing “Ran in” Links?
AFAICT, the "ran in" link is just a link to the same question.AFAICT, the "ran in" link is just a link to the same question. AFAICT, the "ran in" link is just a link to the same question. answers "ran in" MATLAB Answers — New Questions
Ultra RAM on True Dual Port RAM
HI,
I try to design True Dual Port RAM on Ultra RAM. I use block primitive True Dual Port RAM in 2024a and set RAMDirective ‘ultra’. Generated code has this attribute. But when implemen step in Vivado, i have info, that attribute ultra is ignored because invalid write mode. And after implementing my RAM design by block RAM, but i need based on Ultra RAM
Please, give advice about this problemHI,
I try to design True Dual Port RAM on Ultra RAM. I use block primitive True Dual Port RAM in 2024a and set RAMDirective ‘ultra’. Generated code has this attribute. But when implemen step in Vivado, i have info, that attribute ultra is ignored because invalid write mode. And after implementing my RAM design by block RAM, but i need based on Ultra RAM
Please, give advice about this problem HI,
I try to design True Dual Port RAM on Ultra RAM. I use block primitive True Dual Port RAM in 2024a and set RAMDirective ‘ultra’. Generated code has this attribute. But when implemen step in Vivado, i have info, that attribute ultra is ignored because invalid write mode. And after implementing my RAM design by block RAM, but i need based on Ultra RAM
Please, give advice about this problem hdl coder, ultra ram, ramdirective, simulink MATLAB Answers — New Questions
Who can tell me how to use GUIDE in MATLAB version 2025a?T-T
Who can tell me how to use GUIDE in MATLAB version 2025a?T_TWho can tell me how to use GUIDE in MATLAB version 2025a?T_T Who can tell me how to use GUIDE in MATLAB version 2025a?T_T transferred, guide, gui MATLAB Answers — New Questions
the save as option in the axis toolbar i causing the custom x label to collapse .
I an using app designer , the save as option in the axis toolbar i causing the custom x label to collapse and is saving the wrong label position because of it. How to fix the issueI an using app designer , the save as option in the axis toolbar i causing the custom x label to collapse and is saving the wrong label position because of it. How to fix the issue I an using app designer , the save as option in the axis toolbar i causing the custom x label to collapse and is saving the wrong label position because of it. How to fix the issue save as MATLAB Answers — New Questions
Simscape fluids error cylinder area parametrization
Hello i am a university student and i am trying to build a hydraulic system for a crane miniature. My hydraulic system has the my defined values but i am getting the error: Error:An error occurred during simulation and the simulation was terminated
Caused by:
[‘test_hydraulics/Solver Configuration1’]: At time 0.498629, one or more assertions are triggered. See causes for specific information.
Liquid volume must be greater than minimum physical volume. The assertion comes from:
Block path: test_hydraulics/Double-Acting Actuator (IL)1
Assert location:
o In between line: 242, column: 5 and line: 242, column: 11 in file: foundation.isothermal_liquid.elements.translational_mechanical_converter
o In between line: 386, column: 17 and line: 395, column: 39 in file: fluids.isothermal_liquid.actuators.double_actuator
I dont know what to do i tried editing the parameters and i noticed that when i change my actuator area paramters from m^2 to cm^2 it works.
Thanks in advance!Hello i am a university student and i am trying to build a hydraulic system for a crane miniature. My hydraulic system has the my defined values but i am getting the error: Error:An error occurred during simulation and the simulation was terminated
Caused by:
[‘test_hydraulics/Solver Configuration1’]: At time 0.498629, one or more assertions are triggered. See causes for specific information.
Liquid volume must be greater than minimum physical volume. The assertion comes from:
Block path: test_hydraulics/Double-Acting Actuator (IL)1
Assert location:
o In between line: 242, column: 5 and line: 242, column: 11 in file: foundation.isothermal_liquid.elements.translational_mechanical_converter
o In between line: 386, column: 17 and line: 395, column: 39 in file: fluids.isothermal_liquid.actuators.double_actuator
I dont know what to do i tried editing the parameters and i noticed that when i change my actuator area paramters from m^2 to cm^2 it works.
Thanks in advance! Hello i am a university student and i am trying to build a hydraulic system for a crane miniature. My hydraulic system has the my defined values but i am getting the error: Error:An error occurred during simulation and the simulation was terminated
Caused by:
[‘test_hydraulics/Solver Configuration1’]: At time 0.498629, one or more assertions are triggered. See causes for specific information.
Liquid volume must be greater than minimum physical volume. The assertion comes from:
Block path: test_hydraulics/Double-Acting Actuator (IL)1
Assert location:
o In between line: 242, column: 5 and line: 242, column: 11 in file: foundation.isothermal_liquid.elements.translational_mechanical_converter
o In between line: 386, column: 17 and line: 395, column: 39 in file: fluids.isothermal_liquid.actuators.double_actuator
I dont know what to do i tried editing the parameters and i noticed that when i change my actuator area paramters from m^2 to cm^2 it works.
Thanks in advance! simscape MATLAB Answers — New Questions
How to link uialert to my App Designer UI figure?
I recently took over a MATLAB project of a former colleague and is still learning how to write MATLAB code correctly. I would like to change working code that currently uses msgbox to now rather make use of uialert(). I can however not find a way to link the UIFigure of my app to the uialert function. My understanding is that the arguments should be as follows: uialert(uifigure,message,title). My problem seems to be with the uifigure argument.
The uialert Help indicates that the uifigure must be created with the uifigure function. When I use the following code I do get a new uifigure and the alert message appears in front of it as expected.
f = uifigure;
uialert(f,’Test’,’warning’);
I do however want the alert message to appear in front of the App Designer UIFigure rather than a newly created figure. I found code here on the forum that identifies the name of my App Designer figure:
hFigs = findall(groot, ‘Type’, ‘figure’)
hFigs = Figure (VTT) with properties:
Number: []
Name: ‘VTT’
I tried several ways to try to refer to the name of my App Designer figure but none of them worked. Below are two examples of what I tried.
uialert(‘VTT’,’Test’,’warning’);
uialert(hFigs.Name,’Test’,’warning’);
I got the following error with both lines of code:
Error using uialert (line 35)
Invalid or deleted figure handle. First argument must be a valid figure handle
I might be using the wrong terminology but I can not find any answers in this forum that explained to me how I can link uialert() to appear in front of the the App Designer UIFigure.I recently took over a MATLAB project of a former colleague and is still learning how to write MATLAB code correctly. I would like to change working code that currently uses msgbox to now rather make use of uialert(). I can however not find a way to link the UIFigure of my app to the uialert function. My understanding is that the arguments should be as follows: uialert(uifigure,message,title). My problem seems to be with the uifigure argument.
The uialert Help indicates that the uifigure must be created with the uifigure function. When I use the following code I do get a new uifigure and the alert message appears in front of it as expected.
f = uifigure;
uialert(f,’Test’,’warning’);
I do however want the alert message to appear in front of the App Designer UIFigure rather than a newly created figure. I found code here on the forum that identifies the name of my App Designer figure:
hFigs = findall(groot, ‘Type’, ‘figure’)
hFigs = Figure (VTT) with properties:
Number: []
Name: ‘VTT’
I tried several ways to try to refer to the name of my App Designer figure but none of them worked. Below are two examples of what I tried.
uialert(‘VTT’,’Test’,’warning’);
uialert(hFigs.Name,’Test’,’warning’);
I got the following error with both lines of code:
Error using uialert (line 35)
Invalid or deleted figure handle. First argument must be a valid figure handle
I might be using the wrong terminology but I can not find any answers in this forum that explained to me how I can link uialert() to appear in front of the the App Designer UIFigure. I recently took over a MATLAB project of a former colleague and is still learning how to write MATLAB code correctly. I would like to change working code that currently uses msgbox to now rather make use of uialert(). I can however not find a way to link the UIFigure of my app to the uialert function. My understanding is that the arguments should be as follows: uialert(uifigure,message,title). My problem seems to be with the uifigure argument.
The uialert Help indicates that the uifigure must be created with the uifigure function. When I use the following code I do get a new uifigure and the alert message appears in front of it as expected.
f = uifigure;
uialert(f,’Test’,’warning’);
I do however want the alert message to appear in front of the App Designer UIFigure rather than a newly created figure. I found code here on the forum that identifies the name of my App Designer figure:
hFigs = findall(groot, ‘Type’, ‘figure’)
hFigs = Figure (VTT) with properties:
Number: []
Name: ‘VTT’
I tried several ways to try to refer to the name of my App Designer figure but none of them worked. Below are two examples of what I tried.
uialert(‘VTT’,’Test’,’warning’);
uialert(hFigs.Name,’Test’,’warning’);
I got the following error with both lines of code:
Error using uialert (line 35)
Invalid or deleted figure handle. First argument must be a valid figure handle
I might be using the wrong terminology but I can not find any answers in this forum that explained to me how I can link uialert() to appear in front of the the App Designer UIFigure. uialert, app designer uifigure MATLAB Answers — New Questions
Spooky Graphed Data?
Data tip doesn’t match Yaxis or actual data. Actual data is 1073741824.
Can anyone explain this?Data tip doesn’t match Yaxis or actual data. Actual data is 1073741824.
Can anyone explain this? Data tip doesn’t match Yaxis or actual data. Actual data is 1073741824.
Can anyone explain this? graph MATLAB Answers — New Questions
Trying to start Obstacle Avoidance in NVIDIA Jetson with PX4 Autopilot in Hardware-in-the-Loop (HITL) Simulation with UAV Dynamics Modeled in Simulink
Hello, I ran into two problems when working with QGroundControl (QGC), Pixhawk and Jetson as a mission computer. QGC issues the error "Unable to start mission: Vehicle not changing to Mission flight mode". At the same time, the mission is loaded into autopilot, there is a connection between QGC and Pixhawk.
Obstacle Avoidance: The model in Simulink works, but the video viewer does not receive depth frames from Jetson.
In the Jetson log:
[sudo] password for superadmin: No protocol specified
nvbuf_utils: Couild not get EGL display connection
Opening in blocking MODE
State change is async
**starting the model**
I checked the connection beetween Host PC(192.168.1202) and Jetson(192.168.1.201) via wireshark
QGround also see mission computer
In simulink Obstacle Avoidance Model a have such warnings
What could be the cause of the error changing the flight mode to "Mission"? Could it be caused by issues on the Jetson side or in the Simulink model? How can I fix the "Could not get EGL display connection" error on the Jetson so that the obstacle avoidance model can transmit depth frames?Hello, I ran into two problems when working with QGroundControl (QGC), Pixhawk and Jetson as a mission computer. QGC issues the error "Unable to start mission: Vehicle not changing to Mission flight mode". At the same time, the mission is loaded into autopilot, there is a connection between QGC and Pixhawk.
Obstacle Avoidance: The model in Simulink works, but the video viewer does not receive depth frames from Jetson.
In the Jetson log:
[sudo] password for superadmin: No protocol specified
nvbuf_utils: Couild not get EGL display connection
Opening in blocking MODE
State change is async
**starting the model**
I checked the connection beetween Host PC(192.168.1202) and Jetson(192.168.1.201) via wireshark
QGround also see mission computer
In simulink Obstacle Avoidance Model a have such warnings
What could be the cause of the error changing the flight mode to "Mission"? Could it be caused by issues on the Jetson side or in the Simulink model? How can I fix the "Could not get EGL display connection" error on the Jetson so that the obstacle avoidance model can transmit depth frames? Hello, I ran into two problems when working with QGroundControl (QGC), Pixhawk and Jetson as a mission computer. QGC issues the error "Unable to start mission: Vehicle not changing to Mission flight mode". At the same time, the mission is loaded into autopilot, there is a connection between QGC and Pixhawk.
Obstacle Avoidance: The model in Simulink works, but the video viewer does not receive depth frames from Jetson.
In the Jetson log:
[sudo] password for superadmin: No protocol specified
nvbuf_utils: Couild not get EGL display connection
Opening in blocking MODE
State change is async
**starting the model**
I checked the connection beetween Host PC(192.168.1202) and Jetson(192.168.1.201) via wireshark
QGround also see mission computer
In simulink Obstacle Avoidance Model a have such warnings
What could be the cause of the error changing the flight mode to "Mission"? Could it be caused by issues on the Jetson side or in the Simulink model? How can I fix the "Could not get EGL display connection" error on the Jetson so that the obstacle avoidance model can transmit depth frames? jetson, px4, hitl, qgroundcontrol, cube orange plus MATLAB Answers — New Questions
C2000 CAN Video example calls out eCAN, but blockset shows CAN and we have an RX Issue
We are using two 379D launchpads. The TX section works fine.
The RX, when we connect the two boards, the bus stops as if the RX model is not configured correctly. We checked everything.
Is there a known good example of this we can use to get started ?We are using two 379D launchpads. The TX section works fine.
The RX, when we connect the two boards, the bus stops as if the RX model is not configured correctly. We checked everything.
Is there a known good example of this we can use to get started ? We are using two 379D launchpads. The TX section works fine.
The RX, when we connect the two boards, the bus stops as if the RX model is not configured correctly. We checked everything.
Is there a known good example of this we can use to get started ? c2000 can example issue MATLAB Answers — New Questions
Why am I getting a near 0 current in the flyback converter?
Hi,
I am simulating this flyback converter where Vin is 48 V, Vout should be 380 V, the mutual inductance has L1 = 1e-5 H, L2 = 0.036 H, VF in the diode is 2.1 V and C = 87e-6 F. As you can see in the diagram, I tried to control it first by close-loop but as I couldn’t get the right values, I tried by fixing a constant which is 0.116564 which is the calculated duty cycle for Vin= 48 V. The problem I get is the values of V_out which is -1.428 V and I_out near 0 but negative. I tried moving the current measurement block to the bottom and the top branch, changing the connection with the secondary inductance or the polarity in the voltage measurement. I never get positive voltage and positive current with high values. According to my calculations, I_out should be 2.53 A and V_out, as I said 380 V. Could someone with knowledge in power electronics and simulink help me with this issue? It’s R2022b version.
Thanks.
CarlosHi,
I am simulating this flyback converter where Vin is 48 V, Vout should be 380 V, the mutual inductance has L1 = 1e-5 H, L2 = 0.036 H, VF in the diode is 2.1 V and C = 87e-6 F. As you can see in the diagram, I tried to control it first by close-loop but as I couldn’t get the right values, I tried by fixing a constant which is 0.116564 which is the calculated duty cycle for Vin= 48 V. The problem I get is the values of V_out which is -1.428 V and I_out near 0 but negative. I tried moving the current measurement block to the bottom and the top branch, changing the connection with the secondary inductance or the polarity in the voltage measurement. I never get positive voltage and positive current with high values. According to my calculations, I_out should be 2.53 A and V_out, as I said 380 V. Could someone with knowledge in power electronics and simulink help me with this issue? It’s R2022b version.
Thanks.
Carlos Hi,
I am simulating this flyback converter where Vin is 48 V, Vout should be 380 V, the mutual inductance has L1 = 1e-5 H, L2 = 0.036 H, VF in the diode is 2.1 V and C = 87e-6 F. As you can see in the diagram, I tried to control it first by close-loop but as I couldn’t get the right values, I tried by fixing a constant which is 0.116564 which is the calculated duty cycle for Vin= 48 V. The problem I get is the values of V_out which is -1.428 V and I_out near 0 but negative. I tried moving the current measurement block to the bottom and the top branch, changing the connection with the secondary inductance or the polarity in the voltage measurement. I never get positive voltage and positive current with high values. According to my calculations, I_out should be 2.53 A and V_out, as I said 380 V. Could someone with knowledge in power electronics and simulink help me with this issue? It’s R2022b version.
Thanks.
Carlos flyback converter, power_electronics_control, power_conversion_control, simpowersystems, simulink MATLAB Answers — New Questions
Contact angle in a video of a sessile droplet
Hey all
Okay so i have this script to analyze videos of single droplets drying now i want to calculate the contact angles using the script i made which is also attachted but the method i am using now results in results that are not consistent and jaggery so do any of you have suggestions on how to improve the contact angle determination, i think it could also have something to do with how we binarize and determine the edge of the droplet? normally the script processes videos of around 30s at 100 fps but i couldnt attach that so here is a very short sample video. here is the code that calculates the contact angle
%binary image creation
backgroundDiff = abs(double(grayFrame) – averageBackground);
% threshold
binaryImage = backgroundDiff > backgroundThreshold;
% morphological operations to preserve droplet
cleanedImage = imopen(binaryImage, strel(‘disk’, morphOpenDiskSize));
cleanedImage = imclose(cleanedImage, strel(‘disk’, morphCloseDiskSize));
filledImage = imfill(cleanedImage, ‘holes’);
dropletOutsideSurface = filledImage & ~surfaceMask_logical;
dropletAll = filledImage;
% Find droplet boundary
dropletBoundary = bwboundaries(dropletMask);
if ~isempty(dropletBoundary)
outline = dropletBoundary{1};
x_outline = outline(:,2); % Column indices (x-coordinates)
y_outline = outline(:,1); % Row indices (y-coordinates)
if numel(x_outline) >= 20 % Need sufficient points
% Convert to physical coordinates (meters)
x_phys = x_outline * scale_Image * 1e-6;
y_phys = y_outline * scale_Image * 1e-6;
% Find contact points (points near the surface)
surface_y_phys = minYSurface * scale_Image * 1e-6;
contact_threshold = equiv_radius * 0.3; % 30% of droplet radius
% Find all points near the surface
near_surface_indices = find(abs(y_phys – surface_y_phys) < contact_threshold);
if length(near_surface_indices) >= 4
% Find the leftmost and rightmost contact points
x_contact = x_phys(near_surface_indices);
y_contact = y_phys(near_surface_indices);
[x_min, left_idx] = min(x_contact);
[x_max, right_idx] = max(x_contact);
left_contact_point = [x_min, y_contact(left_idx)];
right_contact_point = [x_max, y_contact(right_idx)];
% ADVANCED: Calculate contact angles using tangent method (from original)
tangent_range = equiv_radius * 0.2; % Distance for tangent calculation
% LEFT CONTACT ANGLE
left_contact_idx = near_surface_indices(left_idx);
distances_from_left = sqrt((x_phys – left_contact_point(1)).^2 + …
(y_phys – left_contact_point(2)).^2);
tangent_indices_left = find(distances_from_left <= tangent_range & …
distances_from_left > 0);
if length(tangent_indices_left) >= 3
above_contact = tangent_indices_left(y_phys(tangent_indices_left) < left_contact_point(2));
if length(above_contact) >= 3
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_left = polyfit(x_fit, y_fit, 1);
slope_left = p_left(1);
catch
slope_left = NaN;
end
else
slope_left = NaN;
end
if ~isnan(slope_left)
angle_rad_left = atan(slope_left);
contact_angle_left = 180 – rad2deg(angle_rad_left);
if contact_angle_left < 0
contact_angle_left = contact_angle_left + 180;
elseif contact_angle_left > 180
contact_angle_left = contact_angle_left – 180;
end
end
end
end
% RIGHT CONTACT ANGLE (similar process)
right_contact_idx = near_surface_indices(right_idx);
distances_from_right = sqrt((x_phys – right_contact_point(1)).^2 + …
(y_phys – right_contact_point(2)).^2);
tangent_indices_right = find(distances_from_right <= tangent_range & …
distances_from_right > 0);
if length(tangent_indices_right) >= 3
above_contact = tangent_indices_right(y_phys(tangent_indices_right) < right_contact_point(2));
if length(above_contact) >= 3
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_right = polyfit(x_fit, y_fit, 1);
slope_right = p_right(1);
catch
slope_right = NaN;
end
else
slope_right = NaN;
end
if ~isnan(slope_right)
angle_rad_right = atan(slope_right);
contact_angle_right = rad2deg(angle_rad_right);
if contact_angle_right < 0
contact_angle_right = contact_angle_right + 180;
elseif contact_angle_right > 180
contact_angle_right = contact_angle_right – 180;
end
end
end
end
% Calculate average contact angle
if ~isnan(contact_angle_left) && ~isnan(contact_angle_right)
contact_angle_avg = (contact_angle_left + contact_angle_right) / 2;
elseif ~isnan(contact_angle_left)
contact_angle_avg = contact_angle_left;
elseif ~isnan(contact_angle_right)
contact_angle_avg = contact_angle_right;
end
end
end
endHey all
Okay so i have this script to analyze videos of single droplets drying now i want to calculate the contact angles using the script i made which is also attachted but the method i am using now results in results that are not consistent and jaggery so do any of you have suggestions on how to improve the contact angle determination, i think it could also have something to do with how we binarize and determine the edge of the droplet? normally the script processes videos of around 30s at 100 fps but i couldnt attach that so here is a very short sample video. here is the code that calculates the contact angle
%binary image creation
backgroundDiff = abs(double(grayFrame) – averageBackground);
% threshold
binaryImage = backgroundDiff > backgroundThreshold;
% morphological operations to preserve droplet
cleanedImage = imopen(binaryImage, strel(‘disk’, morphOpenDiskSize));
cleanedImage = imclose(cleanedImage, strel(‘disk’, morphCloseDiskSize));
filledImage = imfill(cleanedImage, ‘holes’);
dropletOutsideSurface = filledImage & ~surfaceMask_logical;
dropletAll = filledImage;
% Find droplet boundary
dropletBoundary = bwboundaries(dropletMask);
if ~isempty(dropletBoundary)
outline = dropletBoundary{1};
x_outline = outline(:,2); % Column indices (x-coordinates)
y_outline = outline(:,1); % Row indices (y-coordinates)
if numel(x_outline) >= 20 % Need sufficient points
% Convert to physical coordinates (meters)
x_phys = x_outline * scale_Image * 1e-6;
y_phys = y_outline * scale_Image * 1e-6;
% Find contact points (points near the surface)
surface_y_phys = minYSurface * scale_Image * 1e-6;
contact_threshold = equiv_radius * 0.3; % 30% of droplet radius
% Find all points near the surface
near_surface_indices = find(abs(y_phys – surface_y_phys) < contact_threshold);
if length(near_surface_indices) >= 4
% Find the leftmost and rightmost contact points
x_contact = x_phys(near_surface_indices);
y_contact = y_phys(near_surface_indices);
[x_min, left_idx] = min(x_contact);
[x_max, right_idx] = max(x_contact);
left_contact_point = [x_min, y_contact(left_idx)];
right_contact_point = [x_max, y_contact(right_idx)];
% ADVANCED: Calculate contact angles using tangent method (from original)
tangent_range = equiv_radius * 0.2; % Distance for tangent calculation
% LEFT CONTACT ANGLE
left_contact_idx = near_surface_indices(left_idx);
distances_from_left = sqrt((x_phys – left_contact_point(1)).^2 + …
(y_phys – left_contact_point(2)).^2);
tangent_indices_left = find(distances_from_left <= tangent_range & …
distances_from_left > 0);
if length(tangent_indices_left) >= 3
above_contact = tangent_indices_left(y_phys(tangent_indices_left) < left_contact_point(2));
if length(above_contact) >= 3
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_left = polyfit(x_fit, y_fit, 1);
slope_left = p_left(1);
catch
slope_left = NaN;
end
else
slope_left = NaN;
end
if ~isnan(slope_left)
angle_rad_left = atan(slope_left);
contact_angle_left = 180 – rad2deg(angle_rad_left);
if contact_angle_left < 0
contact_angle_left = contact_angle_left + 180;
elseif contact_angle_left > 180
contact_angle_left = contact_angle_left – 180;
end
end
end
end
% RIGHT CONTACT ANGLE (similar process)
right_contact_idx = near_surface_indices(right_idx);
distances_from_right = sqrt((x_phys – right_contact_point(1)).^2 + …
(y_phys – right_contact_point(2)).^2);
tangent_indices_right = find(distances_from_right <= tangent_range & …
distances_from_right > 0);
if length(tangent_indices_right) >= 3
above_contact = tangent_indices_right(y_phys(tangent_indices_right) < right_contact_point(2));
if length(above_contact) >= 3
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_right = polyfit(x_fit, y_fit, 1);
slope_right = p_right(1);
catch
slope_right = NaN;
end
else
slope_right = NaN;
end
if ~isnan(slope_right)
angle_rad_right = atan(slope_right);
contact_angle_right = rad2deg(angle_rad_right);
if contact_angle_right < 0
contact_angle_right = contact_angle_right + 180;
elseif contact_angle_right > 180
contact_angle_right = contact_angle_right – 180;
end
end
end
end
% Calculate average contact angle
if ~isnan(contact_angle_left) && ~isnan(contact_angle_right)
contact_angle_avg = (contact_angle_left + contact_angle_right) / 2;
elseif ~isnan(contact_angle_left)
contact_angle_avg = contact_angle_left;
elseif ~isnan(contact_angle_right)
contact_angle_avg = contact_angle_right;
end
end
end
end Hey all
Okay so i have this script to analyze videos of single droplets drying now i want to calculate the contact angles using the script i made which is also attachted but the method i am using now results in results that are not consistent and jaggery so do any of you have suggestions on how to improve the contact angle determination, i think it could also have something to do with how we binarize and determine the edge of the droplet? normally the script processes videos of around 30s at 100 fps but i couldnt attach that so here is a very short sample video. here is the code that calculates the contact angle
%binary image creation
backgroundDiff = abs(double(grayFrame) – averageBackground);
% threshold
binaryImage = backgroundDiff > backgroundThreshold;
% morphological operations to preserve droplet
cleanedImage = imopen(binaryImage, strel(‘disk’, morphOpenDiskSize));
cleanedImage = imclose(cleanedImage, strel(‘disk’, morphCloseDiskSize));
filledImage = imfill(cleanedImage, ‘holes’);
dropletOutsideSurface = filledImage & ~surfaceMask_logical;
dropletAll = filledImage;
% Find droplet boundary
dropletBoundary = bwboundaries(dropletMask);
if ~isempty(dropletBoundary)
outline = dropletBoundary{1};
x_outline = outline(:,2); % Column indices (x-coordinates)
y_outline = outline(:,1); % Row indices (y-coordinates)
if numel(x_outline) >= 20 % Need sufficient points
% Convert to physical coordinates (meters)
x_phys = x_outline * scale_Image * 1e-6;
y_phys = y_outline * scale_Image * 1e-6;
% Find contact points (points near the surface)
surface_y_phys = minYSurface * scale_Image * 1e-6;
contact_threshold = equiv_radius * 0.3; % 30% of droplet radius
% Find all points near the surface
near_surface_indices = find(abs(y_phys – surface_y_phys) < contact_threshold);
if length(near_surface_indices) >= 4
% Find the leftmost and rightmost contact points
x_contact = x_phys(near_surface_indices);
y_contact = y_phys(near_surface_indices);
[x_min, left_idx] = min(x_contact);
[x_max, right_idx] = max(x_contact);
left_contact_point = [x_min, y_contact(left_idx)];
right_contact_point = [x_max, y_contact(right_idx)];
% ADVANCED: Calculate contact angles using tangent method (from original)
tangent_range = equiv_radius * 0.2; % Distance for tangent calculation
% LEFT CONTACT ANGLE
left_contact_idx = near_surface_indices(left_idx);
distances_from_left = sqrt((x_phys – left_contact_point(1)).^2 + …
(y_phys – left_contact_point(2)).^2);
tangent_indices_left = find(distances_from_left <= tangent_range & …
distances_from_left > 0);
if length(tangent_indices_left) >= 3
above_contact = tangent_indices_left(y_phys(tangent_indices_left) < left_contact_point(2));
if length(above_contact) >= 3
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_left = polyfit(x_fit, y_fit, 1);
slope_left = p_left(1);
catch
slope_left = NaN;
end
else
slope_left = NaN;
end
if ~isnan(slope_left)
angle_rad_left = atan(slope_left);
contact_angle_left = 180 – rad2deg(angle_rad_left);
if contact_angle_left < 0
contact_angle_left = contact_angle_left + 180;
elseif contact_angle_left > 180
contact_angle_left = contact_angle_left – 180;
end
end
end
end
% RIGHT CONTACT ANGLE (similar process)
right_contact_idx = near_surface_indices(right_idx);
distances_from_right = sqrt((x_phys – right_contact_point(1)).^2 + …
(y_phys – right_contact_point(2)).^2);
tangent_indices_right = find(distances_from_right <= tangent_range & …
distances_from_right > 0);
if length(tangent_indices_right) >= 3
above_contact = tangent_indices_right(y_phys(tangent_indices_right) < right_contact_point(2));
if length(above_contact) >= 3
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_right = polyfit(x_fit, y_fit, 1);
slope_right = p_right(1);
catch
slope_right = NaN;
end
else
slope_right = NaN;
end
if ~isnan(slope_right)
angle_rad_right = atan(slope_right);
contact_angle_right = rad2deg(angle_rad_right);
if contact_angle_right < 0
contact_angle_right = contact_angle_right + 180;
elseif contact_angle_right > 180
contact_angle_right = contact_angle_right – 180;
end
end
end
end
% Calculate average contact angle
if ~isnan(contact_angle_left) && ~isnan(contact_angle_right)
contact_angle_avg = (contact_angle_left + contact_angle_right) / 2;
elseif ~isnan(contact_angle_left)
contact_angle_avg = contact_angle_left;
elseif ~isnan(contact_angle_right)
contact_angle_avg = contact_angle_right;
end
end
end
end image processing, image analysis MATLAB Answers — New Questions
Possible bug in coneprog.m function
I am running a trajectory optimisation problem.
The formulation is convexified via slack variables and linearisation and I was testing coneprog as solver.
I noticed some issues with the function that I would like to report and verify if it is my mistake or a bug.
My code is completely deterministic. There is no randomisation and the execution should be 100% reproducible.
Nevertheless, running the same code multiple times with the same input and options leads to different results.
Unlinke fmincon, with coneprog it is impossible to access internal calculation and to understand what is going on, therefore I do not have many insights.
My guess is that a random noise is applied to the initial guess.
In theory this should not be a problem since a convex problem has only one minimum.
In practice, the solver sometimes finds an optimal solution and other times declares the problem unfeasible.
I can solve the same exact problem with an NLP formulation using fmincon, so I know for sure the proble is solvable.
I tried to change the initial conditions and the problem persists.
Sometimes, different minima are found in different calls of the solver.
This is not due to the presence of a flat in the solution space because the fval differ by 1 to 2 orders of magnitude.
Another issue I am having is connected to the iterative procedure I have implemented.
At first I obtain an anlytical initial guess that is numerically propagated.
The constraints are linearised around this reference trajectory and the coneprog is called to solve the problem.
Once the optimal control is obtained, the solution is again propagated and if the error is not below the specified tolerance the process is repeated iteratively.
For some initial conditions the solver works smoothly, but for other it stops at the 5-th or 6-th iteration (declaring the problem unfeasible) when it is really close to the finalise the solution.
Again, it is important to highlight that I am 100% confident that the problem is feasible.
It is important to highlight that some degree of reproducibility is still present.
Even if the solver behaves differently, the number of possible behaviours is limited to just a few outcomes, depending on the initial conditions.
In general, for every problem there are 2 or 3 possible outcomes.
Moreover, some outcomes may occur more frequently than others.
I have spent days trying to find the issue in my code, but now, after testing with fmincon, I am starting to be confident that the problem is in coneprog.
I have also noticed that the solver behaves differently depending on the optimalityTolerance.
This was later confirmed when I found out that the problem has already been reported on this forum here.
An other bug I noticed in some solutions is that both Primal and Dual Feasibility report a value, but if I check manually the constraint satisfaction, the feasibility is off by several order of magnitudes.
I am 100% confident that the check I performed is correct because it was performed with a breakpoint placed right after the call to coneprog as shown below.
I have also stored the inputs of coneprog right before the function was called.
In my opinion, if the problem is coneprog as I think it is, the bug is related to the update step of the current guess.
Have you experienced similar problem with coneprog, or are you aware of some limitations it may have?
Did you already encountered such problem and understood where it is coming from?
The main motivations why I think coneprog is the problem are the different outputs produced from a deterministic code, and the fact that, when the problem converges, the solution is correct.
As a final comment, I think it would be really useful to have the freedom of specifying an initial guess.
If I know already a solution that is both an interior point and very close to the optimal one, this would cut down considerably the computational time.
—————————————————————————————————————————-
Below you can find an example of the solver converging to an unfeasible point after some iterations.
The target value of poc is 1e-10.
The formulation of the optimsiation problem is based on a direct transcription to discretise a continuous trajectory into discrete nodes.
The solution vector x is built as:
x = [ux1 uy1 uz1 u1 … uxN uyN uzN uN b1 b2]
where:
[uxi uyi uzi] is the control vector at the i-th node.
ui is the magnitude of the control vector at the i-th node.
[b1 b2] are some end conditions that must satisfy a linear constraint
The only cone constraints present are the one that impose:
sqrt(uxi^2 + uyi^2 + uzi^2) <= 1
sqrt(uxi^2 + uyi^2 + uzi^2) <= ui
The linear objective function minimises the control effort defined as:
In the example below, the trajectory is discretised into 852 nodes.
This is clear from the initial Fval of every iteration that corresponds to the number of nodes, as the initial guess is probably all ones.
The last call of coneprog declares the problem unfeasible and it is the only iteration where Fval increases after the initial guess.
The problem with the constraint satisfication can be understood from the values of the Infeasibilities.
To help the problem converges I defined a lower bound to uxi, uyi, and uzi of -1, and a lower bound to ui of 0.
Similarly, I defined an upper bound to uxi, uyi, uzi, and ui of 1.
An Fval of 1.118894e+03 in the last line of the example below, clearly goes against the upper bound constraint, as the maximum value of Fval allowed by the upper bound is 852.
Instead the sovler is analysing a solution with Fval of approximately 1119, but it thinks that the constraints are satisfied, which is impossible.
Maybe my interpretation of Primal and Dual Feasibility is wrong, but my intuition is suggesting me that coneprog may have some problems.
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.351509e-01 2.500000e-01 8.338790e-02 0.43
1 2.903535e+02 5.653968e-02 4.217479e-02 1.406747e-02 0.46
2 5.760140e+01 1.155766e-02 8.621236e-03 2.875627e-03 0.50
3 1.826360e+01 3.567321e-03 2.660981e-03 8.875744e-04 0.54
4 1.587390e+01 2.115580e-03 1.578080e-03 5.263711e-04 0.58
5 1.496351e+01 1.979895e-03 1.476868e-03 4.926117e-04 0.61
6 1.477297e+01 1.930240e-03 1.439829e-03 4.802573e-04 0.65
7 1.407791e+01 1.740965e-03 1.298643e-03 4.331644e-04 0.69
8 1.195150e+01 1.139652e-03 8.501032e-04 2.835533e-04 0.73
9 1.118074e+01 9.249616e-04 6.899590e-04 2.301369e-04 0.76
10 9.263514e+00 3.932808e-04 2.933610e-04 9.785102e-05 0.80
11 8.435984e+00 1.662211e-04 1.239898e-04 4.135699e-05 0.84
12 8.137082e+00 8.259246e-05 6.160841e-05 2.054958e-05 0.89
13 7.834045e+00 4.811473e-06 3.589036e-06 1.197128e-06 0.93
14 7.817072e+00 4.211285e-07 3.141435e-07 1.047797e-07 0.97
15 7.815469e+00 1.297491e-08 9.741467e-09 3.228250e-09 1.02
16 7.815429e+00 2.773558e-09 3.724366e-09 6.900807e-10 1.05
Optimal solution found.
poc =
4.7669e-05
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 4.148309e-01 2.500000e-01 8.339003e-02 0.24
1 2.936365e+02 7.220152e-02 4.351262e-02 1.451408e-02 0.28
2 3.227398e+01 9.133979e-03 5.504640e-03 1.836128e-03 0.32
3 2.999204e+01 5.626122e-03 3.390612e-03 1.130973e-03 0.36
4 2.891739e+01 5.422358e-03 3.267812e-03 1.090012e-03 0.40
5 2.734221e+01 4.962369e-03 2.990597e-03 9.975440e-04 0.44
6 2.355320e+01 3.776002e-03 2.275627e-03 7.590585e-04 0.48
7 1.765904e+01 1.858229e-03 1.119871e-03 3.735444e-04 0.53
8 1.493406e+01 9.914144e-04 5.974810e-04 1.992958e-04 0.57
9 1.321215e+01 4.284890e-04 2.582311e-04 8.613560e-05 0.61
10 1.247209e+01 1.862607e-04 1.122510e-04 3.744245e-05 0.65
11 1.203916e+01 4.726695e-05 2.848568e-05 9.501685e-06 0.68
12 1.190390e+01 4.898257e-06 2.951962e-06 9.846561e-07 0.73
13 1.188906e+01 1.900382e-07 1.145391e-07 3.820181e-08 0.77
14 1.188847e+01 9.042867e-09 5.942560e-09 1.817813e-09 0.81
Optimal solution found.
poc =
1.7472e-08
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.740554e-01 2.500000e-01 8.338857e-02 0.23
1 2.549188e+02 4.172979e-02 2.789011e-02 9.302867e-03 0.26
2 9.392526e+01 1.561744e-02 1.043792e-02 3.481612e-03 0.30
3 2.667086e+01 4.410425e-03 2.947708e-03 9.832206e-04 0.34
4 2.407913e+01 2.549053e-03 1.703660e-03 5.682632e-04 0.39
5 2.355160e+01 2.499060e-03 1.670247e-03 5.571180e-04 0.43
6 2.324912e+01 2.449195e-03 1.636919e-03 5.460015e-04 0.47
7 2.249923e+01 2.308274e-03 1.542735e-03 5.145858e-04 0.50
8 2.040632e+01 1.851989e-03 1.237777e-03 4.128657e-04 0.54
9 1.970151e+01 1.692941e-03 1.131477e-03 3.774090e-04 0.59
10 1.744126e+01 1.126199e-03 7.526951e-04 2.510647e-04 0.62
11 1.620420e+01 8.023922e-04 5.362790e-04 1.788781e-04 0.66
12 1.474391e+01 3.945190e-04 2.636768e-04 8.795053e-05 0.70
13 1.427557e+01 2.644519e-04 1.767465e-04 5.895455e-05 0.73
14 1.370019e+01 1.011430e-04 6.759892e-05 2.254791e-05 0.77
15 1.348178e+01 3.984925e-05 2.663325e-05 8.883635e-06 0.81
16 1.336507e+01 7.537767e-06 5.037870e-06 1.680402e-06 0.85
17 1.334002e+01 6.477134e-07 4.329037e-07 1.443954e-07 0.88
18 1.333772e+01 1.179424e-08 7.999240e-09 2.629302e-09 0.93
19 1.333768e+01 1.381986e-10 8.290199e-09 3.080877e-11 0.99
Optimal solution found.
poc =
5.3035e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.472650e-01 2.500000e-01 8.338749e-02 0.23
1 2.309201e+02 2.520373e-02 1.814445e-02 6.052081e-03 0.27
2 9.405942e+01 1.047608e-02 7.541850e-03 2.515584e-03 0.31
3 2.721726e+01 3.116075e-03 2.243298e-03 7.482520e-04 0.35
4 2.416710e+01 1.805118e-03 1.299525e-03 4.334564e-04 0.40
5 2.375956e+01 1.781739e-03 1.282694e-03 4.278426e-04 0.43
6 2.358202e+01 1.764206e-03 1.270072e-03 4.236324e-04 0.47
7 2.304355e+01 1.703461e-03 1.226341e-03 4.090461e-04 0.52
8 2.181656e+01 1.527846e-03 1.099914e-03 3.668761e-04 0.56
9 2.124914e+01 1.448597e-03 1.042861e-03 3.478463e-04 0.60
10 1.948615e+01 1.170737e-03 8.428266e-04 2.811248e-04 0.64
11 1.783054e+01 8.717316e-04 6.275695e-04 2.093258e-04 0.68
12 1.708765e+01 7.336925e-04 5.281936e-04 1.761789e-04 0.72
13 1.550449e+01 3.894897e-04 2.803981e-04 9.352676e-05 0.76
14 1.514484e+01 3.155406e-04 2.271613e-04 7.576962e-05 0.80
15 1.441642e+01 1.496860e-04 1.077607e-04 3.594357e-05 0.85
16 1.411738e+01 7.908921e-05 5.693722e-05 1.899141e-05 0.90
17 1.383348e+01 1.063875e-05 7.658959e-06 2.554645e-06 0.95
18 1.380209e+01 2.769706e-06 1.993947e-06 6.650794e-07 0.99
19 1.379178e+01 1.701668e-07 1.225354e-07 4.086155e-08 1.03
20 1.379114e+01 8.779631e-09 6.671732e-09 2.108221e-09 1.07
Optimal solution found.
poc =
1.8216e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.384156e-01 2.500000e-01 8.338731e-02 0.24
1 2.283493e+02 2.314639e-02 1.709909e-02 5.703387e-03 0.29
2 9.475565e+01 9.793019e-03 7.234463e-03 2.413050e-03 0.33
3 2.755188e+01 2.925713e-03 2.161331e-03 7.209104e-04 0.37
4 2.438422e+01 1.697792e-03 1.254221e-03 4.183445e-04 0.41
5 2.398865e+01 1.677057e-03 1.238903e-03 4.132353e-04 0.45
6 2.383017e+01 1.662889e-03 1.228437e-03 4.097444e-04 0.49
7 2.333142e+01 1.612151e-03 1.190955e-03 3.972422e-04 0.53
8 2.217540e+01 1.460099e-03 1.078629e-03 3.597758e-04 0.56
9 2.173362e+01 1.404707e-03 1.037709e-03 3.461270e-04 0.61
10 2.035602e+01 1.210646e-03 8.943487e-04 2.983093e-04 0.65
11 1.865148e+01 9.312689e-04 6.879625e-04 2.294694e-04 0.68
12 1.727485e+01 7.016610e-04 5.183427e-04 1.728928e-04 0.72
13 1.622825e+01 5.067634e-04 3.743647e-04 1.248691e-04 0.76
14 1.539423e+01 3.289696e-04 2.430219e-04 8.105977e-05 0.80
15 1.498430e+01 2.416941e-04 1.785483e-04 5.955466e-05 0.83
16 1.446995e+01 1.222391e-04 9.030248e-05 3.012032e-05 0.87
17 1.418069e+01 5.599477e-05 4.136539e-05 1.379739e-05 0.91
18 1.397083e+01 5.693174e-06 4.205758e-06 1.402827e-06 0.95
19 1.394958e+01 5.174181e-07 3.822538e-07 1.274944e-07 0.99
20 1.394766e+01 4.663196e-08 3.460641e-08 1.149035e-08 1.03
21 1.394748e+01 2.032849e-09 2.212183e-09 5.009042e-10 1.07
Optimal solution found.
poc =
1.0958e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.341137e-01 2.500000e-01 8.338698e-02 0.24
1 9.059917e+02 1.639868e-01 1.227028e-01 4.092728e-02 0.28
2 1.017406e+03 7.906474e-02 5.916006e-02 1.973271e-02 0.31
3 1.124331e+03 4.121461e-03 3.083876e-03 1.028620e-03 0.35
4 1.118894e+03 6.591392e-06 4.931998e-06 1.645058e-06 0.39
5 1.118894e+03 9.882157e-09 7.394312e-09 2.466356e-09 0.43
6 1.118894e+03 1.481584e-11 1.109217e-11 3.698267e-12 0.46
Problem is infeasible.
This was tested on R2025a and R2023a.I am running a trajectory optimisation problem.
The formulation is convexified via slack variables and linearisation and I was testing coneprog as solver.
I noticed some issues with the function that I would like to report and verify if it is my mistake or a bug.
My code is completely deterministic. There is no randomisation and the execution should be 100% reproducible.
Nevertheless, running the same code multiple times with the same input and options leads to different results.
Unlinke fmincon, with coneprog it is impossible to access internal calculation and to understand what is going on, therefore I do not have many insights.
My guess is that a random noise is applied to the initial guess.
In theory this should not be a problem since a convex problem has only one minimum.
In practice, the solver sometimes finds an optimal solution and other times declares the problem unfeasible.
I can solve the same exact problem with an NLP formulation using fmincon, so I know for sure the proble is solvable.
I tried to change the initial conditions and the problem persists.
Sometimes, different minima are found in different calls of the solver.
This is not due to the presence of a flat in the solution space because the fval differ by 1 to 2 orders of magnitude.
Another issue I am having is connected to the iterative procedure I have implemented.
At first I obtain an anlytical initial guess that is numerically propagated.
The constraints are linearised around this reference trajectory and the coneprog is called to solve the problem.
Once the optimal control is obtained, the solution is again propagated and if the error is not below the specified tolerance the process is repeated iteratively.
For some initial conditions the solver works smoothly, but for other it stops at the 5-th or 6-th iteration (declaring the problem unfeasible) when it is really close to the finalise the solution.
Again, it is important to highlight that I am 100% confident that the problem is feasible.
It is important to highlight that some degree of reproducibility is still present.
Even if the solver behaves differently, the number of possible behaviours is limited to just a few outcomes, depending on the initial conditions.
In general, for every problem there are 2 or 3 possible outcomes.
Moreover, some outcomes may occur more frequently than others.
I have spent days trying to find the issue in my code, but now, after testing with fmincon, I am starting to be confident that the problem is in coneprog.
I have also noticed that the solver behaves differently depending on the optimalityTolerance.
This was later confirmed when I found out that the problem has already been reported on this forum here.
An other bug I noticed in some solutions is that both Primal and Dual Feasibility report a value, but if I check manually the constraint satisfaction, the feasibility is off by several order of magnitudes.
I am 100% confident that the check I performed is correct because it was performed with a breakpoint placed right after the call to coneprog as shown below.
I have also stored the inputs of coneprog right before the function was called.
In my opinion, if the problem is coneprog as I think it is, the bug is related to the update step of the current guess.
Have you experienced similar problem with coneprog, or are you aware of some limitations it may have?
Did you already encountered such problem and understood where it is coming from?
The main motivations why I think coneprog is the problem are the different outputs produced from a deterministic code, and the fact that, when the problem converges, the solution is correct.
As a final comment, I think it would be really useful to have the freedom of specifying an initial guess.
If I know already a solution that is both an interior point and very close to the optimal one, this would cut down considerably the computational time.
—————————————————————————————————————————-
Below you can find an example of the solver converging to an unfeasible point after some iterations.
The target value of poc is 1e-10.
The formulation of the optimsiation problem is based on a direct transcription to discretise a continuous trajectory into discrete nodes.
The solution vector x is built as:
x = [ux1 uy1 uz1 u1 … uxN uyN uzN uN b1 b2]
where:
[uxi uyi uzi] is the control vector at the i-th node.
ui is the magnitude of the control vector at the i-th node.
[b1 b2] are some end conditions that must satisfy a linear constraint
The only cone constraints present are the one that impose:
sqrt(uxi^2 + uyi^2 + uzi^2) <= 1
sqrt(uxi^2 + uyi^2 + uzi^2) <= ui
The linear objective function minimises the control effort defined as:
In the example below, the trajectory is discretised into 852 nodes.
This is clear from the initial Fval of every iteration that corresponds to the number of nodes, as the initial guess is probably all ones.
The last call of coneprog declares the problem unfeasible and it is the only iteration where Fval increases after the initial guess.
The problem with the constraint satisfication can be understood from the values of the Infeasibilities.
To help the problem converges I defined a lower bound to uxi, uyi, and uzi of -1, and a lower bound to ui of 0.
Similarly, I defined an upper bound to uxi, uyi, uzi, and ui of 1.
An Fval of 1.118894e+03 in the last line of the example below, clearly goes against the upper bound constraint, as the maximum value of Fval allowed by the upper bound is 852.
Instead the sovler is analysing a solution with Fval of approximately 1119, but it thinks that the constraints are satisfied, which is impossible.
Maybe my interpretation of Primal and Dual Feasibility is wrong, but my intuition is suggesting me that coneprog may have some problems.
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.351509e-01 2.500000e-01 8.338790e-02 0.43
1 2.903535e+02 5.653968e-02 4.217479e-02 1.406747e-02 0.46
2 5.760140e+01 1.155766e-02 8.621236e-03 2.875627e-03 0.50
3 1.826360e+01 3.567321e-03 2.660981e-03 8.875744e-04 0.54
4 1.587390e+01 2.115580e-03 1.578080e-03 5.263711e-04 0.58
5 1.496351e+01 1.979895e-03 1.476868e-03 4.926117e-04 0.61
6 1.477297e+01 1.930240e-03 1.439829e-03 4.802573e-04 0.65
7 1.407791e+01 1.740965e-03 1.298643e-03 4.331644e-04 0.69
8 1.195150e+01 1.139652e-03 8.501032e-04 2.835533e-04 0.73
9 1.118074e+01 9.249616e-04 6.899590e-04 2.301369e-04 0.76
10 9.263514e+00 3.932808e-04 2.933610e-04 9.785102e-05 0.80
11 8.435984e+00 1.662211e-04 1.239898e-04 4.135699e-05 0.84
12 8.137082e+00 8.259246e-05 6.160841e-05 2.054958e-05 0.89
13 7.834045e+00 4.811473e-06 3.589036e-06 1.197128e-06 0.93
14 7.817072e+00 4.211285e-07 3.141435e-07 1.047797e-07 0.97
15 7.815469e+00 1.297491e-08 9.741467e-09 3.228250e-09 1.02
16 7.815429e+00 2.773558e-09 3.724366e-09 6.900807e-10 1.05
Optimal solution found.
poc =
4.7669e-05
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 4.148309e-01 2.500000e-01 8.339003e-02 0.24
1 2.936365e+02 7.220152e-02 4.351262e-02 1.451408e-02 0.28
2 3.227398e+01 9.133979e-03 5.504640e-03 1.836128e-03 0.32
3 2.999204e+01 5.626122e-03 3.390612e-03 1.130973e-03 0.36
4 2.891739e+01 5.422358e-03 3.267812e-03 1.090012e-03 0.40
5 2.734221e+01 4.962369e-03 2.990597e-03 9.975440e-04 0.44
6 2.355320e+01 3.776002e-03 2.275627e-03 7.590585e-04 0.48
7 1.765904e+01 1.858229e-03 1.119871e-03 3.735444e-04 0.53
8 1.493406e+01 9.914144e-04 5.974810e-04 1.992958e-04 0.57
9 1.321215e+01 4.284890e-04 2.582311e-04 8.613560e-05 0.61
10 1.247209e+01 1.862607e-04 1.122510e-04 3.744245e-05 0.65
11 1.203916e+01 4.726695e-05 2.848568e-05 9.501685e-06 0.68
12 1.190390e+01 4.898257e-06 2.951962e-06 9.846561e-07 0.73
13 1.188906e+01 1.900382e-07 1.145391e-07 3.820181e-08 0.77
14 1.188847e+01 9.042867e-09 5.942560e-09 1.817813e-09 0.81
Optimal solution found.
poc =
1.7472e-08
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.740554e-01 2.500000e-01 8.338857e-02 0.23
1 2.549188e+02 4.172979e-02 2.789011e-02 9.302867e-03 0.26
2 9.392526e+01 1.561744e-02 1.043792e-02 3.481612e-03 0.30
3 2.667086e+01 4.410425e-03 2.947708e-03 9.832206e-04 0.34
4 2.407913e+01 2.549053e-03 1.703660e-03 5.682632e-04 0.39
5 2.355160e+01 2.499060e-03 1.670247e-03 5.571180e-04 0.43
6 2.324912e+01 2.449195e-03 1.636919e-03 5.460015e-04 0.47
7 2.249923e+01 2.308274e-03 1.542735e-03 5.145858e-04 0.50
8 2.040632e+01 1.851989e-03 1.237777e-03 4.128657e-04 0.54
9 1.970151e+01 1.692941e-03 1.131477e-03 3.774090e-04 0.59
10 1.744126e+01 1.126199e-03 7.526951e-04 2.510647e-04 0.62
11 1.620420e+01 8.023922e-04 5.362790e-04 1.788781e-04 0.66
12 1.474391e+01 3.945190e-04 2.636768e-04 8.795053e-05 0.70
13 1.427557e+01 2.644519e-04 1.767465e-04 5.895455e-05 0.73
14 1.370019e+01 1.011430e-04 6.759892e-05 2.254791e-05 0.77
15 1.348178e+01 3.984925e-05 2.663325e-05 8.883635e-06 0.81
16 1.336507e+01 7.537767e-06 5.037870e-06 1.680402e-06 0.85
17 1.334002e+01 6.477134e-07 4.329037e-07 1.443954e-07 0.88
18 1.333772e+01 1.179424e-08 7.999240e-09 2.629302e-09 0.93
19 1.333768e+01 1.381986e-10 8.290199e-09 3.080877e-11 0.99
Optimal solution found.
poc =
5.3035e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.472650e-01 2.500000e-01 8.338749e-02 0.23
1 2.309201e+02 2.520373e-02 1.814445e-02 6.052081e-03 0.27
2 9.405942e+01 1.047608e-02 7.541850e-03 2.515584e-03 0.31
3 2.721726e+01 3.116075e-03 2.243298e-03 7.482520e-04 0.35
4 2.416710e+01 1.805118e-03 1.299525e-03 4.334564e-04 0.40
5 2.375956e+01 1.781739e-03 1.282694e-03 4.278426e-04 0.43
6 2.358202e+01 1.764206e-03 1.270072e-03 4.236324e-04 0.47
7 2.304355e+01 1.703461e-03 1.226341e-03 4.090461e-04 0.52
8 2.181656e+01 1.527846e-03 1.099914e-03 3.668761e-04 0.56
9 2.124914e+01 1.448597e-03 1.042861e-03 3.478463e-04 0.60
10 1.948615e+01 1.170737e-03 8.428266e-04 2.811248e-04 0.64
11 1.783054e+01 8.717316e-04 6.275695e-04 2.093258e-04 0.68
12 1.708765e+01 7.336925e-04 5.281936e-04 1.761789e-04 0.72
13 1.550449e+01 3.894897e-04 2.803981e-04 9.352676e-05 0.76
14 1.514484e+01 3.155406e-04 2.271613e-04 7.576962e-05 0.80
15 1.441642e+01 1.496860e-04 1.077607e-04 3.594357e-05 0.85
16 1.411738e+01 7.908921e-05 5.693722e-05 1.899141e-05 0.90
17 1.383348e+01 1.063875e-05 7.658959e-06 2.554645e-06 0.95
18 1.380209e+01 2.769706e-06 1.993947e-06 6.650794e-07 0.99
19 1.379178e+01 1.701668e-07 1.225354e-07 4.086155e-08 1.03
20 1.379114e+01 8.779631e-09 6.671732e-09 2.108221e-09 1.07
Optimal solution found.
poc =
1.8216e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.384156e-01 2.500000e-01 8.338731e-02 0.24
1 2.283493e+02 2.314639e-02 1.709909e-02 5.703387e-03 0.29
2 9.475565e+01 9.793019e-03 7.234463e-03 2.413050e-03 0.33
3 2.755188e+01 2.925713e-03 2.161331e-03 7.209104e-04 0.37
4 2.438422e+01 1.697792e-03 1.254221e-03 4.183445e-04 0.41
5 2.398865e+01 1.677057e-03 1.238903e-03 4.132353e-04 0.45
6 2.383017e+01 1.662889e-03 1.228437e-03 4.097444e-04 0.49
7 2.333142e+01 1.612151e-03 1.190955e-03 3.972422e-04 0.53
8 2.217540e+01 1.460099e-03 1.078629e-03 3.597758e-04 0.56
9 2.173362e+01 1.404707e-03 1.037709e-03 3.461270e-04 0.61
10 2.035602e+01 1.210646e-03 8.943487e-04 2.983093e-04 0.65
11 1.865148e+01 9.312689e-04 6.879625e-04 2.294694e-04 0.68
12 1.727485e+01 7.016610e-04 5.183427e-04 1.728928e-04 0.72
13 1.622825e+01 5.067634e-04 3.743647e-04 1.248691e-04 0.76
14 1.539423e+01 3.289696e-04 2.430219e-04 8.105977e-05 0.80
15 1.498430e+01 2.416941e-04 1.785483e-04 5.955466e-05 0.83
16 1.446995e+01 1.222391e-04 9.030248e-05 3.012032e-05 0.87
17 1.418069e+01 5.599477e-05 4.136539e-05 1.379739e-05 0.91
18 1.397083e+01 5.693174e-06 4.205758e-06 1.402827e-06 0.95
19 1.394958e+01 5.174181e-07 3.822538e-07 1.274944e-07 0.99
20 1.394766e+01 4.663196e-08 3.460641e-08 1.149035e-08 1.03
21 1.394748e+01 2.032849e-09 2.212183e-09 5.009042e-10 1.07
Optimal solution found.
poc =
1.0958e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.341137e-01 2.500000e-01 8.338698e-02 0.24
1 9.059917e+02 1.639868e-01 1.227028e-01 4.092728e-02 0.28
2 1.017406e+03 7.906474e-02 5.916006e-02 1.973271e-02 0.31
3 1.124331e+03 4.121461e-03 3.083876e-03 1.028620e-03 0.35
4 1.118894e+03 6.591392e-06 4.931998e-06 1.645058e-06 0.39
5 1.118894e+03 9.882157e-09 7.394312e-09 2.466356e-09 0.43
6 1.118894e+03 1.481584e-11 1.109217e-11 3.698267e-12 0.46
Problem is infeasible.
This was tested on R2025a and R2023a. I am running a trajectory optimisation problem.
The formulation is convexified via slack variables and linearisation and I was testing coneprog as solver.
I noticed some issues with the function that I would like to report and verify if it is my mistake or a bug.
My code is completely deterministic. There is no randomisation and the execution should be 100% reproducible.
Nevertheless, running the same code multiple times with the same input and options leads to different results.
Unlinke fmincon, with coneprog it is impossible to access internal calculation and to understand what is going on, therefore I do not have many insights.
My guess is that a random noise is applied to the initial guess.
In theory this should not be a problem since a convex problem has only one minimum.
In practice, the solver sometimes finds an optimal solution and other times declares the problem unfeasible.
I can solve the same exact problem with an NLP formulation using fmincon, so I know for sure the proble is solvable.
I tried to change the initial conditions and the problem persists.
Sometimes, different minima are found in different calls of the solver.
This is not due to the presence of a flat in the solution space because the fval differ by 1 to 2 orders of magnitude.
Another issue I am having is connected to the iterative procedure I have implemented.
At first I obtain an anlytical initial guess that is numerically propagated.
The constraints are linearised around this reference trajectory and the coneprog is called to solve the problem.
Once the optimal control is obtained, the solution is again propagated and if the error is not below the specified tolerance the process is repeated iteratively.
For some initial conditions the solver works smoothly, but for other it stops at the 5-th or 6-th iteration (declaring the problem unfeasible) when it is really close to the finalise the solution.
Again, it is important to highlight that I am 100% confident that the problem is feasible.
It is important to highlight that some degree of reproducibility is still present.
Even if the solver behaves differently, the number of possible behaviours is limited to just a few outcomes, depending on the initial conditions.
In general, for every problem there are 2 or 3 possible outcomes.
Moreover, some outcomes may occur more frequently than others.
I have spent days trying to find the issue in my code, but now, after testing with fmincon, I am starting to be confident that the problem is in coneprog.
I have also noticed that the solver behaves differently depending on the optimalityTolerance.
This was later confirmed when I found out that the problem has already been reported on this forum here.
An other bug I noticed in some solutions is that both Primal and Dual Feasibility report a value, but if I check manually the constraint satisfaction, the feasibility is off by several order of magnitudes.
I am 100% confident that the check I performed is correct because it was performed with a breakpoint placed right after the call to coneprog as shown below.
I have also stored the inputs of coneprog right before the function was called.
In my opinion, if the problem is coneprog as I think it is, the bug is related to the update step of the current guess.
Have you experienced similar problem with coneprog, or are you aware of some limitations it may have?
Did you already encountered such problem and understood where it is coming from?
The main motivations why I think coneprog is the problem are the different outputs produced from a deterministic code, and the fact that, when the problem converges, the solution is correct.
As a final comment, I think it would be really useful to have the freedom of specifying an initial guess.
If I know already a solution that is both an interior point and very close to the optimal one, this would cut down considerably the computational time.
—————————————————————————————————————————-
Below you can find an example of the solver converging to an unfeasible point after some iterations.
The target value of poc is 1e-10.
The formulation of the optimsiation problem is based on a direct transcription to discretise a continuous trajectory into discrete nodes.
The solution vector x is built as:
x = [ux1 uy1 uz1 u1 … uxN uyN uzN uN b1 b2]
where:
[uxi uyi uzi] is the control vector at the i-th node.
ui is the magnitude of the control vector at the i-th node.
[b1 b2] are some end conditions that must satisfy a linear constraint
The only cone constraints present are the one that impose:
sqrt(uxi^2 + uyi^2 + uzi^2) <= 1
sqrt(uxi^2 + uyi^2 + uzi^2) <= ui
The linear objective function minimises the control effort defined as:
In the example below, the trajectory is discretised into 852 nodes.
This is clear from the initial Fval of every iteration that corresponds to the number of nodes, as the initial guess is probably all ones.
The last call of coneprog declares the problem unfeasible and it is the only iteration where Fval increases after the initial guess.
The problem with the constraint satisfication can be understood from the values of the Infeasibilities.
To help the problem converges I defined a lower bound to uxi, uyi, and uzi of -1, and a lower bound to ui of 0.
Similarly, I defined an upper bound to uxi, uyi, uzi, and ui of 1.
An Fval of 1.118894e+03 in the last line of the example below, clearly goes against the upper bound constraint, as the maximum value of Fval allowed by the upper bound is 852.
Instead the sovler is analysing a solution with Fval of approximately 1119, but it thinks that the constraints are satisfied, which is impossible.
Maybe my interpretation of Primal and Dual Feasibility is wrong, but my intuition is suggesting me that coneprog may have some problems.
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.351509e-01 2.500000e-01 8.338790e-02 0.43
1 2.903535e+02 5.653968e-02 4.217479e-02 1.406747e-02 0.46
2 5.760140e+01 1.155766e-02 8.621236e-03 2.875627e-03 0.50
3 1.826360e+01 3.567321e-03 2.660981e-03 8.875744e-04 0.54
4 1.587390e+01 2.115580e-03 1.578080e-03 5.263711e-04 0.58
5 1.496351e+01 1.979895e-03 1.476868e-03 4.926117e-04 0.61
6 1.477297e+01 1.930240e-03 1.439829e-03 4.802573e-04 0.65
7 1.407791e+01 1.740965e-03 1.298643e-03 4.331644e-04 0.69
8 1.195150e+01 1.139652e-03 8.501032e-04 2.835533e-04 0.73
9 1.118074e+01 9.249616e-04 6.899590e-04 2.301369e-04 0.76
10 9.263514e+00 3.932808e-04 2.933610e-04 9.785102e-05 0.80
11 8.435984e+00 1.662211e-04 1.239898e-04 4.135699e-05 0.84
12 8.137082e+00 8.259246e-05 6.160841e-05 2.054958e-05 0.89
13 7.834045e+00 4.811473e-06 3.589036e-06 1.197128e-06 0.93
14 7.817072e+00 4.211285e-07 3.141435e-07 1.047797e-07 0.97
15 7.815469e+00 1.297491e-08 9.741467e-09 3.228250e-09 1.02
16 7.815429e+00 2.773558e-09 3.724366e-09 6.900807e-10 1.05
Optimal solution found.
poc =
4.7669e-05
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 4.148309e-01 2.500000e-01 8.339003e-02 0.24
1 2.936365e+02 7.220152e-02 4.351262e-02 1.451408e-02 0.28
2 3.227398e+01 9.133979e-03 5.504640e-03 1.836128e-03 0.32
3 2.999204e+01 5.626122e-03 3.390612e-03 1.130973e-03 0.36
4 2.891739e+01 5.422358e-03 3.267812e-03 1.090012e-03 0.40
5 2.734221e+01 4.962369e-03 2.990597e-03 9.975440e-04 0.44
6 2.355320e+01 3.776002e-03 2.275627e-03 7.590585e-04 0.48
7 1.765904e+01 1.858229e-03 1.119871e-03 3.735444e-04 0.53
8 1.493406e+01 9.914144e-04 5.974810e-04 1.992958e-04 0.57
9 1.321215e+01 4.284890e-04 2.582311e-04 8.613560e-05 0.61
10 1.247209e+01 1.862607e-04 1.122510e-04 3.744245e-05 0.65
11 1.203916e+01 4.726695e-05 2.848568e-05 9.501685e-06 0.68
12 1.190390e+01 4.898257e-06 2.951962e-06 9.846561e-07 0.73
13 1.188906e+01 1.900382e-07 1.145391e-07 3.820181e-08 0.77
14 1.188847e+01 9.042867e-09 5.942560e-09 1.817813e-09 0.81
Optimal solution found.
poc =
1.7472e-08
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.740554e-01 2.500000e-01 8.338857e-02 0.23
1 2.549188e+02 4.172979e-02 2.789011e-02 9.302867e-03 0.26
2 9.392526e+01 1.561744e-02 1.043792e-02 3.481612e-03 0.30
3 2.667086e+01 4.410425e-03 2.947708e-03 9.832206e-04 0.34
4 2.407913e+01 2.549053e-03 1.703660e-03 5.682632e-04 0.39
5 2.355160e+01 2.499060e-03 1.670247e-03 5.571180e-04 0.43
6 2.324912e+01 2.449195e-03 1.636919e-03 5.460015e-04 0.47
7 2.249923e+01 2.308274e-03 1.542735e-03 5.145858e-04 0.50
8 2.040632e+01 1.851989e-03 1.237777e-03 4.128657e-04 0.54
9 1.970151e+01 1.692941e-03 1.131477e-03 3.774090e-04 0.59
10 1.744126e+01 1.126199e-03 7.526951e-04 2.510647e-04 0.62
11 1.620420e+01 8.023922e-04 5.362790e-04 1.788781e-04 0.66
12 1.474391e+01 3.945190e-04 2.636768e-04 8.795053e-05 0.70
13 1.427557e+01 2.644519e-04 1.767465e-04 5.895455e-05 0.73
14 1.370019e+01 1.011430e-04 6.759892e-05 2.254791e-05 0.77
15 1.348178e+01 3.984925e-05 2.663325e-05 8.883635e-06 0.81
16 1.336507e+01 7.537767e-06 5.037870e-06 1.680402e-06 0.85
17 1.334002e+01 6.477134e-07 4.329037e-07 1.443954e-07 0.88
18 1.333772e+01 1.179424e-08 7.999240e-09 2.629302e-09 0.93
19 1.333768e+01 1.381986e-10 8.290199e-09 3.080877e-11 0.99
Optimal solution found.
poc =
5.3035e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.472650e-01 2.500000e-01 8.338749e-02 0.23
1 2.309201e+02 2.520373e-02 1.814445e-02 6.052081e-03 0.27
2 9.405942e+01 1.047608e-02 7.541850e-03 2.515584e-03 0.31
3 2.721726e+01 3.116075e-03 2.243298e-03 7.482520e-04 0.35
4 2.416710e+01 1.805118e-03 1.299525e-03 4.334564e-04 0.40
5 2.375956e+01 1.781739e-03 1.282694e-03 4.278426e-04 0.43
6 2.358202e+01 1.764206e-03 1.270072e-03 4.236324e-04 0.47
7 2.304355e+01 1.703461e-03 1.226341e-03 4.090461e-04 0.52
8 2.181656e+01 1.527846e-03 1.099914e-03 3.668761e-04 0.56
9 2.124914e+01 1.448597e-03 1.042861e-03 3.478463e-04 0.60
10 1.948615e+01 1.170737e-03 8.428266e-04 2.811248e-04 0.64
11 1.783054e+01 8.717316e-04 6.275695e-04 2.093258e-04 0.68
12 1.708765e+01 7.336925e-04 5.281936e-04 1.761789e-04 0.72
13 1.550449e+01 3.894897e-04 2.803981e-04 9.352676e-05 0.76
14 1.514484e+01 3.155406e-04 2.271613e-04 7.576962e-05 0.80
15 1.441642e+01 1.496860e-04 1.077607e-04 3.594357e-05 0.85
16 1.411738e+01 7.908921e-05 5.693722e-05 1.899141e-05 0.90
17 1.383348e+01 1.063875e-05 7.658959e-06 2.554645e-06 0.95
18 1.380209e+01 2.769706e-06 1.993947e-06 6.650794e-07 0.99
19 1.379178e+01 1.701668e-07 1.225354e-07 4.086155e-08 1.03
20 1.379114e+01 8.779631e-09 6.671732e-09 2.108221e-09 1.07
Optimal solution found.
poc =
1.8216e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.384156e-01 2.500000e-01 8.338731e-02 0.24
1 2.283493e+02 2.314639e-02 1.709909e-02 5.703387e-03 0.29
2 9.475565e+01 9.793019e-03 7.234463e-03 2.413050e-03 0.33
3 2.755188e+01 2.925713e-03 2.161331e-03 7.209104e-04 0.37
4 2.438422e+01 1.697792e-03 1.254221e-03 4.183445e-04 0.41
5 2.398865e+01 1.677057e-03 1.238903e-03 4.132353e-04 0.45
6 2.383017e+01 1.662889e-03 1.228437e-03 4.097444e-04 0.49
7 2.333142e+01 1.612151e-03 1.190955e-03 3.972422e-04 0.53
8 2.217540e+01 1.460099e-03 1.078629e-03 3.597758e-04 0.56
9 2.173362e+01 1.404707e-03 1.037709e-03 3.461270e-04 0.61
10 2.035602e+01 1.210646e-03 8.943487e-04 2.983093e-04 0.65
11 1.865148e+01 9.312689e-04 6.879625e-04 2.294694e-04 0.68
12 1.727485e+01 7.016610e-04 5.183427e-04 1.728928e-04 0.72
13 1.622825e+01 5.067634e-04 3.743647e-04 1.248691e-04 0.76
14 1.539423e+01 3.289696e-04 2.430219e-04 8.105977e-05 0.80
15 1.498430e+01 2.416941e-04 1.785483e-04 5.955466e-05 0.83
16 1.446995e+01 1.222391e-04 9.030248e-05 3.012032e-05 0.87
17 1.418069e+01 5.599477e-05 4.136539e-05 1.379739e-05 0.91
18 1.397083e+01 5.693174e-06 4.205758e-06 1.402827e-06 0.95
19 1.394958e+01 5.174181e-07 3.822538e-07 1.274944e-07 0.99
20 1.394766e+01 4.663196e-08 3.460641e-08 1.149035e-08 1.03
21 1.394748e+01 2.032849e-09 2.212183e-09 5.009042e-10 1.07
Optimal solution found.
poc =
1.0958e-10
Iter Fval Primal Infeas Dual Infeas Duality Gap Time
0 8.520000e+02 3.341137e-01 2.500000e-01 8.338698e-02 0.24
1 9.059917e+02 1.639868e-01 1.227028e-01 4.092728e-02 0.28
2 1.017406e+03 7.906474e-02 5.916006e-02 1.973271e-02 0.31
3 1.124331e+03 4.121461e-03 3.083876e-03 1.028620e-03 0.35
4 1.118894e+03 6.591392e-06 4.931998e-06 1.645058e-06 0.39
5 1.118894e+03 9.882157e-09 7.394312e-09 2.466356e-09 0.43
6 1.118894e+03 1.481584e-11 1.109217e-11 3.698267e-12 0.46
Problem is infeasible.
This was tested on R2025a and R2023a. coneprog, bug MATLAB Answers — New Questions
SIMULINK launching Logic Analyzer causes memory leak
Hi all,
I have built a testbench in SIMULINK 2024b usaing the vision HDL toolbox for streaming in video from a test file (.avi) passing through a DUT and then displaying video using the video viewer.
When I try to run a simulation where I stream out 3 of my 1280×1024 8bit pixles from the file (by setting stop time to 36ms), convert to a pixel stream, convert back to a frame and view the video, it works! However, when I try to open the logic analyser to view my 6 logged signals after (or have it open before and run the simulation) MATLAB completely halts, and i have to force quit from the task manager.
From the task manager I can see the Memory consumed by MATLAB rise continually as if there is a memory leak. What is going on here?
Update:
I have removed more and more blocks in my design and have tracked the problem down i believe to the pixels to frame block
Above is a heavily simplified version of my design I/O. Video loaded in from file, converted to pixel stream, then back to a frame and into a display. However Running simulation crashes my matlab – but not immediately:
I open the design and configure my stop time to be equivalent to three frames worth, then I open the logic analyzer to view my logged signals. Then I commence the simulation. The 3 frames appear correctly in the video viewer, but my logged signals do not appear. Then a swirly Icon appears on my logic analyzer and there is a massive surge in memory usage from MATLAB (~20GB). I have to force quit the application.
Note: when I comment out the pixels to frame and video viewer, the logic analyser works completely fine for reading data out of the frame to pixels block
What is going on?Hi all,
I have built a testbench in SIMULINK 2024b usaing the vision HDL toolbox for streaming in video from a test file (.avi) passing through a DUT and then displaying video using the video viewer.
When I try to run a simulation where I stream out 3 of my 1280×1024 8bit pixles from the file (by setting stop time to 36ms), convert to a pixel stream, convert back to a frame and view the video, it works! However, when I try to open the logic analyser to view my 6 logged signals after (or have it open before and run the simulation) MATLAB completely halts, and i have to force quit from the task manager.
From the task manager I can see the Memory consumed by MATLAB rise continually as if there is a memory leak. What is going on here?
Update:
I have removed more and more blocks in my design and have tracked the problem down i believe to the pixels to frame block
Above is a heavily simplified version of my design I/O. Video loaded in from file, converted to pixel stream, then back to a frame and into a display. However Running simulation crashes my matlab – but not immediately:
I open the design and configure my stop time to be equivalent to three frames worth, then I open the logic analyzer to view my logged signals. Then I commence the simulation. The 3 frames appear correctly in the video viewer, but my logged signals do not appear. Then a swirly Icon appears on my logic analyzer and there is a massive surge in memory usage from MATLAB (~20GB). I have to force quit the application.
Note: when I comment out the pixels to frame and video viewer, the logic analyser works completely fine for reading data out of the frame to pixels block
What is going on? Hi all,
I have built a testbench in SIMULINK 2024b usaing the vision HDL toolbox for streaming in video from a test file (.avi) passing through a DUT and then displaying video using the video viewer.
When I try to run a simulation where I stream out 3 of my 1280×1024 8bit pixles from the file (by setting stop time to 36ms), convert to a pixel stream, convert back to a frame and view the video, it works! However, when I try to open the logic analyser to view my 6 logged signals after (or have it open before and run the simulation) MATLAB completely halts, and i have to force quit from the task manager.
From the task manager I can see the Memory consumed by MATLAB rise continually as if there is a memory leak. What is going on here?
Update:
I have removed more and more blocks in my design and have tracked the problem down i believe to the pixels to frame block
Above is a heavily simplified version of my design I/O. Video loaded in from file, converted to pixel stream, then back to a frame and into a display. However Running simulation crashes my matlab – but not immediately:
I open the design and configure my stop time to be equivalent to three frames worth, then I open the logic analyzer to view my logged signals. Then I commence the simulation. The 3 frames appear correctly in the video viewer, but my logged signals do not appear. Then a swirly Icon appears on my logic analyzer and there is a massive surge in memory usage from MATLAB (~20GB). I have to force quit the application.
Note: when I comment out the pixels to frame and video viewer, the logic analyser works completely fine for reading data out of the frame to pixels block
What is going on? computer vision, image processing, simulink, video MATLAB Answers — New Questions
polar/plot incompatibility
Can any one explain the design choise that causes this:
polarscatter(linspace(0,pi*2/3,100).^2,…
linspace(0,pi*2/3,100),…
32,…
linspace(0,pi*2/3,100),’filled’)
hold on
plot([-1 1],[1 -1],’m’)
Error using newplot
Adding Cartesian plot to polaraxes is not supported.
Error in matlab.graphics.internal.newplotwrapper (line 11)
axReturn = newplot(varargin{:});
From my perspective picking polar/cartesian representation of my grid is just that – a choise of either cartesian grid-lines of polar grid-lines. Why should it not be possible to add objects with cartesian coordinates to a region with polar grid-lines or the other way around?Can any one explain the design choise that causes this:
polarscatter(linspace(0,pi*2/3,100).^2,…
linspace(0,pi*2/3,100),…
32,…
linspace(0,pi*2/3,100),’filled’)
hold on
plot([-1 1],[1 -1],’m’)
Error using newplot
Adding Cartesian plot to polaraxes is not supported.
Error in matlab.graphics.internal.newplotwrapper (line 11)
axReturn = newplot(varargin{:});
From my perspective picking polar/cartesian representation of my grid is just that – a choise of either cartesian grid-lines of polar grid-lines. Why should it not be possible to add objects with cartesian coordinates to a region with polar grid-lines or the other way around? Can any one explain the design choise that causes this:
polarscatter(linspace(0,pi*2/3,100).^2,…
linspace(0,pi*2/3,100),…
32,…
linspace(0,pi*2/3,100),’filled’)
hold on
plot([-1 1],[1 -1],’m’)
Error using newplot
Adding Cartesian plot to polaraxes is not supported.
Error in matlab.graphics.internal.newplotwrapper (line 11)
axReturn = newplot(varargin{:});
From my perspective picking polar/cartesian representation of my grid is just that – a choise of either cartesian grid-lines of polar grid-lines. Why should it not be possible to add objects with cartesian coordinates to a region with polar grid-lines or the other way around? polar plot MATLAB Answers — New Questions
Issue Saving image with text overlay to png
I am having issues saving an image that has been displayed in a figure, with a couple markers plotted at specific coordinates and then text overlaid using the text function. I am trying to safe this off as a png via saveas(gcf,’filename.png’); and the figure exports but the overlaid text is missing. The title and the marker points I plotted show up but no text. Below is the figure.
Attached is the exported png using saveas
My code looks as follows:
figure; imshow(img,[]);
hold on;
plot(Stats(TestNum).Centroid(1),Stats(TestNum).Centroid(2),’b*’);
set(gca, ‘ActivePositionProperty’, ‘OuterPosition’);
[filepath,name,ext] = fileparts(files(TestNum).name);
title({[];name;[‘Original Image With Centroid Marked’]},’FontSize’,FontSize);
text(20,500,{[‘Area = ‘,num2str(Stats(TestNum).Area.*pixel_scale^2,’%3.2f’),’mm^2′];…
[‘Eccentricity = ‘,num2str(Stats(TestNum).Eccentricity,’%3.2f’)];…
[‘Orientation = ‘,num2str(Stats(TestNum).Orientation,’%3.2f’),char(176)];…
[‘Major Axis Length = ‘,num2str(Stats(TestNum).MajorAxisLength.*pixel_scale,’%3.2f’),’mm’];…
[‘Minor Axis Length = ‘,num2str(Stats(TestNum).MinorAxisLength.*pixel_scale,’%3.2f’),’mm’]},…
‘Color’,’white’,’FontSize’,FontSize);
saveas(gcf,[pwd ‘outputTest ‘,num2str(TestNum),’TubeMidpointCrossSection – Test ‘,num2str(TestNum),’.png’]);I am having issues saving an image that has been displayed in a figure, with a couple markers plotted at specific coordinates and then text overlaid using the text function. I am trying to safe this off as a png via saveas(gcf,’filename.png’); and the figure exports but the overlaid text is missing. The title and the marker points I plotted show up but no text. Below is the figure.
Attached is the exported png using saveas
My code looks as follows:
figure; imshow(img,[]);
hold on;
plot(Stats(TestNum).Centroid(1),Stats(TestNum).Centroid(2),’b*’);
set(gca, ‘ActivePositionProperty’, ‘OuterPosition’);
[filepath,name,ext] = fileparts(files(TestNum).name);
title({[];name;[‘Original Image With Centroid Marked’]},’FontSize’,FontSize);
text(20,500,{[‘Area = ‘,num2str(Stats(TestNum).Area.*pixel_scale^2,’%3.2f’),’mm^2′];…
[‘Eccentricity = ‘,num2str(Stats(TestNum).Eccentricity,’%3.2f’)];…
[‘Orientation = ‘,num2str(Stats(TestNum).Orientation,’%3.2f’),char(176)];…
[‘Major Axis Length = ‘,num2str(Stats(TestNum).MajorAxisLength.*pixel_scale,’%3.2f’),’mm’];…
[‘Minor Axis Length = ‘,num2str(Stats(TestNum).MinorAxisLength.*pixel_scale,’%3.2f’),’mm’]},…
‘Color’,’white’,’FontSize’,FontSize);
saveas(gcf,[pwd ‘outputTest ‘,num2str(TestNum),’TubeMidpointCrossSection – Test ‘,num2str(TestNum),’.png’]); I am having issues saving an image that has been displayed in a figure, with a couple markers plotted at specific coordinates and then text overlaid using the text function. I am trying to safe this off as a png via saveas(gcf,’filename.png’); and the figure exports but the overlaid text is missing. The title and the marker points I plotted show up but no text. Below is the figure.
Attached is the exported png using saveas
My code looks as follows:
figure; imshow(img,[]);
hold on;
plot(Stats(TestNum).Centroid(1),Stats(TestNum).Centroid(2),’b*’);
set(gca, ‘ActivePositionProperty’, ‘OuterPosition’);
[filepath,name,ext] = fileparts(files(TestNum).name);
title({[];name;[‘Original Image With Centroid Marked’]},’FontSize’,FontSize);
text(20,500,{[‘Area = ‘,num2str(Stats(TestNum).Area.*pixel_scale^2,’%3.2f’),’mm^2′];…
[‘Eccentricity = ‘,num2str(Stats(TestNum).Eccentricity,’%3.2f’)];…
[‘Orientation = ‘,num2str(Stats(TestNum).Orientation,’%3.2f’),char(176)];…
[‘Major Axis Length = ‘,num2str(Stats(TestNum).MajorAxisLength.*pixel_scale,’%3.2f’),’mm’];…
[‘Minor Axis Length = ‘,num2str(Stats(TestNum).MinorAxisLength.*pixel_scale,’%3.2f’),’mm’]},…
‘Color’,’white’,’FontSize’,FontSize);
saveas(gcf,[pwd ‘outputTest ‘,num2str(TestNum),’TubeMidpointCrossSection – Test ‘,num2str(TestNum),’.png’]); saveas, text, png file, figure, overlaid text MATLAB Answers — New Questions
Monitor losses in MOSFET in SimScape
Using the Simscape probe, I can observe the latest turn-on and turn-off switching losses during the simulation. Do these values include both MOSFET and body-diode losses, or can body-diode (reverse-recovery) losses be monitored separately so that the probe’s losses correspond exclusively to the MOSFET?Using the Simscape probe, I can observe the latest turn-on and turn-off switching losses during the simulation. Do these values include both MOSFET and body-diode losses, or can body-diode (reverse-recovery) losses be monitored separately so that the probe’s losses correspond exclusively to the MOSFET? Using the Simscape probe, I can observe the latest turn-on and turn-off switching losses during the simulation. Do these values include both MOSFET and body-diode losses, or can body-diode (reverse-recovery) losses be monitored separately so that the probe’s losses correspond exclusively to the MOSFET? power losses in mosfet simscape MATLAB Answers — New Questions
Editing the format of a chart title in excel through actxserver
I have been trying to work out how to underscore a section of a chart title string in an existing chart in excel through actxserver. I would typically use invoke to format strings in excel cells, but I can’t use that approach in chart titles.
In the code below I am replacing a section of the title string, which has a portion already underscored. This automically underscoes the whole title for some reason, which I then remove and try to underscore just the section that was already underscored.
If anyone has a solution it would be much appreciated. I have tried different LLMs, but this is the method they suggest. Which should work based on excel VBA. Possibly this is just not supported in Matlab?
Example of editing characters in a chart title that doesn’t work.
excel = actxserver(‘Excel.Application’);
file = excel.Workbooks.Open("ABC.xlsx");
Sheet = excel.Worksheets.Item(‘ABC’);
ChartObjects = Sheet.ChartObjects;
chart = ChartObjects.Item(1).Chart; % Selecting chart
s = chart.ChartTitle.Text; % find current chart title
chart.ChartTitle.Text = strrep(s, OldWord, NewWord); % Replace key word in chart title
chart.ChartTitle.Characters.Font.Underline = 0; % Removing all underscored characters
pos = strfind(s, ‘-‘); % finding end of region to underline
% Works up to this last line
chart.ChartTitle.Characters(1, pos(1)-2).Font.Underline = 2; % Underscoring desired region
Example for editing a string in a excel cell that works.
Range = get(Sheet,’Range’, ‘A1’);
Range.Value = {‘(Test Area = 21.65 cm2)’};
Chars = invoke(Range,’Characters’,22,1); % Selecting character range within cell starting at character 22 and continuing for 1 length
Chars.Font.Superscript = ‘true’; % Seting selected character to supersciptI have been trying to work out how to underscore a section of a chart title string in an existing chart in excel through actxserver. I would typically use invoke to format strings in excel cells, but I can’t use that approach in chart titles.
In the code below I am replacing a section of the title string, which has a portion already underscored. This automically underscoes the whole title for some reason, which I then remove and try to underscore just the section that was already underscored.
If anyone has a solution it would be much appreciated. I have tried different LLMs, but this is the method they suggest. Which should work based on excel VBA. Possibly this is just not supported in Matlab?
Example of editing characters in a chart title that doesn’t work.
excel = actxserver(‘Excel.Application’);
file = excel.Workbooks.Open("ABC.xlsx");
Sheet = excel.Worksheets.Item(‘ABC’);
ChartObjects = Sheet.ChartObjects;
chart = ChartObjects.Item(1).Chart; % Selecting chart
s = chart.ChartTitle.Text; % find current chart title
chart.ChartTitle.Text = strrep(s, OldWord, NewWord); % Replace key word in chart title
chart.ChartTitle.Characters.Font.Underline = 0; % Removing all underscored characters
pos = strfind(s, ‘-‘); % finding end of region to underline
% Works up to this last line
chart.ChartTitle.Characters(1, pos(1)-2).Font.Underline = 2; % Underscoring desired region
Example for editing a string in a excel cell that works.
Range = get(Sheet,’Range’, ‘A1’);
Range.Value = {‘(Test Area = 21.65 cm2)’};
Chars = invoke(Range,’Characters’,22,1); % Selecting character range within cell starting at character 22 and continuing for 1 length
Chars.Font.Superscript = ‘true’; % Seting selected character to superscipt I have been trying to work out how to underscore a section of a chart title string in an existing chart in excel through actxserver. I would typically use invoke to format strings in excel cells, but I can’t use that approach in chart titles.
In the code below I am replacing a section of the title string, which has a portion already underscored. This automically underscoes the whole title for some reason, which I then remove and try to underscore just the section that was already underscored.
If anyone has a solution it would be much appreciated. I have tried different LLMs, but this is the method they suggest. Which should work based on excel VBA. Possibly this is just not supported in Matlab?
Example of editing characters in a chart title that doesn’t work.
excel = actxserver(‘Excel.Application’);
file = excel.Workbooks.Open("ABC.xlsx");
Sheet = excel.Worksheets.Item(‘ABC’);
ChartObjects = Sheet.ChartObjects;
chart = ChartObjects.Item(1).Chart; % Selecting chart
s = chart.ChartTitle.Text; % find current chart title
chart.ChartTitle.Text = strrep(s, OldWord, NewWord); % Replace key word in chart title
chart.ChartTitle.Characters.Font.Underline = 0; % Removing all underscored characters
pos = strfind(s, ‘-‘); % finding end of region to underline
% Works up to this last line
chart.ChartTitle.Characters(1, pos(1)-2).Font.Underline = 2; % Underscoring desired region
Example for editing a string in a excel cell that works.
Range = get(Sheet,’Range’, ‘A1’);
Range.Value = {‘(Test Area = 21.65 cm2)’};
Chars = invoke(Range,’Characters’,22,1); % Selecting character range within cell starting at character 22 and continuing for 1 length
Chars.Font.Superscript = ‘true’; % Seting selected character to superscipt actxserver, excel, chart title, underscore MATLAB Answers — New Questions
Discrepancy in sparse matrix math, when NaN’s present
I expect result1 and result2 below to be identical, but they aren’t. The discrepancy must be a bug, right? I’m working in R2024b, but the Run output below shows the issue exists as well in whatever the Matlab online engine is now running.
n = 5; m = 3;
S = sparse(n, m);
v=nan(n, 1);
D=sparse(diag(v));
result1=full(v.*S) %correct
result2=full(D*S) %incorrectI expect result1 and result2 below to be identical, but they aren’t. The discrepancy must be a bug, right? I’m working in R2024b, but the Run output below shows the issue exists as well in whatever the Matlab online engine is now running.
n = 5; m = 3;
S = sparse(n, m);
v=nan(n, 1);
D=sparse(diag(v));
result1=full(v.*S) %correct
result2=full(D*S) %incorrect I expect result1 and result2 below to be identical, but they aren’t. The discrepancy must be a bug, right? I’m working in R2024b, but the Run output below shows the issue exists as well in whatever the Matlab online engine is now running.
n = 5; m = 3;
S = sparse(n, m);
v=nan(n, 1);
D=sparse(diag(v));
result1=full(v.*S) %correct
result2=full(D*S) %incorrect sparse, nan, bug?, numeric MATLAB Answers — New Questions
Why do I get an “Unrecognized method, property, or field ‘IsInterface'” error when accessing NET.assembly properties with .NET 9
With .NET 9, I am attempting to get the properties of a NET.Assembly (like Classes or Interfaces), but this throws an error. For example,
>> asmInfo = NET.addAssembly("System.Windows.Forms");
>> asmInfo.Classes
Unrecognized method, property, or field ‘IsInterface’ for class ‘System.RuntimeType’.
…
This same code works with .NET 8. Why am I getting an error with .NET 9?With .NET 9, I am attempting to get the properties of a NET.Assembly (like Classes or Interfaces), but this throws an error. For example,
>> asmInfo = NET.addAssembly("System.Windows.Forms");
>> asmInfo.Classes
Unrecognized method, property, or field ‘IsInterface’ for class ‘System.RuntimeType’.
…
This same code works with .NET 8. Why am I getting an error with .NET 9? With .NET 9, I am attempting to get the properties of a NET.Assembly (like Classes or Interfaces), but this throws an error. For example,
>> asmInfo = NET.addAssembly("System.Windows.Forms");
>> asmInfo.Classes
Unrecognized method, property, or field ‘IsInterface’ for class ‘System.RuntimeType’.
…
This same code works with .NET 8. Why am I getting an error with .NET 9? MATLAB Answers — New Questions
Evaporator heat-flow reversed in refrigerant loop model (Simscape)
Hello everyone,
I’m currently modeling a refrigerant test loop in Simscape. The flow path is:
High-pressure reservoir → condenser → short pipe → valve (TXV or EXV) → short pipe → evaporator → low-pressure reservoir. All parameters are set to realistic values (pressures, diameters, temperatures, etc.).
The issue I’m facing is that the evaporator appears to be removing heat from the refrigerant instead of adding it, the temperature at port B is higher than at port A, even though the evaporator’s ambient is hotter. This causes downstream effects such as superheat decreasing when the valve closes, which is the opposite of physical behavior. Meanwhile, the condenser behaves correctly (temperature drops from port A → B as it rejects heat). Has anyone seen this before or know why the evaporator heat direction might flip in Simscape?Hello everyone,
I’m currently modeling a refrigerant test loop in Simscape. The flow path is:
High-pressure reservoir → condenser → short pipe → valve (TXV or EXV) → short pipe → evaporator → low-pressure reservoir. All parameters are set to realistic values (pressures, diameters, temperatures, etc.).
The issue I’m facing is that the evaporator appears to be removing heat from the refrigerant instead of adding it, the temperature at port B is higher than at port A, even though the evaporator’s ambient is hotter. This causes downstream effects such as superheat decreasing when the valve closes, which is the opposite of physical behavior. Meanwhile, the condenser behaves correctly (temperature drops from port A → B as it rejects heat). Has anyone seen this before or know why the evaporator heat direction might flip in Simscape? Hello everyone,
I’m currently modeling a refrigerant test loop in Simscape. The flow path is:
High-pressure reservoir → condenser → short pipe → valve (TXV or EXV) → short pipe → evaporator → low-pressure reservoir. All parameters are set to realistic values (pressures, diameters, temperatures, etc.).
The issue I’m facing is that the evaporator appears to be removing heat from the refrigerant instead of adding it, the temperature at port B is higher than at port A, even though the evaporator’s ambient is hotter. This causes downstream effects such as superheat decreasing when the valve closes, which is the opposite of physical behavior. Meanwhile, the condenser behaves correctly (temperature drops from port A → B as it rejects heat). Has anyone seen this before or know why the evaporator heat direction might flip in Simscape? simscape MATLAB Answers — New Questions









