Author: PuTI
C-Caller crash with Matlab 2025a
I have many models which uses C-Callers and they work properly in accelerator mode with matlab 2024b and previous.
With Matlab 2025a almost all these models crash when I run them. "Validate custom code" runs fine, but when I run the model it crash. In normal as it should be it doesn’t crash.
The issue is located into the C-caller of course, but I never had problems until R2025a.
Do you have similar issues? Any advices?
Many thanks in advanced.
DI have many models which uses C-Callers and they work properly in accelerator mode with matlab 2024b and previous.
With Matlab 2025a almost all these models crash when I run them. "Validate custom code" runs fine, but when I run the model it crash. In normal as it should be it doesn’t crash.
The issue is located into the C-caller of course, but I never had problems until R2025a.
Do you have similar issues? Any advices?
Many thanks in advanced.
D I have many models which uses C-Callers and they work properly in accelerator mode with matlab 2024b and previous.
With Matlab 2025a almost all these models crash when I run them. "Validate custom code" runs fine, but when I run the model it crash. In normal as it should be it doesn’t crash.
The issue is located into the C-caller of course, but I never had problems until R2025a.
Do you have similar issues? Any advices?
Many thanks in advanced.
D c-caller, simscape MATLAB Answers — New Questions
How does the Compare To Constant block in Simulink choose type of the Constant value, and what are the implications for fixed-point operations?
How can I detect and address questionable fixed-point operations in Compare To Constant block?
This example model generates code that does not function as intended. It appears that value 15 is cast to fixdt(1,8,-5) as sfix8_E5, and quantized to zero.How can I detect and address questionable fixed-point operations in Compare To Constant block?
This example model generates code that does not function as intended. It appears that value 15 is cast to fixdt(1,8,-5) as sfix8_E5, and quantized to zero. How can I detect and address questionable fixed-point operations in Compare To Constant block?
This example model generates code that does not function as intended. It appears that value 15 is cast to fixdt(1,8,-5) as sfix8_E5, and quantized to zero. fixed point, data type rules MATLAB Answers — New Questions
Problems with quiver plot
Hey!
I try to create a quiver plot with unequl axis length. I’ like to have the arrows the same length, which somehow does not want to work.
Any ideas?
Thanks!
%% system paramters
eta = .1;
mu = .1;
nu = 1;
gamma = 2;
%% dependent variables
roi = 2;
s = linspace(max([(1-roi)*s_0,0]),(1+roi)*s_0,10);
p = linspace(max([(1-roi)*p_0,0]),(1+roi)*p_0,10);
[s,p] = meshgrid(s,p);
%% gradient flow
v = s.*p.^gamma ./ (1+(1+s).*p.^gamma);
ds = -v + eta;
dp = mu*(v – nu*p);
mag = sqrt(ds.^2 + dp.^2);
arrow_scale = 3E-1;
norm_ds = arrow_scale*ds./mag;
norm_dp = arrow_scale*dp./mag;
%% plot
q = quiver(s,p,norm_ds,norm_dp,’Autoscale’,’off’, ‘Color’,.6*[1,1,1]);
q.ShowArrowHead = ‘off’;
q.Marker = ‘.’;Hey!
I try to create a quiver plot with unequl axis length. I’ like to have the arrows the same length, which somehow does not want to work.
Any ideas?
Thanks!
%% system paramters
eta = .1;
mu = .1;
nu = 1;
gamma = 2;
%% dependent variables
roi = 2;
s = linspace(max([(1-roi)*s_0,0]),(1+roi)*s_0,10);
p = linspace(max([(1-roi)*p_0,0]),(1+roi)*p_0,10);
[s,p] = meshgrid(s,p);
%% gradient flow
v = s.*p.^gamma ./ (1+(1+s).*p.^gamma);
ds = -v + eta;
dp = mu*(v – nu*p);
mag = sqrt(ds.^2 + dp.^2);
arrow_scale = 3E-1;
norm_ds = arrow_scale*ds./mag;
norm_dp = arrow_scale*dp./mag;
%% plot
q = quiver(s,p,norm_ds,norm_dp,’Autoscale’,’off’, ‘Color’,.6*[1,1,1]);
q.ShowArrowHead = ‘off’;
q.Marker = ‘.’; Hey!
I try to create a quiver plot with unequl axis length. I’ like to have the arrows the same length, which somehow does not want to work.
Any ideas?
Thanks!
%% system paramters
eta = .1;
mu = .1;
nu = 1;
gamma = 2;
%% dependent variables
roi = 2;
s = linspace(max([(1-roi)*s_0,0]),(1+roi)*s_0,10);
p = linspace(max([(1-roi)*p_0,0]),(1+roi)*p_0,10);
[s,p] = meshgrid(s,p);
%% gradient flow
v = s.*p.^gamma ./ (1+(1+s).*p.^gamma);
ds = -v + eta;
dp = mu*(v – nu*p);
mag = sqrt(ds.^2 + dp.^2);
arrow_scale = 3E-1;
norm_ds = arrow_scale*ds./mag;
norm_dp = arrow_scale*dp./mag;
%% plot
q = quiver(s,p,norm_ds,norm_dp,’Autoscale’,’off’, ‘Color’,.6*[1,1,1]);
q.ShowArrowHead = ‘off’;
q.Marker = ‘.’; quiver, plot MATLAB Answers — New Questions
Why Does Answers Run Code in 2025a But the Run Button, the “Executing In” Popup, and the “Ran In” Tag Still Show 2024b?
verver ver answers version MATLAB Answers — New Questions
Function requires a Toolbox for which you do not have a license
Up until today, I have been using my scripts without any issues. These scripts rely on a number of functions associated with certain toolboxes (for example, the tdfread function, which belongs to the Statistics and Machine Learning Toolbox). However, all of a sudden, MATLAB no longer allows me to run these scripts, as it tells me I do not have access to these functions.
It seems the reason is that I do not have a license for these toolboxes. Still, I have been able to use them without any problem until now, and my account is linked to an academic institution that supposedly has licenses for all of these toolboxes.
Could you please tell me what might be happening?Up until today, I have been using my scripts without any issues. These scripts rely on a number of functions associated with certain toolboxes (for example, the tdfread function, which belongs to the Statistics and Machine Learning Toolbox). However, all of a sudden, MATLAB no longer allows me to run these scripts, as it tells me I do not have access to these functions.
It seems the reason is that I do not have a license for these toolboxes. Still, I have been able to use them without any problem until now, and my account is linked to an academic institution that supposedly has licenses for all of these toolboxes.
Could you please tell me what might be happening? Up until today, I have been using my scripts without any issues. These scripts rely on a number of functions associated with certain toolboxes (for example, the tdfread function, which belongs to the Statistics and Machine Learning Toolbox). However, all of a sudden, MATLAB no longer allows me to run these scripts, as it tells me I do not have access to these functions.
It seems the reason is that I do not have a license for these toolboxes. Still, I have been able to use them without any problem until now, and my account is linked to an academic institution that supposedly has licenses for all of these toolboxes.
Could you please tell me what might be happening? license, toolkits, functions MATLAB Answers — New Questions
How can I change the fontsize of datatip box?
<</matlabcentral/answers/uploaded_files/108002/matlab.png>>
I mean the font size of x:5 and y:-12.38
Thanks in advance<</matlabcentral/answers/uploaded_files/108002/matlab.png>>
I mean the font size of x:5 and y:-12.38
Thanks in advance <</matlabcentral/answers/uploaded_files/108002/matlab.png>>
I mean the font size of x:5 and y:-12.38
Thanks in advance datatip, fontsize MATLAB Answers — New Questions
R2025a exportgraphics new behavior for PDF export
I use to export figure to PDF using the following code :
exportgraphics(fig, [ savepath ‘fig_name.pdf’], ‘ContentType’, ‘vector’);
It contains both plots and imagesc in subplots.
In Matlab R2024b, the exported PDF would look smooth even zooming in -> vector graphic confirmed. Or good enough let’s say: I’ve heard that imagesc figures can’t be vectorized in a proper way anyway.
In Matlab R2025a, the plots are ok, the imagesc are very blured, even if I specify dpi = 600 in the exportgraphic function.
So I’m guessing the behaviour of that function have changed.
Anyone has any input about this ?
How can I have the same result as in R2024b in R2025a is my question.I use to export figure to PDF using the following code :
exportgraphics(fig, [ savepath ‘fig_name.pdf’], ‘ContentType’, ‘vector’);
It contains both plots and imagesc in subplots.
In Matlab R2024b, the exported PDF would look smooth even zooming in -> vector graphic confirmed. Or good enough let’s say: I’ve heard that imagesc figures can’t be vectorized in a proper way anyway.
In Matlab R2025a, the plots are ok, the imagesc are very blured, even if I specify dpi = 600 in the exportgraphic function.
So I’m guessing the behaviour of that function have changed.
Anyone has any input about this ?
How can I have the same result as in R2024b in R2025a is my question. I use to export figure to PDF using the following code :
exportgraphics(fig, [ savepath ‘fig_name.pdf’], ‘ContentType’, ‘vector’);
It contains both plots and imagesc in subplots.
In Matlab R2024b, the exported PDF would look smooth even zooming in -> vector graphic confirmed. Or good enough let’s say: I’ve heard that imagesc figures can’t be vectorized in a proper way anyway.
In Matlab R2025a, the plots are ok, the imagesc are very blured, even if I specify dpi = 600 in the exportgraphic function.
So I’m guessing the behaviour of that function have changed.
Anyone has any input about this ?
How can I have the same result as in R2024b in R2025a is my question. exportgraphic, pdf, r2025a MATLAB Answers — New Questions
making a custom way to train CNNs, and I am noticing that avgpool is SIGNIFICANTLY faster than maxpool in forward and backwards passes…
I’m designing a custom training procedure for a CNN that is different from backpropagation in that I use manual update rules for layers or sets of layers. I’m studying my gradient for two types of layers: “conv + actfun + maxpool”, and “conv + actfun + avgpool”, which are identical layers except the last action is a different pooling type.
I compared the two layer types with identical data dimension sizes to see the time differences between maxpool and avgpool, both in the forward pass and the backwards pass of the pooling layers. All other steps in calculating the gradient were exactly the same between the two layers, and showed the same time costs in the two layers. But when looking at time costs specifically of the pooling operations’ forward and backwards passes, I get significantly different times (average of 5000 runs of the gradient, each measurement is in milliseconds):
gradient step | AvgPool | MaxPool | Difference
————————–|———|———|———-
pooling (forward pass) | 0.4165 | 38.6316 | +38.2151
unpooling (backward pass) | 9.9468 | 46.1667 | +36.2199
For reference, all my data arrays are dlarrays on the GPU (gpuArrays in dlarrays), all single precision, and the pooling operations convert 32 by 32 feature maps (across 2 channels and 16384 batch size) to 16 by 16 feature maps (of same # channels and batch size), so just a 2 by 2 pooling operation.
You can see here that the maxpool forward pass (using “maxpool” function) is about 92 times slower than the avgpool forward pass (using “avgpool”), and the maxpool backward pass (using “maxunpool”) is about 4.6 times slower than the avgpool backward pass (using a custom “avgunpool” function that Anthropic’s Claude had to create for me, since matlab has no “avgunpool”).
These results are extremely suspect to me. For the forwards pass, comparing matlab’s built in "maxpool" to built in "avgpool" functions gives a 92x difference, but searching online people seem to instead claim that training max pooling is supposed to be faster than avg pooling, which contradicts the results here.
For simplicity, see the code example below that runs just "maxpool" and "avgpool" only (no other functions) and compares their times:
function analyze_pooling_timing()
% GPU setup
g = gpuDevice();
fprintf(‘GPU: %sn’, g.Name);
% Parameters matching your test
H_in = 32; W_in = 32; C_in = 3; C_out = 2;
N = 16384; % batch size. Try N = 32 small or N = 16384 big
kH = 3; kW = 3;
pool_params.pool_size = [2, 2];
pool_params.pool_stride = [2, 2];
pool_params.pool_padding = 0;
conv_params.stride = [1, 1];
conv_params.padding = ‘same’;
conv_params.dilation = [1, 1];
% Initialize data
Wj = dlarray(gpuArray(single(randn(kH, kW, C_in, C_out) * 0.01)), ‘SSCU’);
Bj = dlarray(gpuArray(single(zeros(C_out, 1))), ‘C’);
Fjmin1 = dlarray(gpuArray(single(randn(H_in, W_in, C_in, N))), ‘SSCB’);
% Number of iterations for averaging
num_iter = 100;
fprintf(‘Running %d iterations for each timing measurement…nn’, num_iter);
%% setup everything in forward pass before the pooling:
% Forward convolution
Sj = dlconv(Fjmin1, Wj, Bj, …
‘Stride’, conv_params.stride, …
‘Padding’, conv_params.padding, …
‘DilationFactor’, conv_params.dilation);
% activation function (and derivative)
Oj = max(Sj, 0); Fprimej = sign(Oj);
%% Time AVERAGE POOLING
fprintf(‘=== AVERAGE POOLING (conv_af_ap) ===n’);
times_ap = struct();
for iter = 1:num_iter
% Average pooling
tic;
Oj_pooled = avgpool(Oj, pool_params.pool_size, …
‘Stride’, pool_params.pool_stride, …
‘Padding’, pool_params.pool_padding);
wait(g);
times_ap.pooling(iter) = toc;
end
%% Time MAX POOLING
fprintf(‘n=== MAX POOLING (conv_af_mp) ===n’);
times_mp = struct();
for iter = 1:num_iter
% Max pooling with indices
tic;
[Oj_pooled, max_indices] = maxpool(Oj, pool_params.pool_size, …
‘Stride’, pool_params.pool_stride, …
‘Padding’, pool_params.pool_padding);
wait(g);
times_mp.pooling(iter) = toc;
end
%% Compute statistics and display results
fprintf(‘n=== TIMING RESULTS (milliseconds) ===n’);
fprintf(‘%-25s %12s %12s %12sn’, ‘Step’, ‘AvgPool’, ‘MaxPool’, ‘Difference’);
fprintf(‘%sn’, repmat(‘-‘, 1, 65));
steps_common = { ‘pooling’};
total_ap = 0;
total_mp = 0;
for i = 1:length(steps_common)
step = steps_common{i};
if isfield(times_ap, step) && isfield(times_mp, step)
mean_ap = mean(times_ap.(step)) * 1000; % times 1000 to convert seconds to milliseconds
mean_mp = mean(times_mp.(step)) * 1000; % times 1000 to convert seconds to milliseconds
total_ap = total_ap + mean_ap;
total_mp = total_mp + mean_mp;
diff = mean_mp – mean_ap;
fprintf(‘%-25s %12.4f %12.4f %+12.4fn’, step, mean_ap, mean_mp, diff);
end
end
fprintf(‘%sn’, repmat(‘-‘, 1, 65));
%fprintf(‘%-25s %12.4f %12.4f %+12.4fn’, ‘TOTAL’, total_ap, total_mp, total_mp – total_ap);
fprintf(‘%-25s %12s %12s %12.2fxn’, ‘Speedup’, ”, ”, total_mp/total_ap);
end
Now you can see one main difference between my calling of maxpool and avgpool: for avgpool I only have 1 output (the pooled values), but with maxpool I have 2 outputs (the pooled values, and the index locations of these max values).
This is important because if I replaced the call to maxpool with only requesting the pooled values (1 output), maxpool is faster as expected:
>> analyze_pooling_timing
GPU: NVIDIA GeForce RTX 5080
Running 1000 iterations for each timing measurement…
=== AVERAGE POOLING (conv_af_ap) ===
=== MAX POOLING (conv_af_mp) ===
=== TIMING RESULTS (milliseconds) ===
Step AvgPool MaxPool Difference
—————————————————————–
pooling 0.4358 0.2330 -0.2028
—————————————————————–
max/avg 0.53x
>>
However if I call maxpool like here with 2 outputs (pooled values and indices), or with 3 outputs (pooled values, indices, and inputSize), this is where maxpool is extremely slow:
>> analyze_pooling_timing
GPU: NVIDIA GeForce RTX 5080
Running 1000 iterations for each timing measurement…
=== AVERAGE POOLING (conv_af_ap) ===
=== MAX POOLING (conv_af_mp) ===
=== TIMING RESULTS (milliseconds) ===
Step AvgPool MaxPool Difference
—————————————————————–
pooling 0.4153 38.9818 +38.5665
—————————————————————–
max/avg 93.86x
>>
So it appears that this is the reason why maxpool is so much slower: requesting the maxpool function to also output the indices leads to a massive slowdown.
Unfortunately, the indices are needed to later differentiate (backwards pass) the maxpool layer… so I need the indices…
I’d assume that whenever someone wants to train a CNN in matlab using a maxpool layer, they would have to call maxpool with indices, and thus I’d expect a similar slowdown…
Can anyone here comment on this? My application needs me to train maxpool layers, so I need to both forward pass and backwards pass through them, thus I need these indices. But it appears that matlab’s version of maxpool may not be the best implementation of a maxpool operation… maybe some inefficient processes regarding obtaining the indices?I’m designing a custom training procedure for a CNN that is different from backpropagation in that I use manual update rules for layers or sets of layers. I’m studying my gradient for two types of layers: “conv + actfun + maxpool”, and “conv + actfun + avgpool”, which are identical layers except the last action is a different pooling type.
I compared the two layer types with identical data dimension sizes to see the time differences between maxpool and avgpool, both in the forward pass and the backwards pass of the pooling layers. All other steps in calculating the gradient were exactly the same between the two layers, and showed the same time costs in the two layers. But when looking at time costs specifically of the pooling operations’ forward and backwards passes, I get significantly different times (average of 5000 runs of the gradient, each measurement is in milliseconds):
gradient step | AvgPool | MaxPool | Difference
————————–|———|———|———-
pooling (forward pass) | 0.4165 | 38.6316 | +38.2151
unpooling (backward pass) | 9.9468 | 46.1667 | +36.2199
For reference, all my data arrays are dlarrays on the GPU (gpuArrays in dlarrays), all single precision, and the pooling operations convert 32 by 32 feature maps (across 2 channels and 16384 batch size) to 16 by 16 feature maps (of same # channels and batch size), so just a 2 by 2 pooling operation.
You can see here that the maxpool forward pass (using “maxpool” function) is about 92 times slower than the avgpool forward pass (using “avgpool”), and the maxpool backward pass (using “maxunpool”) is about 4.6 times slower than the avgpool backward pass (using a custom “avgunpool” function that Anthropic’s Claude had to create for me, since matlab has no “avgunpool”).
These results are extremely suspect to me. For the forwards pass, comparing matlab’s built in "maxpool" to built in "avgpool" functions gives a 92x difference, but searching online people seem to instead claim that training max pooling is supposed to be faster than avg pooling, which contradicts the results here.
For simplicity, see the code example below that runs just "maxpool" and "avgpool" only (no other functions) and compares their times:
function analyze_pooling_timing()
% GPU setup
g = gpuDevice();
fprintf(‘GPU: %sn’, g.Name);
% Parameters matching your test
H_in = 32; W_in = 32; C_in = 3; C_out = 2;
N = 16384; % batch size. Try N = 32 small or N = 16384 big
kH = 3; kW = 3;
pool_params.pool_size = [2, 2];
pool_params.pool_stride = [2, 2];
pool_params.pool_padding = 0;
conv_params.stride = [1, 1];
conv_params.padding = ‘same’;
conv_params.dilation = [1, 1];
% Initialize data
Wj = dlarray(gpuArray(single(randn(kH, kW, C_in, C_out) * 0.01)), ‘SSCU’);
Bj = dlarray(gpuArray(single(zeros(C_out, 1))), ‘C’);
Fjmin1 = dlarray(gpuArray(single(randn(H_in, W_in, C_in, N))), ‘SSCB’);
% Number of iterations for averaging
num_iter = 100;
fprintf(‘Running %d iterations for each timing measurement…nn’, num_iter);
%% setup everything in forward pass before the pooling:
% Forward convolution
Sj = dlconv(Fjmin1, Wj, Bj, …
‘Stride’, conv_params.stride, …
‘Padding’, conv_params.padding, …
‘DilationFactor’, conv_params.dilation);
% activation function (and derivative)
Oj = max(Sj, 0); Fprimej = sign(Oj);
%% Time AVERAGE POOLING
fprintf(‘=== AVERAGE POOLING (conv_af_ap) ===n’);
times_ap = struct();
for iter = 1:num_iter
% Average pooling
tic;
Oj_pooled = avgpool(Oj, pool_params.pool_size, …
‘Stride’, pool_params.pool_stride, …
‘Padding’, pool_params.pool_padding);
wait(g);
times_ap.pooling(iter) = toc;
end
%% Time MAX POOLING
fprintf(‘n=== MAX POOLING (conv_af_mp) ===n’);
times_mp = struct();
for iter = 1:num_iter
% Max pooling with indices
tic;
[Oj_pooled, max_indices] = maxpool(Oj, pool_params.pool_size, …
‘Stride’, pool_params.pool_stride, …
‘Padding’, pool_params.pool_padding);
wait(g);
times_mp.pooling(iter) = toc;
end
%% Compute statistics and display results
fprintf(‘n=== TIMING RESULTS (milliseconds) ===n’);
fprintf(‘%-25s %12s %12s %12sn’, ‘Step’, ‘AvgPool’, ‘MaxPool’, ‘Difference’);
fprintf(‘%sn’, repmat(‘-‘, 1, 65));
steps_common = { ‘pooling’};
total_ap = 0;
total_mp = 0;
for i = 1:length(steps_common)
step = steps_common{i};
if isfield(times_ap, step) && isfield(times_mp, step)
mean_ap = mean(times_ap.(step)) * 1000; % times 1000 to convert seconds to milliseconds
mean_mp = mean(times_mp.(step)) * 1000; % times 1000 to convert seconds to milliseconds
total_ap = total_ap + mean_ap;
total_mp = total_mp + mean_mp;
diff = mean_mp – mean_ap;
fprintf(‘%-25s %12.4f %12.4f %+12.4fn’, step, mean_ap, mean_mp, diff);
end
end
fprintf(‘%sn’, repmat(‘-‘, 1, 65));
%fprintf(‘%-25s %12.4f %12.4f %+12.4fn’, ‘TOTAL’, total_ap, total_mp, total_mp – total_ap);
fprintf(‘%-25s %12s %12s %12.2fxn’, ‘Speedup’, ”, ”, total_mp/total_ap);
end
Now you can see one main difference between my calling of maxpool and avgpool: for avgpool I only have 1 output (the pooled values), but with maxpool I have 2 outputs (the pooled values, and the index locations of these max values).
This is important because if I replaced the call to maxpool with only requesting the pooled values (1 output), maxpool is faster as expected:
>> analyze_pooling_timing
GPU: NVIDIA GeForce RTX 5080
Running 1000 iterations for each timing measurement…
=== AVERAGE POOLING (conv_af_ap) ===
=== MAX POOLING (conv_af_mp) ===
=== TIMING RESULTS (milliseconds) ===
Step AvgPool MaxPool Difference
—————————————————————–
pooling 0.4358 0.2330 -0.2028
—————————————————————–
max/avg 0.53x
>>
However if I call maxpool like here with 2 outputs (pooled values and indices), or with 3 outputs (pooled values, indices, and inputSize), this is where maxpool is extremely slow:
>> analyze_pooling_timing
GPU: NVIDIA GeForce RTX 5080
Running 1000 iterations for each timing measurement…
=== AVERAGE POOLING (conv_af_ap) ===
=== MAX POOLING (conv_af_mp) ===
=== TIMING RESULTS (milliseconds) ===
Step AvgPool MaxPool Difference
—————————————————————–
pooling 0.4153 38.9818 +38.5665
—————————————————————–
max/avg 93.86x
>>
So it appears that this is the reason why maxpool is so much slower: requesting the maxpool function to also output the indices leads to a massive slowdown.
Unfortunately, the indices are needed to later differentiate (backwards pass) the maxpool layer… so I need the indices…
I’d assume that whenever someone wants to train a CNN in matlab using a maxpool layer, they would have to call maxpool with indices, and thus I’d expect a similar slowdown…
Can anyone here comment on this? My application needs me to train maxpool layers, so I need to both forward pass and backwards pass through them, thus I need these indices. But it appears that matlab’s version of maxpool may not be the best implementation of a maxpool operation… maybe some inefficient processes regarding obtaining the indices? I’m designing a custom training procedure for a CNN that is different from backpropagation in that I use manual update rules for layers or sets of layers. I’m studying my gradient for two types of layers: “conv + actfun + maxpool”, and “conv + actfun + avgpool”, which are identical layers except the last action is a different pooling type.
I compared the two layer types with identical data dimension sizes to see the time differences between maxpool and avgpool, both in the forward pass and the backwards pass of the pooling layers. All other steps in calculating the gradient were exactly the same between the two layers, and showed the same time costs in the two layers. But when looking at time costs specifically of the pooling operations’ forward and backwards passes, I get significantly different times (average of 5000 runs of the gradient, each measurement is in milliseconds):
gradient step | AvgPool | MaxPool | Difference
————————–|———|———|———-
pooling (forward pass) | 0.4165 | 38.6316 | +38.2151
unpooling (backward pass) | 9.9468 | 46.1667 | +36.2199
For reference, all my data arrays are dlarrays on the GPU (gpuArrays in dlarrays), all single precision, and the pooling operations convert 32 by 32 feature maps (across 2 channels and 16384 batch size) to 16 by 16 feature maps (of same # channels and batch size), so just a 2 by 2 pooling operation.
You can see here that the maxpool forward pass (using “maxpool” function) is about 92 times slower than the avgpool forward pass (using “avgpool”), and the maxpool backward pass (using “maxunpool”) is about 4.6 times slower than the avgpool backward pass (using a custom “avgunpool” function that Anthropic’s Claude had to create for me, since matlab has no “avgunpool”).
These results are extremely suspect to me. For the forwards pass, comparing matlab’s built in "maxpool" to built in "avgpool" functions gives a 92x difference, but searching online people seem to instead claim that training max pooling is supposed to be faster than avg pooling, which contradicts the results here.
For simplicity, see the code example below that runs just "maxpool" and "avgpool" only (no other functions) and compares their times:
function analyze_pooling_timing()
% GPU setup
g = gpuDevice();
fprintf(‘GPU: %sn’, g.Name);
% Parameters matching your test
H_in = 32; W_in = 32; C_in = 3; C_out = 2;
N = 16384; % batch size. Try N = 32 small or N = 16384 big
kH = 3; kW = 3;
pool_params.pool_size = [2, 2];
pool_params.pool_stride = [2, 2];
pool_params.pool_padding = 0;
conv_params.stride = [1, 1];
conv_params.padding = ‘same’;
conv_params.dilation = [1, 1];
% Initialize data
Wj = dlarray(gpuArray(single(randn(kH, kW, C_in, C_out) * 0.01)), ‘SSCU’);
Bj = dlarray(gpuArray(single(zeros(C_out, 1))), ‘C’);
Fjmin1 = dlarray(gpuArray(single(randn(H_in, W_in, C_in, N))), ‘SSCB’);
% Number of iterations for averaging
num_iter = 100;
fprintf(‘Running %d iterations for each timing measurement…nn’, num_iter);
%% setup everything in forward pass before the pooling:
% Forward convolution
Sj = dlconv(Fjmin1, Wj, Bj, …
‘Stride’, conv_params.stride, …
‘Padding’, conv_params.padding, …
‘DilationFactor’, conv_params.dilation);
% activation function (and derivative)
Oj = max(Sj, 0); Fprimej = sign(Oj);
%% Time AVERAGE POOLING
fprintf(‘=== AVERAGE POOLING (conv_af_ap) ===n’);
times_ap = struct();
for iter = 1:num_iter
% Average pooling
tic;
Oj_pooled = avgpool(Oj, pool_params.pool_size, …
‘Stride’, pool_params.pool_stride, …
‘Padding’, pool_params.pool_padding);
wait(g);
times_ap.pooling(iter) = toc;
end
%% Time MAX POOLING
fprintf(‘n=== MAX POOLING (conv_af_mp) ===n’);
times_mp = struct();
for iter = 1:num_iter
% Max pooling with indices
tic;
[Oj_pooled, max_indices] = maxpool(Oj, pool_params.pool_size, …
‘Stride’, pool_params.pool_stride, …
‘Padding’, pool_params.pool_padding);
wait(g);
times_mp.pooling(iter) = toc;
end
%% Compute statistics and display results
fprintf(‘n=== TIMING RESULTS (milliseconds) ===n’);
fprintf(‘%-25s %12s %12s %12sn’, ‘Step’, ‘AvgPool’, ‘MaxPool’, ‘Difference’);
fprintf(‘%sn’, repmat(‘-‘, 1, 65));
steps_common = { ‘pooling’};
total_ap = 0;
total_mp = 0;
for i = 1:length(steps_common)
step = steps_common{i};
if isfield(times_ap, step) && isfield(times_mp, step)
mean_ap = mean(times_ap.(step)) * 1000; % times 1000 to convert seconds to milliseconds
mean_mp = mean(times_mp.(step)) * 1000; % times 1000 to convert seconds to milliseconds
total_ap = total_ap + mean_ap;
total_mp = total_mp + mean_mp;
diff = mean_mp – mean_ap;
fprintf(‘%-25s %12.4f %12.4f %+12.4fn’, step, mean_ap, mean_mp, diff);
end
end
fprintf(‘%sn’, repmat(‘-‘, 1, 65));
%fprintf(‘%-25s %12.4f %12.4f %+12.4fn’, ‘TOTAL’, total_ap, total_mp, total_mp – total_ap);
fprintf(‘%-25s %12s %12s %12.2fxn’, ‘Speedup’, ”, ”, total_mp/total_ap);
end
Now you can see one main difference between my calling of maxpool and avgpool: for avgpool I only have 1 output (the pooled values), but with maxpool I have 2 outputs (the pooled values, and the index locations of these max values).
This is important because if I replaced the call to maxpool with only requesting the pooled values (1 output), maxpool is faster as expected:
>> analyze_pooling_timing
GPU: NVIDIA GeForce RTX 5080
Running 1000 iterations for each timing measurement…
=== AVERAGE POOLING (conv_af_ap) ===
=== MAX POOLING (conv_af_mp) ===
=== TIMING RESULTS (milliseconds) ===
Step AvgPool MaxPool Difference
—————————————————————–
pooling 0.4358 0.2330 -0.2028
—————————————————————–
max/avg 0.53x
>>
However if I call maxpool like here with 2 outputs (pooled values and indices), or with 3 outputs (pooled values, indices, and inputSize), this is where maxpool is extremely slow:
>> analyze_pooling_timing
GPU: NVIDIA GeForce RTX 5080
Running 1000 iterations for each timing measurement…
=== AVERAGE POOLING (conv_af_ap) ===
=== MAX POOLING (conv_af_mp) ===
=== TIMING RESULTS (milliseconds) ===
Step AvgPool MaxPool Difference
—————————————————————–
pooling 0.4153 38.9818 +38.5665
—————————————————————–
max/avg 93.86x
>>
So it appears that this is the reason why maxpool is so much slower: requesting the maxpool function to also output the indices leads to a massive slowdown.
Unfortunately, the indices are needed to later differentiate (backwards pass) the maxpool layer… so I need the indices…
I’d assume that whenever someone wants to train a CNN in matlab using a maxpool layer, they would have to call maxpool with indices, and thus I’d expect a similar slowdown…
Can anyone here comment on this? My application needs me to train maxpool layers, so I need to both forward pass and backwards pass through them, thus I need these indices. But it appears that matlab’s version of maxpool may not be the best implementation of a maxpool operation… maybe some inefficient processes regarding obtaining the indices? deep learning, maxpool, avgpool, indexing MATLAB Answers — New Questions
How to adjust MATLAB Contour Plot’s colorbar to display a selected range of the colormap without changing the actual data limits (‘CLim’)?
I am trying to adjust the Contour Plot’s Colorbar in MATLAB to display a selected range of the colormap without altering the actual data limits (‘CLim’). How can I achieve this?I am trying to adjust the Contour Plot’s Colorbar in MATLAB to display a selected range of the colormap without altering the actual data limits (‘CLim’). How can I achieve this? I am trying to adjust the Contour Plot’s Colorbar in MATLAB to display a selected range of the colormap without altering the actual data limits (‘CLim’). How can I achieve this? colorbar, contour MATLAB Answers — New Questions
How do I change column headers in my table
I have some data that I am displaying in my script and have outputted it in 28 different tables. My script is quite long so I am just posting a screenshot for now.
Where is says var 2 I want to change to the storey number. So for table 1 I want storey 1, for table 2, storey 2 etc…
If you can see for the main output i am running a loop and using the matrix called "Int_force". I also have made the row headers as [Axial Force, Shear Force, Bending Moment. Thus, I am hoping someone can help me so that I can change the column headers to my desired wish? I am not sure how I would change the loop to accomplish this.
Many thanks,
ScottI have some data that I am displaying in my script and have outputted it in 28 different tables. My script is quite long so I am just posting a screenshot for now.
Where is says var 2 I want to change to the storey number. So for table 1 I want storey 1, for table 2, storey 2 etc…
If you can see for the main output i am running a loop and using the matrix called "Int_force". I also have made the row headers as [Axial Force, Shear Force, Bending Moment. Thus, I am hoping someone can help me so that I can change the column headers to my desired wish? I am not sure how I would change the loop to accomplish this.
Many thanks,
Scott I have some data that I am displaying in my script and have outputted it in 28 different tables. My script is quite long so I am just posting a screenshot for now.
Where is says var 2 I want to change to the storey number. So for table 1 I want storey 1, for table 2, storey 2 etc…
If you can see for the main output i am running a loop and using the matrix called "Int_force". I also have made the row headers as [Axial Force, Shear Force, Bending Moment. Thus, I am hoping someone can help me so that I can change the column headers to my desired wish? I am not sure how I would change the loop to accomplish this.
Many thanks,
Scott tables, for loop, matrices MATLAB Answers — New Questions
How to resample LTE waveforms generated using the LTE Waveform Generator in Simulink R2024b?
I have used the "resample" function in MATLAB to upsample LTE waveforms generated using the LTE Waveform Generator. I would like to do the same in Simulink. What blocks can I use to resample LTE waveforms in Simulink? I attempted to use the "Upsample" block in Simulink, but I do not get results similar to what I get in MATLAB.I have used the "resample" function in MATLAB to upsample LTE waveforms generated using the LTE Waveform Generator. I would like to do the same in Simulink. What blocks can I use to resample LTE waveforms in Simulink? I attempted to use the "Upsample" block in Simulink, but I do not get results similar to what I get in MATLAB. I have used the "resample" function in MATLAB to upsample LTE waveforms generated using the LTE Waveform Generator. I would like to do the same in Simulink. What blocks can I use to resample LTE waveforms in Simulink? I attempted to use the "Upsample" block in Simulink, but I do not get results similar to what I get in MATLAB. ltewaveform, resampling, upsampling, firinterpolation, firrateconversion MATLAB Answers — New Questions
Is there a way to edit the default size of an edit control in a livescript?
Is there any way to change the width of the edit controls in a livescript, either globally or on a per-control basis?
The edit box is a bit small when using it to enter Matlab code etc. and I would like to have a bit of control over it’s width.
The screenshot below shows the limited width of the edit box,
It would be nice if it was longer.Is there any way to change the width of the edit controls in a livescript, either globally or on a per-control basis?
The edit box is a bit small when using it to enter Matlab code etc. and I would like to have a bit of control over it’s width.
The screenshot below shows the limited width of the edit box,
It would be nice if it was longer. Is there any way to change the width of the edit controls in a livescript, either globally or on a per-control basis?
The edit box is a bit small when using it to enter Matlab code etc. and I would like to have a bit of control over it’s width.
The screenshot below shows the limited width of the edit box,
It would be nice if it was longer. livescript, mlx MATLAB Answers — New Questions
Looking for a reactive zoom implementation
I’m trying to pick up the zoom event from an active figure. I have a figure with the world’s coastlines, and a number of events and their geographical coordinates. I Want to make a 2d density map of the events over the coastline. The map should be smoothed with a gaussian filter with a width that is dependent on the level of zoom, such that when I zoom in I get a more.dtailed view. Has anyone implemented something similar already? Even a minimal working example would be great.I’m trying to pick up the zoom event from an active figure. I have a figure with the world’s coastlines, and a number of events and their geographical coordinates. I Want to make a 2d density map of the events over the coastline. The map should be smoothed with a gaussian filter with a width that is dependent on the level of zoom, such that when I zoom in I get a more.dtailed view. Has anyone implemented something similar already? Even a minimal working example would be great. I’m trying to pick up the zoom event from an active figure. I have a figure with the world’s coastlines, and a number of events and their geographical coordinates. I Want to make a 2d density map of the events over the coastline. The map should be smoothed with a gaussian filter with a width that is dependent on the level of zoom, such that when I zoom in I get a more.dtailed view. Has anyone implemented something similar already? Even a minimal working example would be great. zoom, callbacks, histogram, density MATLAB Answers — New Questions
Issue on running polyspace bugfinder qualification kit
I was trying to run the polyspace qualification kit but ihave an issue on a ReportGeneratorQual.pm module
The module can’t be found (i have also installed perl) and i can’t find online anything about this module
How can i install/find this module?I was trying to run the polyspace qualification kit but ihave an issue on a ReportGeneratorQual.pm module
The module can’t be found (i have also installed perl) and i can’t find online anything about this module
How can i install/find this module? I was trying to run the polyspace qualification kit but ihave an issue on a ReportGeneratorQual.pm module
The module can’t be found (i have also installed perl) and i can’t find online anything about this module
How can i install/find this module? polyspace, do, qualification, qual MATLAB Answers — New Questions
Question with respect to NPUSCH BLER Example
Hello All,
I am trying to simulate the NPUSCH BLER example and would like to understand the hidden assumptions when we disable perfect channel estimation for this example? The simulation results in BLER = 0 for SNR = -25dB when SCS=3.75kHz for 1RU and 1 subcarrier. I would like to use a custom channel (say Rician) for example. I have made the changes accordingly, but it does not seem to work. Please could you help me figure out what is happening in the background?
Update: I realised that noiseEst is always 0 when ‘perfectChannelEstimate=false’ and this is giving me wrong results for lower SNR.
Thanks in advanceHello All,
I am trying to simulate the NPUSCH BLER example and would like to understand the hidden assumptions when we disable perfect channel estimation for this example? The simulation results in BLER = 0 for SNR = -25dB when SCS=3.75kHz for 1RU and 1 subcarrier. I would like to use a custom channel (say Rician) for example. I have made the changes accordingly, but it does not seem to work. Please could you help me figure out what is happening in the background?
Update: I realised that noiseEst is always 0 when ‘perfectChannelEstimate=false’ and this is giving me wrong results for lower SNR.
Thanks in advance Hello All,
I am trying to simulate the NPUSCH BLER example and would like to understand the hidden assumptions when we disable perfect channel estimation for this example? The simulation results in BLER = 0 for SNR = -25dB when SCS=3.75kHz for 1RU and 1 subcarrier. I would like to use a custom channel (say Rician) for example. I have made the changes accordingly, but it does not seem to work. Please could you help me figure out what is happening in the background?
Update: I realised that noiseEst is always 0 when ‘perfectChannelEstimate=false’ and this is giving me wrong results for lower SNR.
Thanks in advance nbiot, npusch, bler MATLAB Answers — New Questions
How do I find the mode of an array and verify it using the frequency?
A very basic question, but I am just getting back into it and I’m struggling to find the right answer on the forums (or I very bad at using Google?).
I have an array which is 100×50 and want to find the mode of each row. When I run the below function, it provides a 98% correct solution. Two of the rows have a mix of values and it is not as easy to tell the mode, whereas the other 98 rows have a distint value. Is it possible to set a threshold so that out of the row, if the value is only less than 30% of the total value then ignore it?
So if row 99 has a value of 1 as the mode, but 1 only occurs 20% (10/50) of the time in the total row then ignore it.
mode(a(:,:));A very basic question, but I am just getting back into it and I’m struggling to find the right answer on the forums (or I very bad at using Google?).
I have an array which is 100×50 and want to find the mode of each row. When I run the below function, it provides a 98% correct solution. Two of the rows have a mix of values and it is not as easy to tell the mode, whereas the other 98 rows have a distint value. Is it possible to set a threshold so that out of the row, if the value is only less than 30% of the total value then ignore it?
So if row 99 has a value of 1 as the mode, but 1 only occurs 20% (10/50) of the time in the total row then ignore it.
mode(a(:,:)); A very basic question, but I am just getting back into it and I’m struggling to find the right answer on the forums (or I very bad at using Google?).
I have an array which is 100×50 and want to find the mode of each row. When I run the below function, it provides a 98% correct solution. Two of the rows have a mix of values and it is not as easy to tell the mode, whereas the other 98 rows have a distint value. Is it possible to set a threshold so that out of the row, if the value is only less than 30% of the total value then ignore it?
So if row 99 has a value of 1 as the mode, but 1 only occurs 20% (10/50) of the time in the total row then ignore it.
mode(a(:,:)); mode, frequency, array MATLAB Answers — New Questions
Cross-Coupled System Identification
Hi everyone, I aim to build a model of my system using real-time data. My system is a MIMO (Multiple Input Multiple Output) system, where the inputs are RPM and rudder angle, and the outputs are linear velocity and angular velocity. Also the system is cross-coupled, so both inputs effect both outputs and I think that there is nonlinear model. I want to implemented system identification model. I collected data for train and validation. Then, I implemented filter and prepared for system identification. I tried different models such as TF, State Space and Nonlinear models. I see that best models estimated by Nonlinear ARX model. But I don’t know how can I find the best model fit because there are many options in Nonlinear ARX model window. For example there are many options in Nonlinear Function bar such as Wavelet, Sigmoid, Neural, Gaussian etc… So how can i find best model fit. Do I need to write code about grid search may be it finds best possible trying different conditions? Do you have any recommendation?Hi everyone, I aim to build a model of my system using real-time data. My system is a MIMO (Multiple Input Multiple Output) system, where the inputs are RPM and rudder angle, and the outputs are linear velocity and angular velocity. Also the system is cross-coupled, so both inputs effect both outputs and I think that there is nonlinear model. I want to implemented system identification model. I collected data for train and validation. Then, I implemented filter and prepared for system identification. I tried different models such as TF, State Space and Nonlinear models. I see that best models estimated by Nonlinear ARX model. But I don’t know how can I find the best model fit because there are many options in Nonlinear ARX model window. For example there are many options in Nonlinear Function bar such as Wavelet, Sigmoid, Neural, Gaussian etc… So how can i find best model fit. Do I need to write code about grid search may be it finds best possible trying different conditions? Do you have any recommendation? Hi everyone, I aim to build a model of my system using real-time data. My system is a MIMO (Multiple Input Multiple Output) system, where the inputs are RPM and rudder angle, and the outputs are linear velocity and angular velocity. Also the system is cross-coupled, so both inputs effect both outputs and I think that there is nonlinear model. I want to implemented system identification model. I collected data for train and validation. Then, I implemented filter and prepared for system identification. I tried different models such as TF, State Space and Nonlinear models. I see that best models estimated by Nonlinear ARX model. But I don’t know how can I find the best model fit because there are many options in Nonlinear ARX model window. For example there are many options in Nonlinear Function bar such as Wavelet, Sigmoid, Neural, Gaussian etc… So how can i find best model fit. Do I need to write code about grid search may be it finds best possible trying different conditions? Do you have any recommendation? model, system MATLAB Answers — New Questions
Running MATLAB R2024a headless on Ubuntu 24.04 causes GUI errors
Hello,
I’ve installed MATLAB R2024a on a Ubuntu Server 24.04.3 LTS machine. My goal is to run it headlessly (without a GUI), so I try launching it with:
matlab -nodesktop -nojvm -nosplash
However, when doing this, MATLAB attempts to use a graphical interface and triggers errors related to missing graphical libraries (libXrandr, libgdk_pixbuf, libXinerama, etc.).
The error messages appear to come from a temporary ServiceHost installer located at:
~/.MathWorks/ServiceHost/<machine_name>/_tmp_MSHI_xxxxx/mci/_tempinstaller_glnxa64/bin/glnxa64/InstallMathWorksServiceHost
It seems that the ServiceHost installer is trying to use GUI components, which doesn’t work in this headless server environment.
My questions are:
Is there a way to disable or bypass the ServiceHost installation when running MATLAB in headless mode?
Alternatively, is there a way to install ServiceHost in a non-GUI/headless manner so MATLAB won’t attempt to launch the graphical installer?Hello,
I’ve installed MATLAB R2024a on a Ubuntu Server 24.04.3 LTS machine. My goal is to run it headlessly (without a GUI), so I try launching it with:
matlab -nodesktop -nojvm -nosplash
However, when doing this, MATLAB attempts to use a graphical interface and triggers errors related to missing graphical libraries (libXrandr, libgdk_pixbuf, libXinerama, etc.).
The error messages appear to come from a temporary ServiceHost installer located at:
~/.MathWorks/ServiceHost/<machine_name>/_tmp_MSHI_xxxxx/mci/_tempinstaller_glnxa64/bin/glnxa64/InstallMathWorksServiceHost
It seems that the ServiceHost installer is trying to use GUI components, which doesn’t work in this headless server environment.
My questions are:
Is there a way to disable or bypass the ServiceHost installation when running MATLAB in headless mode?
Alternatively, is there a way to install ServiceHost in a non-GUI/headless manner so MATLAB won’t attempt to launch the graphical installer? Hello,
I’ve installed MATLAB R2024a on a Ubuntu Server 24.04.3 LTS machine. My goal is to run it headlessly (without a GUI), so I try launching it with:
matlab -nodesktop -nojvm -nosplash
However, when doing this, MATLAB attempts to use a graphical interface and triggers errors related to missing graphical libraries (libXrandr, libgdk_pixbuf, libXinerama, etc.).
The error messages appear to come from a temporary ServiceHost installer located at:
~/.MathWorks/ServiceHost/<machine_name>/_tmp_MSHI_xxxxx/mci/_tempinstaller_glnxa64/bin/glnxa64/InstallMathWorksServiceHost
It seems that the ServiceHost installer is trying to use GUI components, which doesn’t work in this headless server environment.
My questions are:
Is there a way to disable or bypass the ServiceHost installation when running MATLAB in headless mode?
Alternatively, is there a way to install ServiceHost in a non-GUI/headless manner so MATLAB won’t attempt to launch the graphical installer? installation, servicehost, linux, ubuntu, headless MATLAB Answers — New Questions
Crash with C Caller in Accelerator mode
I have a proget which uses Ccallers and with release 2025a in crash in accelerator mode.
Same model with 2024b or later it runs fine in accelerator and normal.
In rapid accelerator same issues with older and last release.
I think it is a well known problem. Any advice?
Thanks to all.
DI have a proget which uses Ccallers and with release 2025a in crash in accelerator mode.
Same model with 2024b or later it runs fine in accelerator and normal.
In rapid accelerator same issues with older and last release.
I think it is a well known problem. Any advice?
Thanks to all.
D I have a proget which uses Ccallers and with release 2025a in crash in accelerator mode.
Same model with 2024b or later it runs fine in accelerator and normal.
In rapid accelerator same issues with older and last release.
I think it is a well known problem. Any advice?
Thanks to all.
D ccaller MATLAB Answers — New Questions
define 300 function calls x1(t)—x300(t)
Hi there,
I am using ode15s to resolve a DAE system. Since there are 300 variables x1(t)~x300(t) in my case, so I feel it is a little bit inconvenient to define them by writing
syms x1(t) … x300(t)
one by one. Are there any efficient codes to define them?
Many thanks!Hi there,
I am using ode15s to resolve a DAE system. Since there are 300 variables x1(t)~x300(t) in my case, so I feel it is a little bit inconvenient to define them by writing
syms x1(t) … x300(t)
one by one. Are there any efficient codes to define them?
Many thanks! Hi there,
I am using ode15s to resolve a DAE system. Since there are 300 variables x1(t)~x300(t) in my case, so I feel it is a little bit inconvenient to define them by writing
syms x1(t) … x300(t)
one by one. Are there any efficient codes to define them?
Many thanks! function calls, ode, differential equations MATLAB Answers — New Questions









