Author: PuTI
Color inside Confidence Interval after a fitlm
Hi
I’d like to color the area in betwen the Confidence Interval after a fitlm, like shown in the attached pic
I tried patch, area, fill, but I couln’t make any of them work.
I think the issue is that the x values are not continuous (it’s not 1:19 for example)
I have 2 continuous variables
% x = rand(1,19); y = x+[1:19];
d = load(‘d.txt’) ;
x = d(:,1) ;
y = d(:,2) ;
mdl = fitlm(x,y)
mdl.plot
thanks a lotHi
I’d like to color the area in betwen the Confidence Interval after a fitlm, like shown in the attached pic
I tried patch, area, fill, but I couln’t make any of them work.
I think the issue is that the x values are not continuous (it’s not 1:19 for example)
I have 2 continuous variables
% x = rand(1,19); y = x+[1:19];
d = load(‘d.txt’) ;
x = d(:,1) ;
y = d(:,2) ;
mdl = fitlm(x,y)
mdl.plot
thanks a lot Hi
I’d like to color the area in betwen the Confidence Interval after a fitlm, like shown in the attached pic
I tried patch, area, fill, but I couln’t make any of them work.
I think the issue is that the x values are not continuous (it’s not 1:19 for example)
I have 2 continuous variables
% x = rand(1,19); y = x+[1:19];
d = load(‘d.txt’) ;
x = d(:,1) ;
y = d(:,2) ;
mdl = fitlm(x,y)
mdl.plot
thanks a lot area color, fitlm, confidence interval MATLAB Answers — New Questions
Why isnt the mathworks course task not acceptig my answer?
I need to finish the control system analysis course for a class and the first coding task isnt being accepted by matlab i font understand why i need this to workI need to finish the control system analysis course for a class and the first coding task isnt being accepted by matlab i font understand why i need this to work I need to finish the control system analysis course for a class and the first coding task isnt being accepted by matlab i font understand why i need this to work self-paced course MATLAB Answers — New Questions
Cone angle of spray
Hello to everybody,
I want to calculate spray angle of this image and i use this code (that I found here) but this code evaluates an angle of 0 degrees. Can someone help me???? This is the final image
function test
clc;
close all;
workspace; % Make sure the workspace panel with all the variables is showing.
format longg;
format compact;
fontSize = 18;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license(‘test’, ‘image_toolbox’);
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf(‘Sorry, but you do not seem to have the Image Processing Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a standard MATLAB color demo image.
folder = pwd;
baseFileName = ‘prova.jpg’;
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, ‘file’)
% Didn’t find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, ‘file’)
% Still didn’t find it. Alert user.
errorMessage = sprintf(‘Error: %s does not exist.’, fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% If it’s really color, then convert to gray scale.
grayImage = grayImage(:,:,2);
end
% Display the original image.
subplot(2, 3, 1);
imshow(grayImage);
axis on;
title(‘Original Image’, ‘FontSize’, fontSize);
% Enlarge figure to full screen.
set(gcf, ‘Units’, ‘Normalized’, ‘Outerposition’, [0, 0, 1, 1]);
% Let’s compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
% Suppress bins at 0 and 255 because they’re so tall we can’t see the rest of it.
pixelCount(1) = 0;
pixelCount(end) = 0;
subplot(2, 3, 2);
bar(grayLevels, pixelCount);
grid on;
title(‘Histogram of original image’, ‘FontSize’, fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% [lowThreshold, highThreshold, lastThresholdedBand] = threshold(133, 255, grayImage);
% Threshold the image
thresholdValue = 50;
binaryImage = grayImage < thresholdValue;
% Fill holes
% binaryImage = imfill(binaryImage, ‘holes’);
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage);
axis on;
title(‘Binary Image’, ‘FontSize’, fontSize);
%—————————————————————————
% Extract the largest area using our custom function ExtractNLargestBlobs().
numberToExtract = 1;
binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract);
%—————————————————————————
% % Fill any holes that might be present
binaryImage = imfill(binaryImage, ‘holes’);
% Do an opening to smooth out the edges.
se = strel(‘disk’, 3, 0);
binaryImage = imopen(binaryImage, se);
% Display the image.
subplot(2, 3, 4);
imshow(binaryImage);
axis on;
title(‘Biggest Blob’, ‘FontSize’, fontSize);
drawnow;
% Go down the image line by line finding the width
widths = zeros(1, rows);
leftEdge = zeros(1, rows);
rightEdge = zeros(1, rows);
for row = 1 : rows
thisRow = binaryImage(row, :);
leftIndex = find(thisRow, 1, ‘first’);
if ~isempty(leftIndex)
% There’s something there
leftEdge(row) = leftIndex;
rightEdge(row) = find(thisRow, 1, ‘last’);
widths(row) = rightEdge(row) – leftEdge(row);
end
end
% plot the widths
subplot(2, 3, 5);
plot(1:rows, widths, ‘b-‘, ‘LineWidth’, 2);
grid on;
title(‘Widths as a function of line number’, ‘FontSize’, fontSize);
axis on;
% Now find min width at top and max width.
% This could be an algorithm all by itself, but since this is just a simple demo,
% I’m going to hard code in values that I can see from the plot of the widths.
% I’m going to fit between rows 10 and 60
x = 10:60;
% Get the left angle.
y = leftEdge(x);
leftCoefficients = polyfit(x, y, 1);
leftAngle = atand(leftCoefficients(1))
subplot(2, 3, 6);
plot(x, y, ‘b-‘, ‘LineWidth’, 2);
hold on;
y = rightEdge(x);
rightCoefficients = polyfit(x, y, 1);
rightAngle = atand(rightCoefficients(1))
plot(x, y, ‘r-‘, ‘LineWidth’, 2);
grid on;
coneAngle = abs(leftAngle) + abs(rightAngle);
% Plot the fitted lines
yLeftFit = polyval(leftCoefficients, x);
plot(x, yLeftFit, ‘b-‘, ‘LineWidth’, 2);
yRightFit = polyval(rightCoefficients, x);
plot(x, yRightFit, ‘r-‘, ‘LineWidth’, 2);
legend(‘left’, ‘right’, ‘Location’, ‘east’);
message = sprintf(‘Done with demo.nThe cone angle is %.1f degrees.’, coneAngle);
uiwait(helpdlg(message));
%==============================================================================================
% Function to return the specified number of largest or smallest blobs in a binary image.
% If numberToExtract > 0 it returns the numberToExtract largest blobs.
% If numberToExtract < 0 it returns the numberToExtract smallest blobs.
% Example: return a binary image with only the largest blob:
% binaryImage = ExtractNLargestBlobs(binaryImage, 1);
% Example: return a binary image with the 3 smallest blobs:
% binaryImage = ExtractNLargestBlobs(binaryImage, -3);
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
try
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
blobMeasurements = regionprops(labeledImage, ‘area’);
% Get all the areas
allAreas = [blobMeasurements.Area];
if numberToExtract > length(allAreas);
% Limit the number they can get to the number that are there/available.
numberToExtract = length(allAreas);
end
if numberToExtract > 0
% For positive numbers, sort in order of largest to smallest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, ‘descend’);
elseif numberToExtract < 0
% For negative numbers, sort in order of smallest to largest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, ‘ascend’);
% Need to negate numberToExtract so we can use it in sortIndexes later.
numberToExtract = -numberToExtract;
else
% numberToExtract = 0. Shouldn’t happen. Return no blobs.
binaryImage = false(size(binaryImage));
return;
end
% Extract the "numberToExtract" largest blob(a)s using ismember().
biggestBlob = ismember(labeledImage, sortIndexes(1:numberToExtract));
% Convert from integer labeled image into binary (logical) image.
binaryImage = biggestBlob > 0;
catch ME
errorMessage = sprintf(‘Error in function ExtractNLargestBlobs().nnError Message:n%s’, ME.message);
fprintf(1, ‘%sn’, errorMessage);
uiwait(warndlg(errorMessage));
endHello to everybody,
I want to calculate spray angle of this image and i use this code (that I found here) but this code evaluates an angle of 0 degrees. Can someone help me???? This is the final image
function test
clc;
close all;
workspace; % Make sure the workspace panel with all the variables is showing.
format longg;
format compact;
fontSize = 18;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license(‘test’, ‘image_toolbox’);
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf(‘Sorry, but you do not seem to have the Image Processing Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a standard MATLAB color demo image.
folder = pwd;
baseFileName = ‘prova.jpg’;
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, ‘file’)
% Didn’t find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, ‘file’)
% Still didn’t find it. Alert user.
errorMessage = sprintf(‘Error: %s does not exist.’, fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% If it’s really color, then convert to gray scale.
grayImage = grayImage(:,:,2);
end
% Display the original image.
subplot(2, 3, 1);
imshow(grayImage);
axis on;
title(‘Original Image’, ‘FontSize’, fontSize);
% Enlarge figure to full screen.
set(gcf, ‘Units’, ‘Normalized’, ‘Outerposition’, [0, 0, 1, 1]);
% Let’s compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
% Suppress bins at 0 and 255 because they’re so tall we can’t see the rest of it.
pixelCount(1) = 0;
pixelCount(end) = 0;
subplot(2, 3, 2);
bar(grayLevels, pixelCount);
grid on;
title(‘Histogram of original image’, ‘FontSize’, fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% [lowThreshold, highThreshold, lastThresholdedBand] = threshold(133, 255, grayImage);
% Threshold the image
thresholdValue = 50;
binaryImage = grayImage < thresholdValue;
% Fill holes
% binaryImage = imfill(binaryImage, ‘holes’);
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage);
axis on;
title(‘Binary Image’, ‘FontSize’, fontSize);
%—————————————————————————
% Extract the largest area using our custom function ExtractNLargestBlobs().
numberToExtract = 1;
binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract);
%—————————————————————————
% % Fill any holes that might be present
binaryImage = imfill(binaryImage, ‘holes’);
% Do an opening to smooth out the edges.
se = strel(‘disk’, 3, 0);
binaryImage = imopen(binaryImage, se);
% Display the image.
subplot(2, 3, 4);
imshow(binaryImage);
axis on;
title(‘Biggest Blob’, ‘FontSize’, fontSize);
drawnow;
% Go down the image line by line finding the width
widths = zeros(1, rows);
leftEdge = zeros(1, rows);
rightEdge = zeros(1, rows);
for row = 1 : rows
thisRow = binaryImage(row, :);
leftIndex = find(thisRow, 1, ‘first’);
if ~isempty(leftIndex)
% There’s something there
leftEdge(row) = leftIndex;
rightEdge(row) = find(thisRow, 1, ‘last’);
widths(row) = rightEdge(row) – leftEdge(row);
end
end
% plot the widths
subplot(2, 3, 5);
plot(1:rows, widths, ‘b-‘, ‘LineWidth’, 2);
grid on;
title(‘Widths as a function of line number’, ‘FontSize’, fontSize);
axis on;
% Now find min width at top and max width.
% This could be an algorithm all by itself, but since this is just a simple demo,
% I’m going to hard code in values that I can see from the plot of the widths.
% I’m going to fit between rows 10 and 60
x = 10:60;
% Get the left angle.
y = leftEdge(x);
leftCoefficients = polyfit(x, y, 1);
leftAngle = atand(leftCoefficients(1))
subplot(2, 3, 6);
plot(x, y, ‘b-‘, ‘LineWidth’, 2);
hold on;
y = rightEdge(x);
rightCoefficients = polyfit(x, y, 1);
rightAngle = atand(rightCoefficients(1))
plot(x, y, ‘r-‘, ‘LineWidth’, 2);
grid on;
coneAngle = abs(leftAngle) + abs(rightAngle);
% Plot the fitted lines
yLeftFit = polyval(leftCoefficients, x);
plot(x, yLeftFit, ‘b-‘, ‘LineWidth’, 2);
yRightFit = polyval(rightCoefficients, x);
plot(x, yRightFit, ‘r-‘, ‘LineWidth’, 2);
legend(‘left’, ‘right’, ‘Location’, ‘east’);
message = sprintf(‘Done with demo.nThe cone angle is %.1f degrees.’, coneAngle);
uiwait(helpdlg(message));
%==============================================================================================
% Function to return the specified number of largest or smallest blobs in a binary image.
% If numberToExtract > 0 it returns the numberToExtract largest blobs.
% If numberToExtract < 0 it returns the numberToExtract smallest blobs.
% Example: return a binary image with only the largest blob:
% binaryImage = ExtractNLargestBlobs(binaryImage, 1);
% Example: return a binary image with the 3 smallest blobs:
% binaryImage = ExtractNLargestBlobs(binaryImage, -3);
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
try
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
blobMeasurements = regionprops(labeledImage, ‘area’);
% Get all the areas
allAreas = [blobMeasurements.Area];
if numberToExtract > length(allAreas);
% Limit the number they can get to the number that are there/available.
numberToExtract = length(allAreas);
end
if numberToExtract > 0
% For positive numbers, sort in order of largest to smallest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, ‘descend’);
elseif numberToExtract < 0
% For negative numbers, sort in order of smallest to largest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, ‘ascend’);
% Need to negate numberToExtract so we can use it in sortIndexes later.
numberToExtract = -numberToExtract;
else
% numberToExtract = 0. Shouldn’t happen. Return no blobs.
binaryImage = false(size(binaryImage));
return;
end
% Extract the "numberToExtract" largest blob(a)s using ismember().
biggestBlob = ismember(labeledImage, sortIndexes(1:numberToExtract));
% Convert from integer labeled image into binary (logical) image.
binaryImage = biggestBlob > 0;
catch ME
errorMessage = sprintf(‘Error in function ExtractNLargestBlobs().nnError Message:n%s’, ME.message);
fprintf(1, ‘%sn’, errorMessage);
uiwait(warndlg(errorMessage));
end Hello to everybody,
I want to calculate spray angle of this image and i use this code (that I found here) but this code evaluates an angle of 0 degrees. Can someone help me???? This is the final image
function test
clc;
close all;
workspace; % Make sure the workspace panel with all the variables is showing.
format longg;
format compact;
fontSize = 18;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license(‘test’, ‘image_toolbox’);
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf(‘Sorry, but you do not seem to have the Image Processing Toolbox.nDo you want to try to continue anyway?’);
reply = questdlg(message, ‘Toolbox missing’, ‘Yes’, ‘No’, ‘Yes’);
if strcmpi(reply, ‘No’)
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a standard MATLAB color demo image.
folder = pwd;
baseFileName = ‘prova.jpg’;
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, ‘file’)
% Didn’t find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, ‘file’)
% Still didn’t find it. Alert user.
errorMessage = sprintf(‘Error: %s does not exist.’, fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% If it’s really color, then convert to gray scale.
grayImage = grayImage(:,:,2);
end
% Display the original image.
subplot(2, 3, 1);
imshow(grayImage);
axis on;
title(‘Original Image’, ‘FontSize’, fontSize);
% Enlarge figure to full screen.
set(gcf, ‘Units’, ‘Normalized’, ‘Outerposition’, [0, 0, 1, 1]);
% Let’s compute and display the histogram.
[pixelCount, grayLevels] = imhist(grayImage);
% Suppress bins at 0 and 255 because they’re so tall we can’t see the rest of it.
pixelCount(1) = 0;
pixelCount(end) = 0;
subplot(2, 3, 2);
bar(grayLevels, pixelCount);
grid on;
title(‘Histogram of original image’, ‘FontSize’, fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% [lowThreshold, highThreshold, lastThresholdedBand] = threshold(133, 255, grayImage);
% Threshold the image
thresholdValue = 50;
binaryImage = grayImage < thresholdValue;
% Fill holes
% binaryImage = imfill(binaryImage, ‘holes’);
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage);
axis on;
title(‘Binary Image’, ‘FontSize’, fontSize);
%—————————————————————————
% Extract the largest area using our custom function ExtractNLargestBlobs().
numberToExtract = 1;
binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract);
%—————————————————————————
% % Fill any holes that might be present
binaryImage = imfill(binaryImage, ‘holes’);
% Do an opening to smooth out the edges.
se = strel(‘disk’, 3, 0);
binaryImage = imopen(binaryImage, se);
% Display the image.
subplot(2, 3, 4);
imshow(binaryImage);
axis on;
title(‘Biggest Blob’, ‘FontSize’, fontSize);
drawnow;
% Go down the image line by line finding the width
widths = zeros(1, rows);
leftEdge = zeros(1, rows);
rightEdge = zeros(1, rows);
for row = 1 : rows
thisRow = binaryImage(row, :);
leftIndex = find(thisRow, 1, ‘first’);
if ~isempty(leftIndex)
% There’s something there
leftEdge(row) = leftIndex;
rightEdge(row) = find(thisRow, 1, ‘last’);
widths(row) = rightEdge(row) – leftEdge(row);
end
end
% plot the widths
subplot(2, 3, 5);
plot(1:rows, widths, ‘b-‘, ‘LineWidth’, 2);
grid on;
title(‘Widths as a function of line number’, ‘FontSize’, fontSize);
axis on;
% Now find min width at top and max width.
% This could be an algorithm all by itself, but since this is just a simple demo,
% I’m going to hard code in values that I can see from the plot of the widths.
% I’m going to fit between rows 10 and 60
x = 10:60;
% Get the left angle.
y = leftEdge(x);
leftCoefficients = polyfit(x, y, 1);
leftAngle = atand(leftCoefficients(1))
subplot(2, 3, 6);
plot(x, y, ‘b-‘, ‘LineWidth’, 2);
hold on;
y = rightEdge(x);
rightCoefficients = polyfit(x, y, 1);
rightAngle = atand(rightCoefficients(1))
plot(x, y, ‘r-‘, ‘LineWidth’, 2);
grid on;
coneAngle = abs(leftAngle) + abs(rightAngle);
% Plot the fitted lines
yLeftFit = polyval(leftCoefficients, x);
plot(x, yLeftFit, ‘b-‘, ‘LineWidth’, 2);
yRightFit = polyval(rightCoefficients, x);
plot(x, yRightFit, ‘r-‘, ‘LineWidth’, 2);
legend(‘left’, ‘right’, ‘Location’, ‘east’);
message = sprintf(‘Done with demo.nThe cone angle is %.1f degrees.’, coneAngle);
uiwait(helpdlg(message));
%==============================================================================================
% Function to return the specified number of largest or smallest blobs in a binary image.
% If numberToExtract > 0 it returns the numberToExtract largest blobs.
% If numberToExtract < 0 it returns the numberToExtract smallest blobs.
% Example: return a binary image with only the largest blob:
% binaryImage = ExtractNLargestBlobs(binaryImage, 1);
% Example: return a binary image with the 3 smallest blobs:
% binaryImage = ExtractNLargestBlobs(binaryImage, -3);
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
try
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
blobMeasurements = regionprops(labeledImage, ‘area’);
% Get all the areas
allAreas = [blobMeasurements.Area];
if numberToExtract > length(allAreas);
% Limit the number they can get to the number that are there/available.
numberToExtract = length(allAreas);
end
if numberToExtract > 0
% For positive numbers, sort in order of largest to smallest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, ‘descend’);
elseif numberToExtract < 0
% For negative numbers, sort in order of smallest to largest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, ‘ascend’);
% Need to negate numberToExtract so we can use it in sortIndexes later.
numberToExtract = -numberToExtract;
else
% numberToExtract = 0. Shouldn’t happen. Return no blobs.
binaryImage = false(size(binaryImage));
return;
end
% Extract the "numberToExtract" largest blob(a)s using ismember().
biggestBlob = ismember(labeledImage, sortIndexes(1:numberToExtract));
% Convert from integer labeled image into binary (logical) image.
binaryImage = biggestBlob > 0;
catch ME
errorMessage = sprintf(‘Error in function ExtractNLargestBlobs().nnError Message:n%s’, ME.message);
fprintf(1, ‘%sn’, errorMessage);
uiwait(warndlg(errorMessage));
end angle, spray, cone angle, angle spray, spray angle, spray cone MATLAB Answers — New Questions
How to download R2016a version of matlab.
How to download R2016a version of matlab,When i try to download it, it is asking for license key or activation key.i already have R2010b installed on my system.when i enter license key it is saying u entered invalid key.Please tell how to download latest version of matlabHow to download R2016a version of matlab,When i try to download it, it is asking for license key or activation key.i already have R2010b installed on my system.when i enter license key it is saying u entered invalid key.Please tell how to download latest version of matlab How to download R2016a version of matlab,When i try to download it, it is asking for license key or activation key.i already have R2010b installed on my system.when i enter license key it is saying u entered invalid key.Please tell how to download latest version of matlab download matlab MATLAB Answers — New Questions
Vulnerability in Apache Log4j version included in 2025a relating to CVE-2026-34480 and CVE-2026-34477
Do either of these vulnerabilites affect Matlab 2025a, 2025b or 2026a as a result of the distribution of Log4j version included, e.g. for Matlab 2025a C:Program FilesMATLABR2025ajavajarextlog4j-core-2.17.1.jar.Do either of these vulnerabilites affect Matlab 2025a, 2025b or 2026a as a result of the distribution of Log4j version included, e.g. for Matlab 2025a C:Program FilesMATLABR2025ajavajarextlog4j-core-2.17.1.jar. Do either of these vulnerabilites affect Matlab 2025a, 2025b or 2026a as a result of the distribution of Log4j version included, e.g. for Matlab 2025a C:Program FilesMATLABR2025ajavajarextlog4j-core-2.17.1.jar. log4j, cve-2026-34480, cve-2026-34477 MATLAB Answers — New Questions
Licensing Error 5005: “You do not have a valid license file” on R2026a startup.
Hello, I am unable to launch MATLAB R2026a due to Licensing Error 5005.
Steps I have already taken:
Attempted manual activation using activate_matlab.exe as Administrator.
Performed a clean reinstall, manually deleting the following folders:
C:Program FilesMATLABR2026a
C:UsersdanieAppDataRoamingMathWorks
I noticed a ghost entry for a previous version (R2022a) in Windows Settings that points to a non-existent path on the Desktop, which I cannot remove.
Checked the licenses folder; it was empty or contained a file that didn’t resolve the issue.
I have attached a screenshot of the error message. How can I force MATLAB to recognize my valid license?Hello, I am unable to launch MATLAB R2026a due to Licensing Error 5005.
Steps I have already taken:
Attempted manual activation using activate_matlab.exe as Administrator.
Performed a clean reinstall, manually deleting the following folders:
C:Program FilesMATLABR2026a
C:UsersdanieAppDataRoamingMathWorks
I noticed a ghost entry for a previous version (R2022a) in Windows Settings that points to a non-existent path on the Desktop, which I cannot remove.
Checked the licenses folder; it was empty or contained a file that didn’t resolve the issue.
I have attached a screenshot of the error message. How can I force MATLAB to recognize my valid license? Hello, I am unable to launch MATLAB R2026a due to Licensing Error 5005.
Steps I have already taken:
Attempted manual activation using activate_matlab.exe as Administrator.
Performed a clean reinstall, manually deleting the following folders:
C:Program FilesMATLABR2026a
C:UsersdanieAppDataRoamingMathWorks
I noticed a ghost entry for a previous version (R2022a) in Windows Settings that points to a non-existent path on the Desktop, which I cannot remove.
Checked the licenses folder; it was empty or contained a file that didn’t resolve the issue.
I have attached a screenshot of the error message. How can I force MATLAB to recognize my valid license? installation, licensing, error 5005, activation MATLAB Answers — New Questions
Simscape Multibody: What is the difference between the force and the motion actuation in prismatic joint?
I have a simscape model, in which a set of spheres are trying to grab a cylinder. I used the spatial contact force block between the cylinder and spheres. I set up two ways that the spheres move up: 1, Input a motion actuation to the prismatic model; 2, Input a force actuation to the prismatic model.
For setup 1: The tube does NOT move. The spheres slip along the cylinder.
For setup 2: The tube MOVE UP with the spheres.
All the other settings are the same except the input actuation. So I am wondering what is the reason for this? Can anyone help to answer? Thanks!I have a simscape model, in which a set of spheres are trying to grab a cylinder. I used the spatial contact force block between the cylinder and spheres. I set up two ways that the spheres move up: 1, Input a motion actuation to the prismatic model; 2, Input a force actuation to the prismatic model.
For setup 1: The tube does NOT move. The spheres slip along the cylinder.
For setup 2: The tube MOVE UP with the spheres.
All the other settings are the same except the input actuation. So I am wondering what is the reason for this? Can anyone help to answer? Thanks! I have a simscape model, in which a set of spheres are trying to grab a cylinder. I used the spatial contact force block between the cylinder and spheres. I set up two ways that the spheres move up: 1, Input a motion actuation to the prismatic model; 2, Input a force actuation to the prismatic model.
For setup 1: The tube does NOT move. The spheres slip along the cylinder.
For setup 2: The tube MOVE UP with the spheres.
All the other settings are the same except the input actuation. So I am wondering what is the reason for this? Can anyone help to answer? Thanks! simscape, spatial contact force, prismatic joint MATLAB Answers — New Questions
Copilot cannot access matlab environment?
In most IDEs you can ask the LLM about the code on the screen, and the copilot chat seems to think it can access the editor, although I could not get it to actually do so. After trying to do this and getting a lot of conflicted answers I finally got this:
Me
Can you read files that are currently open in matlab?
Copilot
No — I cannot directly read files on your machine or access the MATLAB Editor. I can only work with text or files you share here.
Is that correct? The chat is not actually integrated with the Matlab like in a normal IDE (VS, VSCode, etc)? Is there some way to fix this or otherwise get it to work with the environment? Or if it is intentional it might be helpful to explain that the system is much more limited than it thinks it is.In most IDEs you can ask the LLM about the code on the screen, and the copilot chat seems to think it can access the editor, although I could not get it to actually do so. After trying to do this and getting a lot of conflicted answers I finally got this:
Me
Can you read files that are currently open in matlab?
Copilot
No — I cannot directly read files on your machine or access the MATLAB Editor. I can only work with text or files you share here.
Is that correct? The chat is not actually integrated with the Matlab like in a normal IDE (VS, VSCode, etc)? Is there some way to fix this or otherwise get it to work with the environment? Or if it is intentional it might be helpful to explain that the system is much more limited than it thinks it is. In most IDEs you can ask the LLM about the code on the screen, and the copilot chat seems to think it can access the editor, although I could not get it to actually do so. After trying to do this and getting a lot of conflicted answers I finally got this:
Me
Can you read files that are currently open in matlab?
Copilot
No — I cannot directly read files on your machine or access the MATLAB Editor. I can only work with text or files you share here.
Is that correct? The chat is not actually integrated with the Matlab like in a normal IDE (VS, VSCode, etc)? Is there some way to fix this or otherwise get it to work with the environment? Or if it is intentional it might be helpful to explain that the system is much more limited than it thinks it is. copilot MATLAB Answers — New Questions
Error in simscape when computing derivative
I have a Simscape block that takes linPosition (physical signal) as an input and computes rotPosition (another physical signal). If I put it in my model, where linPosition is 0 for 1ms and then starts increasing smoothly, it works (rotPosition and theta are constant for 1ms and then follow the growth of linPosition). The problem arises when I try to add an additional computation: omega == der(theta) (I need it to make more calculation and provide another output). With that additional equation, I get this warning:
Equations (including nonlinear equations) of one or more components may be dependent or inconsistent. This can cause problems in transient initialization.
referred to the first and second equations. Then the simulation stops at 1ms:
An error occurred during simulation and the simulation was stopped
Caused by:
[‘testCircuit/Solver Configuration’]: Transient initialization at time 0.001, solving for consistent states and modes, failed to converge.
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
all components and nodal across variables involved
Cannot solve for one or more variables, including dynamic variable derivatives:
Time derivative of ‘CRIB.CRIB_velocityBased.breaking_part.offsetSliderCrank.theta’ (rot angle with respect to horizontal)
‘CRIB.CRIB_velocityBased.breaking_part.offsetSliderCrank.omega’ (omega)
In my mind, theta and gamma in the equations are computed and then omega follows the value of theta, but I guess that this is not how it works.
component offsetSliderCrank
inputs
linPosition = {0, ‘mm’};
end
outputs
rotPosition = {0, ‘deg’};
end
parameters
lRod = { 45, ‘mm’ }; %
rJunction = { 10, ‘mm’ }; %
xC = { 2, ‘mm’ }; %
yC = { 40, ‘mm’ }; %
end
variables(Access=Protected)
theta = {value={0,’deg’},imin={-90,’deg’},imax={89,’deg’}}; % rot angle with respect to horizontal
gamma = {value={0,’deg’},imin={0,’deg’},imax={180,’deg’}}; % angle between lRod and horizontal
omega = {0,’deg/s’};
end
equations
lRod*cos(gamma)+xC == rJunction*cos(theta);
yC-linPosition – rJunction*sin(theta) == lRod*sin(gamma);
let
theta0 = asin((yC^2+rJunction^2-lRod^2+xC^2)/(2*rJunction*sqrt(xC^2+yC^2))) – atan(xC/yC) ;
in
rotPosition == – (theta- theta0);
end
omega == der(theta);
end
endI have a Simscape block that takes linPosition (physical signal) as an input and computes rotPosition (another physical signal). If I put it in my model, where linPosition is 0 for 1ms and then starts increasing smoothly, it works (rotPosition and theta are constant for 1ms and then follow the growth of linPosition). The problem arises when I try to add an additional computation: omega == der(theta) (I need it to make more calculation and provide another output). With that additional equation, I get this warning:
Equations (including nonlinear equations) of one or more components may be dependent or inconsistent. This can cause problems in transient initialization.
referred to the first and second equations. Then the simulation stops at 1ms:
An error occurred during simulation and the simulation was stopped
Caused by:
[‘testCircuit/Solver Configuration’]: Transient initialization at time 0.001, solving for consistent states and modes, failed to converge.
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
all components and nodal across variables involved
Cannot solve for one or more variables, including dynamic variable derivatives:
Time derivative of ‘CRIB.CRIB_velocityBased.breaking_part.offsetSliderCrank.theta’ (rot angle with respect to horizontal)
‘CRIB.CRIB_velocityBased.breaking_part.offsetSliderCrank.omega’ (omega)
In my mind, theta and gamma in the equations are computed and then omega follows the value of theta, but I guess that this is not how it works.
component offsetSliderCrank
inputs
linPosition = {0, ‘mm’};
end
outputs
rotPosition = {0, ‘deg’};
end
parameters
lRod = { 45, ‘mm’ }; %
rJunction = { 10, ‘mm’ }; %
xC = { 2, ‘mm’ }; %
yC = { 40, ‘mm’ }; %
end
variables(Access=Protected)
theta = {value={0,’deg’},imin={-90,’deg’},imax={89,’deg’}}; % rot angle with respect to horizontal
gamma = {value={0,’deg’},imin={0,’deg’},imax={180,’deg’}}; % angle between lRod and horizontal
omega = {0,’deg/s’};
end
equations
lRod*cos(gamma)+xC == rJunction*cos(theta);
yC-linPosition – rJunction*sin(theta) == lRod*sin(gamma);
let
theta0 = asin((yC^2+rJunction^2-lRod^2+xC^2)/(2*rJunction*sqrt(xC^2+yC^2))) – atan(xC/yC) ;
in
rotPosition == – (theta- theta0);
end
omega == der(theta);
end
end I have a Simscape block that takes linPosition (physical signal) as an input and computes rotPosition (another physical signal). If I put it in my model, where linPosition is 0 for 1ms and then starts increasing smoothly, it works (rotPosition and theta are constant for 1ms and then follow the growth of linPosition). The problem arises when I try to add an additional computation: omega == der(theta) (I need it to make more calculation and provide another output). With that additional equation, I get this warning:
Equations (including nonlinear equations) of one or more components may be dependent or inconsistent. This can cause problems in transient initialization.
referred to the first and second equations. Then the simulation stops at 1ms:
An error occurred during simulation and the simulation was stopped
Caused by:
[‘testCircuit/Solver Configuration’]: Transient initialization at time 0.001, solving for consistent states and modes, failed to converge.
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
all components and nodal across variables involved
Cannot solve for one or more variables, including dynamic variable derivatives:
Time derivative of ‘CRIB.CRIB_velocityBased.breaking_part.offsetSliderCrank.theta’ (rot angle with respect to horizontal)
‘CRIB.CRIB_velocityBased.breaking_part.offsetSliderCrank.omega’ (omega)
In my mind, theta and gamma in the equations are computed and then omega follows the value of theta, but I guess that this is not how it works.
component offsetSliderCrank
inputs
linPosition = {0, ‘mm’};
end
outputs
rotPosition = {0, ‘deg’};
end
parameters
lRod = { 45, ‘mm’ }; %
rJunction = { 10, ‘mm’ }; %
xC = { 2, ‘mm’ }; %
yC = { 40, ‘mm’ }; %
end
variables(Access=Protected)
theta = {value={0,’deg’},imin={-90,’deg’},imax={89,’deg’}}; % rot angle with respect to horizontal
gamma = {value={0,’deg’},imin={0,’deg’},imax={180,’deg’}}; % angle between lRod and horizontal
omega = {0,’deg/s’};
end
equations
lRod*cos(gamma)+xC == rJunction*cos(theta);
yC-linPosition – rJunction*sin(theta) == lRod*sin(gamma);
let
theta0 = asin((yC^2+rJunction^2-lRod^2+xC^2)/(2*rJunction*sqrt(xC^2+yC^2))) – atan(xC/yC) ;
in
rotPosition == – (theta- theta0);
end
omega == der(theta);
end
end simscape, derivative MATLAB Answers — New Questions
How to calculate spray cone angle with videos?
Hello, everyone!
I have a high-speed video where a new spray image appears approximately every second, and I need to automate the extraction of the spray cone angle for each frame. Additionally, I would like to generate a plot to demonstrate the angle variations after every 200 analyses. I would greatly appreciate any suggestions, relevant functions, or example scripts regarding the best image processing workflow for boundary detection, as well as advice on how to structure the loop for sequential processing and periodic plot updates. Thank you very much for your time and patience!Hello, everyone!
I have a high-speed video where a new spray image appears approximately every second, and I need to automate the extraction of the spray cone angle for each frame. Additionally, I would like to generate a plot to demonstrate the angle variations after every 200 analyses. I would greatly appreciate any suggestions, relevant functions, or example scripts regarding the best image processing workflow for boundary detection, as well as advice on how to structure the loop for sequential processing and periodic plot updates. Thank you very much for your time and patience! Hello, everyone!
I have a high-speed video where a new spray image appears approximately every second, and I need to automate the extraction of the spray cone angle for each frame. Additionally, I would like to generate a plot to demonstrate the angle variations after every 200 analyses. I would greatly appreciate any suggestions, relevant functions, or example scripts regarding the best image processing workflow for boundary detection, as well as advice on how to structure the loop for sequential processing and periodic plot updates. Thank you very much for your time and patience! spray, angle, video, help MATLAB Answers — New Questions
How to install Surrogate Toolbox 3.0 by Dr. Viana?
I am trying to Install <https://sites.google.com/site/srgtstoolbox/ Surrogate Toolbox 3.0>
by Dr. Viana in 64 bit machine with Windows 10. It seems to be very easy, but somehow I am getting the error while installing.
I am getting:
—————————————————————————
What would you like to do? 2
Building with ‘Microsoft Visual C++ 2013 Professional (C)’.
MEX completed successfully.
Error using fileparts
Too many output arguments.
Error in srgtsSVMGunnFiles>srgtsCompileSVMGunn (line 101)
[pathstr, name, ext, versn] = fileparts(file_source);
Error in srgtsSVMGunnFiles (line 61)
[file_source filename] = srgtsCompileSVMGunn(srgtsRootDir, interpreter);
Error in srgtsInstall (line 75)
srgtsSVMGunnFiles(srgtsRootDir, hostname, interpreter);I am trying to Install <https://sites.google.com/site/srgtstoolbox/ Surrogate Toolbox 3.0>
by Dr. Viana in 64 bit machine with Windows 10. It seems to be very easy, but somehow I am getting the error while installing.
I am getting:
—————————————————————————
What would you like to do? 2
Building with ‘Microsoft Visual C++ 2013 Professional (C)’.
MEX completed successfully.
Error using fileparts
Too many output arguments.
Error in srgtsSVMGunnFiles>srgtsCompileSVMGunn (line 101)
[pathstr, name, ext, versn] = fileparts(file_source);
Error in srgtsSVMGunnFiles (line 61)
[file_source filename] = srgtsCompileSVMGunn(srgtsRootDir, interpreter);
Error in srgtsInstall (line 75)
srgtsSVMGunnFiles(srgtsRootDir, hostname, interpreter); I am trying to Install <https://sites.google.com/site/srgtstoolbox/ Surrogate Toolbox 3.0>
by Dr. Viana in 64 bit machine with Windows 10. It seems to be very easy, but somehow I am getting the error while installing.
I am getting:
—————————————————————————
What would you like to do? 2
Building with ‘Microsoft Visual C++ 2013 Professional (C)’.
MEX completed successfully.
Error using fileparts
Too many output arguments.
Error in srgtsSVMGunnFiles>srgtsCompileSVMGunn (line 101)
[pathstr, name, ext, versn] = fileparts(file_source);
Error in srgtsSVMGunnFiles (line 61)
[file_source filename] = srgtsCompileSVMGunn(srgtsRootDir, interpreter);
Error in srgtsInstall (line 75)
srgtsSVMGunnFiles(srgtsRootDir, hostname, interpreter); surrogate toolbox MATLAB Answers — New Questions
Non-linear data fit with multiple constants
I have a non-linear equation with 3 variables I wish to be constants and only 1 variable to be fitted to x,y data.
Using fittype, I have entered the equation and tried to specify b, c & d as constants. However, the options ‘problem’ only seems to allow single variables to be specified as constants
ft = fittype(@(a, b, c, d,x) a*c*x./(1+c*x) + b*d*x./(1+d*x),’problem’,’b,c,d’);
Error using fittype>iAssertValidVariableNames
The name ‘[b,c,d]’ is not a valid MATLAB variable name.
In the next part I use "fit" to fit the data, and specify the value of the 3 constants and starting point of the fit:
f = fit(p(1:index),q(1:index),ft,’problem’,[Qm2 b1 b2],’StartPoint’,Qm1);
Is there another way to specify constants in the fittype?I have a non-linear equation with 3 variables I wish to be constants and only 1 variable to be fitted to x,y data.
Using fittype, I have entered the equation and tried to specify b, c & d as constants. However, the options ‘problem’ only seems to allow single variables to be specified as constants
ft = fittype(@(a, b, c, d,x) a*c*x./(1+c*x) + b*d*x./(1+d*x),’problem’,’b,c,d’);
Error using fittype>iAssertValidVariableNames
The name ‘[b,c,d]’ is not a valid MATLAB variable name.
In the next part I use "fit" to fit the data, and specify the value of the 3 constants and starting point of the fit:
f = fit(p(1:index),q(1:index),ft,’problem’,[Qm2 b1 b2],’StartPoint’,Qm1);
Is there another way to specify constants in the fittype? I have a non-linear equation with 3 variables I wish to be constants and only 1 variable to be fitted to x,y data.
Using fittype, I have entered the equation and tried to specify b, c & d as constants. However, the options ‘problem’ only seems to allow single variables to be specified as constants
ft = fittype(@(a, b, c, d,x) a*c*x./(1+c*x) + b*d*x./(1+d*x),’problem’,’b,c,d’);
Error using fittype>iAssertValidVariableNames
The name ‘[b,c,d]’ is not a valid MATLAB variable name.
In the next part I use "fit" to fit the data, and specify the value of the 3 constants and starting point of the fit:
f = fit(p(1:index),q(1:index),ft,’problem’,[Qm2 b1 b2],’StartPoint’,Qm1);
Is there another way to specify constants in the fittype? curve fitting MATLAB Answers — New Questions
How to add Simscape Electrical in simulink
How to add Simscape Electrical in Matlab Student ?
I have Simulink, but can read or reconize electrical tools.How to add Simscape Electrical in Matlab Student ?
I have Simulink, but can read or reconize electrical tools. How to add Simscape Electrical in Matlab Student ?
I have Simulink, but can read or reconize electrical tools. simscape, electrical MATLAB Answers — New Questions
Import data does not properly
Dear all,
I moved from the R2024 to R2026 version and now when I import data it shows a very curious data representations for e.g. two column
197 0000 0000->0
196 8000 8000->1
196 6000 6000->0
196 4000 4000->0
rather than
197,0000 0,494778
196,8000 1,07849
196,6000 0,965887
196,4000 0,839238
I did ‘Set type’ to Number, but no real effect.
How can I manage it?
Thanks
Best
MarcoDear all,
I moved from the R2024 to R2026 version and now when I import data it shows a very curious data representations for e.g. two column
197 0000 0000->0
196 8000 8000->1
196 6000 6000->0
196 4000 4000->0
rather than
197,0000 0,494778
196,8000 1,07849
196,6000 0,965887
196,4000 0,839238
I did ‘Set type’ to Number, but no real effect.
How can I manage it?
Thanks
Best
Marco Dear all,
I moved from the R2024 to R2026 version and now when I import data it shows a very curious data representations for e.g. two column
197 0000 0000->0
196 8000 8000->1
196 6000 6000->0
196 4000 4000->0
rather than
197,0000 0,494778
196,8000 1,07849
196,6000 0,965887
196,4000 0,839238
I did ‘Set type’ to Number, but no real effect.
How can I manage it?
Thanks
Best
Marco data import MATLAB Answers — New Questions
Is “ZCU208” board supported for the “Streaming Data from Hardware to Software” MATLAB example?
I wanted to confirm whether the Streaming Data from Hardware to Software MATLAB example supports the "AMD XILINX Zynq UltraScale+ RFSoC ZCU208" Evaluation Kit. I noticed that the lower specification "ZCU111" is supported; does this example also work with the "ZCU208"?I wanted to confirm whether the Streaming Data from Hardware to Software MATLAB example supports the "AMD XILINX Zynq UltraScale+ RFSoC ZCU208" Evaluation Kit. I noticed that the lower specification "ZCU111" is supported; does this example also work with the "ZCU208"? I wanted to confirm whether the Streaming Data from Hardware to Software MATLAB example supports the "AMD XILINX Zynq UltraScale+ RFSoC ZCU208" Evaluation Kit. I noticed that the lower specification "ZCU111" is supported; does this example also work with the "ZCU208"? amd, xilinx, xilinxzynq, zcu208 MATLAB Answers — New Questions
Memoize an anonymous function with externally scoped variables
I am trying to memoize a function that takes an anonymous handle with an externally-scoped parameter as input. The problem is that no two anonymous functions are ever the same. Therefore, every time the memoization handle mf is invoked, it executes in its entirety and freshly cache’s the results.
mf=memoize(@subfunc);
A=3;
for i=1:4
mf(@(z)A*z)
end
I know that the Lord punisheth those who use eval(), but I can see no other alternative but to pass the anonymous function in char/string form and use evalin. This works fine when there are no externally-scoped variables. Caching indeed only occurs on the first call:
for i=1:4
mf(‘@(z)3*z’)
end
However, when the anonymous function does contain an externally-scoped variable A, the workaround fails.
A=3;
mf(‘@(z)A*z’)
So two questions,
Why does the workaround fail to find externally scoped variables?
Is there a more robust workaround?
function out = subfunc(argFun)
disp ‘Caching’
if isa(argFun,’function_handle’) %argFun is char or string
fun=argFun;
else
fun=evalin(‘caller’,argFun);
end
out=fun(5);
endI am trying to memoize a function that takes an anonymous handle with an externally-scoped parameter as input. The problem is that no two anonymous functions are ever the same. Therefore, every time the memoization handle mf is invoked, it executes in its entirety and freshly cache’s the results.
mf=memoize(@subfunc);
A=3;
for i=1:4
mf(@(z)A*z)
end
I know that the Lord punisheth those who use eval(), but I can see no other alternative but to pass the anonymous function in char/string form and use evalin. This works fine when there are no externally-scoped variables. Caching indeed only occurs on the first call:
for i=1:4
mf(‘@(z)3*z’)
end
However, when the anonymous function does contain an externally-scoped variable A, the workaround fails.
A=3;
mf(‘@(z)A*z’)
So two questions,
Why does the workaround fail to find externally scoped variables?
Is there a more robust workaround?
function out = subfunc(argFun)
disp ‘Caching’
if isa(argFun,’function_handle’) %argFun is char or string
fun=argFun;
else
fun=evalin(‘caller’,argFun);
end
out=fun(5);
end I am trying to memoize a function that takes an anonymous handle with an externally-scoped parameter as input. The problem is that no two anonymous functions are ever the same. Therefore, every time the memoization handle mf is invoked, it executes in its entirety and freshly cache’s the results.
mf=memoize(@subfunc);
A=3;
for i=1:4
mf(@(z)A*z)
end
I know that the Lord punisheth those who use eval(), but I can see no other alternative but to pass the anonymous function in char/string form and use evalin. This works fine when there are no externally-scoped variables. Caching indeed only occurs on the first call:
for i=1:4
mf(‘@(z)3*z’)
end
However, when the anonymous function does contain an externally-scoped variable A, the workaround fails.
A=3;
mf(‘@(z)A*z’)
So two questions,
Why does the workaround fail to find externally scoped variables?
Is there a more robust workaround?
function out = subfunc(argFun)
disp ‘Caching’
if isa(argFun,’function_handle’) %argFun is char or string
fun=argFun;
else
fun=evalin(‘caller’,argFun);
end
out=fun(5);
end memoize, eval, anonymous functions MATLAB Answers — New Questions
Please help me to write character in vertical axis of the run figre as in attached photo
clc;clf;clear;
myLegend1 = {};
rr = [ 0.4 0.5 0.6]
for i =1:numel(rr)
x=0:0.0001:9;
alfa= rr(i);
s=1;h=1;
L1=-0.5;L2=0.4;
c=30;
y=0.5;b=1;
k0=386; ce=3.831*10^2; mu=38.6*10^9;alfat=1.78*10^-5; rho=89.54*10^2; lamda=77.6*10^9;taw=0.5;Tnot=2.93*10^2;
c0=sqrt((lamda+2*mu)/(rho)); Betanot=(3*lamda+2*mu)*alfat; a1=mu/(lamda+2*mu);a2=(mu+lamda)/(lamda+2*mu);a3=(Betanot*Tnot)/(lamda+2*mu);omega=(rho*ce)/(k0);
a4=lamda/(lamda+2*mu);a5=(k0*omega*c0^2)/(k0);a6=(rho*ce*c0^2)/(k0);
a7=(Betanot*c0^2)/(k0); a8=a6*taw; a9=a7*taw; a10=rho*ce*taw*omega*c0^4/(k0); a11=Betanot*taw*omega*c0^4/(k0);w=rho*ce/(k0);
b1=s^2+a1*h^2-(x+y+b).^2;b2=a2*s*h;b3=0;b4=a3*s;b5=alfa*b1;b6=alfa*b2;b7=alfa*b3;b8=2*alfa*b4;
B1=b1*L1^2+b2*L2^2;B2=-b3*L1-b4;
B3=-b5*L1^2-b6*L2^2;
%B4=b7*L1+b8;
B4=B3./4;
sec= ((B1-B2)./(3*B4))-((B1-B2)./(3*B4))+c;
T=-((B1-B2)./(3*B4))+(sec).*exp(-(s*x+h*y+b));
% fprintf(‘%12.10f %15.8f rn’,-((B1-B2)./(3*B4)),(c+((B1-B2)./(3*B4))));
%fir=c+sec;
% N2=zeros(1,1);
% N2=(s*L1+a4*h*L2).*-1*(c+((B1-B2)./(3*B4))).*exp(-(s*x+h*y+b)).*(1-alfa.*T)+a3.*T.*(alfa.*T-1);
% N3=zeros(1,1);
% N3=a1*(h*L1+s*L2)*(1-alfa.*T).*(-1*(c+((B1-B2)./(3*B4))).*exp(-(s*x+h*y+b)));
figure(1)
plot(x,T)
grid on,hold on
myLegend1{i}=[‘alfa= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold onclc;clf;clear;
myLegend1 = {};
rr = [ 0.4 0.5 0.6]
for i =1:numel(rr)
x=0:0.0001:9;
alfa= rr(i);
s=1;h=1;
L1=-0.5;L2=0.4;
c=30;
y=0.5;b=1;
k0=386; ce=3.831*10^2; mu=38.6*10^9;alfat=1.78*10^-5; rho=89.54*10^2; lamda=77.6*10^9;taw=0.5;Tnot=2.93*10^2;
c0=sqrt((lamda+2*mu)/(rho)); Betanot=(3*lamda+2*mu)*alfat; a1=mu/(lamda+2*mu);a2=(mu+lamda)/(lamda+2*mu);a3=(Betanot*Tnot)/(lamda+2*mu);omega=(rho*ce)/(k0);
a4=lamda/(lamda+2*mu);a5=(k0*omega*c0^2)/(k0);a6=(rho*ce*c0^2)/(k0);
a7=(Betanot*c0^2)/(k0); a8=a6*taw; a9=a7*taw; a10=rho*ce*taw*omega*c0^4/(k0); a11=Betanot*taw*omega*c0^4/(k0);w=rho*ce/(k0);
b1=s^2+a1*h^2-(x+y+b).^2;b2=a2*s*h;b3=0;b4=a3*s;b5=alfa*b1;b6=alfa*b2;b7=alfa*b3;b8=2*alfa*b4;
B1=b1*L1^2+b2*L2^2;B2=-b3*L1-b4;
B3=-b5*L1^2-b6*L2^2;
%B4=b7*L1+b8;
B4=B3./4;
sec= ((B1-B2)./(3*B4))-((B1-B2)./(3*B4))+c;
T=-((B1-B2)./(3*B4))+(sec).*exp(-(s*x+h*y+b));
% fprintf(‘%12.10f %15.8f rn’,-((B1-B2)./(3*B4)),(c+((B1-B2)./(3*B4))));
%fir=c+sec;
% N2=zeros(1,1);
% N2=(s*L1+a4*h*L2).*-1*(c+((B1-B2)./(3*B4))).*exp(-(s*x+h*y+b)).*(1-alfa.*T)+a3.*T.*(alfa.*T-1);
% N3=zeros(1,1);
% N3=a1*(h*L1+s*L2)*(1-alfa.*T).*(-1*(c+((B1-B2)./(3*B4))).*exp(-(s*x+h*y+b)));
figure(1)
plot(x,T)
grid on,hold on
myLegend1{i}=[‘alfa= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on clc;clf;clear;
myLegend1 = {};
rr = [ 0.4 0.5 0.6]
for i =1:numel(rr)
x=0:0.0001:9;
alfa= rr(i);
s=1;h=1;
L1=-0.5;L2=0.4;
c=30;
y=0.5;b=1;
k0=386; ce=3.831*10^2; mu=38.6*10^9;alfat=1.78*10^-5; rho=89.54*10^2; lamda=77.6*10^9;taw=0.5;Tnot=2.93*10^2;
c0=sqrt((lamda+2*mu)/(rho)); Betanot=(3*lamda+2*mu)*alfat; a1=mu/(lamda+2*mu);a2=(mu+lamda)/(lamda+2*mu);a3=(Betanot*Tnot)/(lamda+2*mu);omega=(rho*ce)/(k0);
a4=lamda/(lamda+2*mu);a5=(k0*omega*c0^2)/(k0);a6=(rho*ce*c0^2)/(k0);
a7=(Betanot*c0^2)/(k0); a8=a6*taw; a9=a7*taw; a10=rho*ce*taw*omega*c0^4/(k0); a11=Betanot*taw*omega*c0^4/(k0);w=rho*ce/(k0);
b1=s^2+a1*h^2-(x+y+b).^2;b2=a2*s*h;b3=0;b4=a3*s;b5=alfa*b1;b6=alfa*b2;b7=alfa*b3;b8=2*alfa*b4;
B1=b1*L1^2+b2*L2^2;B2=-b3*L1-b4;
B3=-b5*L1^2-b6*L2^2;
%B4=b7*L1+b8;
B4=B3./4;
sec= ((B1-B2)./(3*B4))-((B1-B2)./(3*B4))+c;
T=-((B1-B2)./(3*B4))+(sec).*exp(-(s*x+h*y+b));
% fprintf(‘%12.10f %15.8f rn’,-((B1-B2)./(3*B4)),(c+((B1-B2)./(3*B4))));
%fir=c+sec;
% N2=zeros(1,1);
% N2=(s*L1+a4*h*L2).*-1*(c+((B1-B2)./(3*B4))).*exp(-(s*x+h*y+b)).*(1-alfa.*T)+a3.*T.*(alfa.*T-1);
% N3=zeros(1,1);
% N3=a1*(h*L1+s*L2)*(1-alfa.*T).*(-1*(c+((B1-B2)./(3*B4))).*exp(-(s*x+h*y+b)));
figure(1)
plot(x,T)
grid on,hold on
myLegend1{i}=[‘alfa= ‘,num2str(rr(i))];
i=i+1;
end
figure(1)
legend(myLegend1)
hold on figure MATLAB Answers — New Questions
R2025b Polyspace_Server is silently failing to install
The script below works perfectly locally on an Ubuntu mechine but it refuses to work when called in a Jenkins job.We tried both freestyle and scripted pipelines but always fails on Jenkins.
It fails in Jenkins silently without any clues in the log polyspaceServerOut/install-psserver.log has the contents of installer_input.txt but nothing after that. There is no indication of why it’s not installing the products. and the log PolyTemp/mathworks_xxx.log is empty with zero siize. I am not sure how to debug the problem with empty logs
#!/bin/bash -x
curl to download the bundle from JFrog R2025b_Polyspace_Server_Linux.zip (Works)
unzip -q R2025b_Polyspace_Server_Linux.zip (Works)
unzip -q R2025b/2025_10_06_15_25_35/matlab_R2025b_Linux.zip -d R2025b/2025_10_06_15_25_35 (Works)
mv R2025b/2025_10_06_15_25_35 polyspace_server_installer (Works)
chmod -R 755 polyspace_server_installer (Works)
export TMPDIR=<absolute_path>/PolyTemp (Works)
mkdir -p ${TMPDIR} (Works)
polyspace_server_installer/install -v -inputFile <absolute_path>/polyspace_server_installer/installer_input.txt
The file installer_input.txt has the following entries
agreeToLicense = yes
product.Polyspace_Bug_Finder_Server
product.Polyspace_Code_Prover_Server
mode = silent
fileInstallationKey = XXXXX-XXXXX-XXXXX-XXXXX
licensePath = <absolute_path>/polyspaceServer.lic
destinationFolder = <absolute_path>/polyspaceServer
outputFile = <absolute_path>/polyspaceServerOut/install-psserver.log
improveMATLAB = no
The file polyspaceServer.lic has the following entries
SERVER <host_server> XXXXXXXXXXXX XXXX
USE_SERVER
P.S. The exact same commands currently work fine locally and in Jenkins for 2024bThe script below works perfectly locally on an Ubuntu mechine but it refuses to work when called in a Jenkins job.We tried both freestyle and scripted pipelines but always fails on Jenkins.
It fails in Jenkins silently without any clues in the log polyspaceServerOut/install-psserver.log has the contents of installer_input.txt but nothing after that. There is no indication of why it’s not installing the products. and the log PolyTemp/mathworks_xxx.log is empty with zero siize. I am not sure how to debug the problem with empty logs
#!/bin/bash -x
curl to download the bundle from JFrog R2025b_Polyspace_Server_Linux.zip (Works)
unzip -q R2025b_Polyspace_Server_Linux.zip (Works)
unzip -q R2025b/2025_10_06_15_25_35/matlab_R2025b_Linux.zip -d R2025b/2025_10_06_15_25_35 (Works)
mv R2025b/2025_10_06_15_25_35 polyspace_server_installer (Works)
chmod -R 755 polyspace_server_installer (Works)
export TMPDIR=<absolute_path>/PolyTemp (Works)
mkdir -p ${TMPDIR} (Works)
polyspace_server_installer/install -v -inputFile <absolute_path>/polyspace_server_installer/installer_input.txt
The file installer_input.txt has the following entries
agreeToLicense = yes
product.Polyspace_Bug_Finder_Server
product.Polyspace_Code_Prover_Server
mode = silent
fileInstallationKey = XXXXX-XXXXX-XXXXX-XXXXX
licensePath = <absolute_path>/polyspaceServer.lic
destinationFolder = <absolute_path>/polyspaceServer
outputFile = <absolute_path>/polyspaceServerOut/install-psserver.log
improveMATLAB = no
The file polyspaceServer.lic has the following entries
SERVER <host_server> XXXXXXXXXXXX XXXX
USE_SERVER
P.S. The exact same commands currently work fine locally and in Jenkins for 2024b The script below works perfectly locally on an Ubuntu mechine but it refuses to work when called in a Jenkins job.We tried both freestyle and scripted pipelines but always fails on Jenkins.
It fails in Jenkins silently without any clues in the log polyspaceServerOut/install-psserver.log has the contents of installer_input.txt but nothing after that. There is no indication of why it’s not installing the products. and the log PolyTemp/mathworks_xxx.log is empty with zero siize. I am not sure how to debug the problem with empty logs
#!/bin/bash -x
curl to download the bundle from JFrog R2025b_Polyspace_Server_Linux.zip (Works)
unzip -q R2025b_Polyspace_Server_Linux.zip (Works)
unzip -q R2025b/2025_10_06_15_25_35/matlab_R2025b_Linux.zip -d R2025b/2025_10_06_15_25_35 (Works)
mv R2025b/2025_10_06_15_25_35 polyspace_server_installer (Works)
chmod -R 755 polyspace_server_installer (Works)
export TMPDIR=<absolute_path>/PolyTemp (Works)
mkdir -p ${TMPDIR} (Works)
polyspace_server_installer/install -v -inputFile <absolute_path>/polyspace_server_installer/installer_input.txt
The file installer_input.txt has the following entries
agreeToLicense = yes
product.Polyspace_Bug_Finder_Server
product.Polyspace_Code_Prover_Server
mode = silent
fileInstallationKey = XXXXX-XXXXX-XXXXX-XXXXX
licensePath = <absolute_path>/polyspaceServer.lic
destinationFolder = <absolute_path>/polyspaceServer
outputFile = <absolute_path>/polyspaceServerOut/install-psserver.log
improveMATLAB = no
The file polyspaceServer.lic has the following entries
SERVER <host_server> XXXXXXXXXXXX XXXX
USE_SERVER
P.S. The exact same commands currently work fine locally and in Jenkins for 2024b installation, bug finder server, code prover server MATLAB Answers — New Questions
Find x values where y values are the same from a set of data.
I have 2 datasets from a continuous signal that will display a voltage in 1 set of data (D8) and repeat that voltage in data set D2 after a randomized delay. I need to find the voltage and time these repetitions occur, but I’m unsure of how to do that.
My code finds these repetitions, removes where the 2 datasets intercept as there’s no delay going on there, and displays the time of the repetitions. I need the original voltage, the original time from D8, and the delayed time in D2 when the repeated value occurs.
data = load(‘DatasSet2_Test.txt’); %my directory is different but it includes my name so it just calls the attached file
%Characterize columns
t1 = data(:,1)/1000; %convert time from ms to s
%convert from bits to V
resolution = 2^10-1;
%Data as assigned pairs *10^8 to transfer within the MeV to GeV range
D1 = (data(:,2)*5)/resolution*10^8; D2 = (data(:,3)*5)/resolution*10^8;
D3 = (data(:,4)*5)/resolution*10^8; D4 = (data(:,5)*5)/resolution*10^8;
D5 = (data(:,6)*5)/resolution*10^8; D6 = (data(:,7)*5)/resolution*10^8;
D7 = (data(:,8)*5)/resolution*10^8; D8 = (data(:,9)*5)/resolution*10^8; %all in V
c1 = D8(:)==D2 %finds same voltage indep of time occuring
x1values1 = t1(find(c1)); %Gives time of repeated values
r1usure1 = t1(find(intersect(D8,D2))); %checks for intersections as they don’t include delay
l1 = setdiff(x1values1, r1usure1); %Gives time of repeated values excluding intersections
This is the code I have so far, but it only checks for similar values and returns repeated time values instead of including the original time, and I’ve been struggling to find the associated voltages. I have also attached the file with the signals where the first column is time, column 3 is D2 in V, and column 9 is D8 in V.
This might not be well explained so I will answer questions as quickly as possible. Thank you in advance !I have 2 datasets from a continuous signal that will display a voltage in 1 set of data (D8) and repeat that voltage in data set D2 after a randomized delay. I need to find the voltage and time these repetitions occur, but I’m unsure of how to do that.
My code finds these repetitions, removes where the 2 datasets intercept as there’s no delay going on there, and displays the time of the repetitions. I need the original voltage, the original time from D8, and the delayed time in D2 when the repeated value occurs.
data = load(‘DatasSet2_Test.txt’); %my directory is different but it includes my name so it just calls the attached file
%Characterize columns
t1 = data(:,1)/1000; %convert time from ms to s
%convert from bits to V
resolution = 2^10-1;
%Data as assigned pairs *10^8 to transfer within the MeV to GeV range
D1 = (data(:,2)*5)/resolution*10^8; D2 = (data(:,3)*5)/resolution*10^8;
D3 = (data(:,4)*5)/resolution*10^8; D4 = (data(:,5)*5)/resolution*10^8;
D5 = (data(:,6)*5)/resolution*10^8; D6 = (data(:,7)*5)/resolution*10^8;
D7 = (data(:,8)*5)/resolution*10^8; D8 = (data(:,9)*5)/resolution*10^8; %all in V
c1 = D8(:)==D2 %finds same voltage indep of time occuring
x1values1 = t1(find(c1)); %Gives time of repeated values
r1usure1 = t1(find(intersect(D8,D2))); %checks for intersections as they don’t include delay
l1 = setdiff(x1values1, r1usure1); %Gives time of repeated values excluding intersections
This is the code I have so far, but it only checks for similar values and returns repeated time values instead of including the original time, and I’ve been struggling to find the associated voltages. I have also attached the file with the signals where the first column is time, column 3 is D2 in V, and column 9 is D8 in V.
This might not be well explained so I will answer questions as quickly as possible. Thank you in advance ! I have 2 datasets from a continuous signal that will display a voltage in 1 set of data (D8) and repeat that voltage in data set D2 after a randomized delay. I need to find the voltage and time these repetitions occur, but I’m unsure of how to do that.
My code finds these repetitions, removes where the 2 datasets intercept as there’s no delay going on there, and displays the time of the repetitions. I need the original voltage, the original time from D8, and the delayed time in D2 when the repeated value occurs.
data = load(‘DatasSet2_Test.txt’); %my directory is different but it includes my name so it just calls the attached file
%Characterize columns
t1 = data(:,1)/1000; %convert time from ms to s
%convert from bits to V
resolution = 2^10-1;
%Data as assigned pairs *10^8 to transfer within the MeV to GeV range
D1 = (data(:,2)*5)/resolution*10^8; D2 = (data(:,3)*5)/resolution*10^8;
D3 = (data(:,4)*5)/resolution*10^8; D4 = (data(:,5)*5)/resolution*10^8;
D5 = (data(:,6)*5)/resolution*10^8; D6 = (data(:,7)*5)/resolution*10^8;
D7 = (data(:,8)*5)/resolution*10^8; D8 = (data(:,9)*5)/resolution*10^8; %all in V
c1 = D8(:)==D2 %finds same voltage indep of time occuring
x1values1 = t1(find(c1)); %Gives time of repeated values
r1usure1 = t1(find(intersect(D8,D2))); %checks for intersections as they don’t include delay
l1 = setdiff(x1values1, r1usure1); %Gives time of repeated values excluding intersections
This is the code I have so far, but it only checks for similar values and returns repeated time values instead of including the original time, and I’ve been struggling to find the associated voltages. I have also attached the file with the signals where the first column is time, column 3 is D2 in V, and column 9 is D8 in V.
This might not be well explained so I will answer questions as quickly as possible. Thank you in advance ! indexing, find function, repeated values MATLAB Answers — New Questions
Very slow graphics when mouse pointer moves around a figure
I’ve got a little widget that animates a sequence of images by calling the "image()" function repeatedly with new images in a sequence. Normally the animation proceeds reasonably fast around 50-60 frames per second. However, if the mouse is in the figure window and moves around (not even clicking on anything), then the animation slows to a crawl (about 2-3 frames per second) as long as the mouse moves in the figure window. (See code at bottom for simple example to replicate this).
I’ve checked to ensure that the ‘WindowButtonMotionFcn’ figure callback is disabled (as are all other figure callbacks). I can’t find any other figure, axes or even image objects that might be triggered by mouse motion in the figure window.
If I run the profiler and compare results with and without the mouse moving around the figure window, I see the function:
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
(and its dependent functions ) is getting called thousands of times and is consuming 90% of the runtime when the mouse is moving around I tried turning off both the figure’s toolbar and the figure’s menu bar, e.g:
hFigure.ToolBar = ‘none’;
hFigure.MenuBar = ‘none’;
and that slightly alleviates the issue somewhat, but not much (perhaps 10-20% better) . Further, even with the toolbars turned off, the profiler still indicates that
ToolbarController.ToolbarController>@obj.handleMouseMotion
is still consuming 90% of the run time whenever the mouse is moving around. There also is the function
AxesToolbarButton.AxesToolbarButton>AxesToolbarButton.AxesToolbarButton
that is also getting called thousands of times and is consuming some of the time. So I also disable the AxesToolbar by:
axesTB = get(hAxes,’ToolBar’);
axesTB.visible = ‘off’;
axesTB.BusyAction = ‘cancel’;
(Unlike the figure toolbar, there doesn’t seem a setting to completely disable a AxesToolbar). Anyway, turning off the axesTB didn’t seem to help.
% This code can be used to illustrate the issue of slowly updating graphics.
% Run this, and then move the mouse around the figure window.
for loop=1:500
image(rand(300,300),’CDataMapping’,’scaled’);
drawnow;
end
%Clearing the axes with "cla" before the image() call doesn’t change the result. However, this version of the code is seemingly NOT impacted by this issue or very little:
hImg = image(rand(300,300),’CDataMapping’,’scaled’);
for loop=1:500
hImg.CData = rand(300,300);
drawnow;
end
In the latter case, the profiler say that the function
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
still gets called a whole bunch of times but it ends up only consuming about 15% of the runtime (not 90+%), and the animation proceeds at 50+ FPS. So there is something about the combination of a moving mouse and creating new objects (rather than changing attributes of existing objects) that seems to grind matlab graphics to a halt. While I clearly point out a workaround for my little example above, in the general case, such workarounds are not always possible. It seems odd that moving a mouse while drawing objects in a figure shouldn’t necessarily slow down things as much as it appears to do.
Thoughts appreciated.I’ve got a little widget that animates a sequence of images by calling the "image()" function repeatedly with new images in a sequence. Normally the animation proceeds reasonably fast around 50-60 frames per second. However, if the mouse is in the figure window and moves around (not even clicking on anything), then the animation slows to a crawl (about 2-3 frames per second) as long as the mouse moves in the figure window. (See code at bottom for simple example to replicate this).
I’ve checked to ensure that the ‘WindowButtonMotionFcn’ figure callback is disabled (as are all other figure callbacks). I can’t find any other figure, axes or even image objects that might be triggered by mouse motion in the figure window.
If I run the profiler and compare results with and without the mouse moving around the figure window, I see the function:
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
(and its dependent functions ) is getting called thousands of times and is consuming 90% of the runtime when the mouse is moving around I tried turning off both the figure’s toolbar and the figure’s menu bar, e.g:
hFigure.ToolBar = ‘none’;
hFigure.MenuBar = ‘none’;
and that slightly alleviates the issue somewhat, but not much (perhaps 10-20% better) . Further, even with the toolbars turned off, the profiler still indicates that
ToolbarController.ToolbarController>@obj.handleMouseMotion
is still consuming 90% of the run time whenever the mouse is moving around. There also is the function
AxesToolbarButton.AxesToolbarButton>AxesToolbarButton.AxesToolbarButton
that is also getting called thousands of times and is consuming some of the time. So I also disable the AxesToolbar by:
axesTB = get(hAxes,’ToolBar’);
axesTB.visible = ‘off’;
axesTB.BusyAction = ‘cancel’;
(Unlike the figure toolbar, there doesn’t seem a setting to completely disable a AxesToolbar). Anyway, turning off the axesTB didn’t seem to help.
% This code can be used to illustrate the issue of slowly updating graphics.
% Run this, and then move the mouse around the figure window.
for loop=1:500
image(rand(300,300),’CDataMapping’,’scaled’);
drawnow;
end
%Clearing the axes with "cla" before the image() call doesn’t change the result. However, this version of the code is seemingly NOT impacted by this issue or very little:
hImg = image(rand(300,300),’CDataMapping’,’scaled’);
for loop=1:500
hImg.CData = rand(300,300);
drawnow;
end
In the latter case, the profiler say that the function
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
still gets called a whole bunch of times but it ends up only consuming about 15% of the runtime (not 90+%), and the animation proceeds at 50+ FPS. So there is something about the combination of a moving mouse and creating new objects (rather than changing attributes of existing objects) that seems to grind matlab graphics to a halt. While I clearly point out a workaround for my little example above, in the general case, such workarounds are not always possible. It seems odd that moving a mouse while drawing objects in a figure shouldn’t necessarily slow down things as much as it appears to do.
Thoughts appreciated. I’ve got a little widget that animates a sequence of images by calling the "image()" function repeatedly with new images in a sequence. Normally the animation proceeds reasonably fast around 50-60 frames per second. However, if the mouse is in the figure window and moves around (not even clicking on anything), then the animation slows to a crawl (about 2-3 frames per second) as long as the mouse moves in the figure window. (See code at bottom for simple example to replicate this).
I’ve checked to ensure that the ‘WindowButtonMotionFcn’ figure callback is disabled (as are all other figure callbacks). I can’t find any other figure, axes or even image objects that might be triggered by mouse motion in the figure window.
If I run the profiler and compare results with and without the mouse moving around the figure window, I see the function:
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
(and its dependent functions ) is getting called thousands of times and is consuming 90% of the runtime when the mouse is moving around I tried turning off both the figure’s toolbar and the figure’s menu bar, e.g:
hFigure.ToolBar = ‘none’;
hFigure.MenuBar = ‘none’;
and that slightly alleviates the issue somewhat, but not much (perhaps 10-20% better) . Further, even with the toolbars turned off, the profiler still indicates that
ToolbarController.ToolbarController>@obj.handleMouseMotion
is still consuming 90% of the run time whenever the mouse is moving around. There also is the function
AxesToolbarButton.AxesToolbarButton>AxesToolbarButton.AxesToolbarButton
that is also getting called thousands of times and is consuming some of the time. So I also disable the AxesToolbar by:
axesTB = get(hAxes,’ToolBar’);
axesTB.visible = ‘off’;
axesTB.BusyAction = ‘cancel’;
(Unlike the figure toolbar, there doesn’t seem a setting to completely disable a AxesToolbar). Anyway, turning off the axesTB didn’t seem to help.
% This code can be used to illustrate the issue of slowly updating graphics.
% Run this, and then move the mouse around the figure window.
for loop=1:500
image(rand(300,300),’CDataMapping’,’scaled’);
drawnow;
end
%Clearing the axes with "cla" before the image() call doesn’t change the result. However, this version of the code is seemingly NOT impacted by this issue or very little:
hImg = image(rand(300,300),’CDataMapping’,’scaled’);
for loop=1:500
hImg.CData = rand(300,300);
drawnow;
end
In the latter case, the profiler say that the function
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
still gets called a whole bunch of times but it ends up only consuming about 15% of the runtime (not 90+%), and the animation proceeds at 50+ FPS. So there is something about the combination of a moving mouse and creating new objects (rather than changing attributes of existing objects) that seems to grind matlab graphics to a halt. While I clearly point out a workaround for my little example above, in the general case, such workarounds are not always possible. It seems odd that moving a mouse while drawing objects in a figure shouldn’t necessarily slow down things as much as it appears to do.
Thoughts appreciated. slow graphics, mouse motion MATLAB Answers — New Questions









