Author: PuTI
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
How to further utilize the “simplify” function for simplification?
I was simplifying the trigonometric function, but despite using the "simplify" function, the result I obtained is as follows.
However, this result can still be further simplified. Could you please tell me where the problem lies?I was simplifying the trigonometric function, but despite using the "simplify" function, the result I obtained is as follows.
However, this result can still be further simplified. Could you please tell me where the problem lies? I was simplifying the trigonometric function, but despite using the "simplify" function, the result I obtained is as follows.
However, this result can still be further simplified. Could you please tell me where the problem lies? symbolic, simplify MATLAB Answers — New Questions
create a code for butterworth 4th order bandpass filter without Signal Processing Toolbox
I am working with Surface EMG data and need to use a 4th order butterworth bandpass filter but don’t have the signal processing toolbox. The cutoff frequency range is from 20 to 450 hz. I am also trying to understand how to come up with the coefficients using this bandpass filter and where I can apply that if I’m using that filtered signal to measure the MVIC of the data.
Thank youI am working with Surface EMG data and need to use a 4th order butterworth bandpass filter but don’t have the signal processing toolbox. The cutoff frequency range is from 20 to 450 hz. I am also trying to understand how to come up with the coefficients using this bandpass filter and where I can apply that if I’m using that filtered signal to measure the MVIC of the data.
Thank you I am working with Surface EMG data and need to use a 4th order butterworth bandpass filter but don’t have the signal processing toolbox. The cutoff frequency range is from 20 to 450 hz. I am also trying to understand how to come up with the coefficients using this bandpass filter and where I can apply that if I’m using that filtered signal to measure the MVIC of the data.
Thank you filter, signal processing MATLAB Answers — New Questions
Matlab unable to parse a Numeric field when I use the gather function on a tall array.
So I have a CSV file with a large amount of datapoints that I want to perform a particular algorithm on. So I created a tall array from the file and wanted to import a small chunk of the data at a time. However, when I tried to use gather to get the small chunk into the memory, I get the following error.
"Board_Ai0" is the header of the CSV file. It is not in present in row 15355 as can be seen below where I opened the csv file in MATLAB’s import tool.
The same algorithm works perfectly fine when I don’t use tall array but instead import the whole file into the memory. However, I have other larger CSV files that I also want to analyze but won’t fit in memory.
UPDATE: So apparently the images were illegible but someone else edited the question to make the size of the image larger so I guess it should be fine now. Also I can’t attach the data files to this question because the data files that give me this problems are all larger than 5 GB.So I have a CSV file with a large amount of datapoints that I want to perform a particular algorithm on. So I created a tall array from the file and wanted to import a small chunk of the data at a time. However, when I tried to use gather to get the small chunk into the memory, I get the following error.
"Board_Ai0" is the header of the CSV file. It is not in present in row 15355 as can be seen below where I opened the csv file in MATLAB’s import tool.
The same algorithm works perfectly fine when I don’t use tall array but instead import the whole file into the memory. However, I have other larger CSV files that I also want to analyze but won’t fit in memory.
UPDATE: So apparently the images were illegible but someone else edited the question to make the size of the image larger so I guess it should be fine now. Also I can’t attach the data files to this question because the data files that give me this problems are all larger than 5 GB. So I have a CSV file with a large amount of datapoints that I want to perform a particular algorithm on. So I created a tall array from the file and wanted to import a small chunk of the data at a time. However, when I tried to use gather to get the small chunk into the memory, I get the following error.
"Board_Ai0" is the header of the CSV file. It is not in present in row 15355 as can be seen below where I opened the csv file in MATLAB’s import tool.
The same algorithm works perfectly fine when I don’t use tall array but instead import the whole file into the memory. However, I have other larger CSV files that I also want to analyze but won’t fit in memory.
UPDATE: So apparently the images were illegible but someone else edited the question to make the size of the image larger so I guess it should be fine now. Also I can’t attach the data files to this question because the data files that give me this problems are all larger than 5 GB. tall, gather MATLAB Answers — New Questions
How Do Assignment and Deletion Work with an Empty Index on the Left Hand Side ?
I’ve always thought that indexing with an empty array on the LHS of an = is a no-op for the variable on the LHS (there could be side effects of the evaluation of the RHS).
For example
% Case 1
A = [1 2;3 4];
A([]) = 5
But, assigning a non-scalar on the RHS result in an error
% Case 2
try
A([]) = [5,6];
catch ME
ME.message
end
Why doesn’t Case 1 result in an error insofar as it also had a different number of elements on the left and right sides?
Using the deletion operator on the RHS with an empty index on the LHS reshapes the matrix
% Case 3
A = [1 2;3 4];
A([]) = []
Why does a request to delete nothing from A change A?
But that doesn’t happen if A is column vector
% Case 4
A = [1;2;3;4];
A([]) = []
Deletion with a non-zero dimension of an empty index also reshapes the LHS
% Case 5
A = [1 2;3 4];
A(double.empty(0,1)) = []
A = [1 2; 3 4];
A(double.empty(1,0)) = []
I suppose Cases 3 and 5 are related to deleting a specific (non-empty) element from a matrix
% Case 6
A = [1 2;3 4];
A(3) = []
But I’m surprised that the result is not a column vector.
Are any/all of these results following a general rule? Pointers to relevant documentation would be welcome. I couldn’t find any.I’ve always thought that indexing with an empty array on the LHS of an = is a no-op for the variable on the LHS (there could be side effects of the evaluation of the RHS).
For example
% Case 1
A = [1 2;3 4];
A([]) = 5
But, assigning a non-scalar on the RHS result in an error
% Case 2
try
A([]) = [5,6];
catch ME
ME.message
end
Why doesn’t Case 1 result in an error insofar as it also had a different number of elements on the left and right sides?
Using the deletion operator on the RHS with an empty index on the LHS reshapes the matrix
% Case 3
A = [1 2;3 4];
A([]) = []
Why does a request to delete nothing from A change A?
But that doesn’t happen if A is column vector
% Case 4
A = [1;2;3;4];
A([]) = []
Deletion with a non-zero dimension of an empty index also reshapes the LHS
% Case 5
A = [1 2;3 4];
A(double.empty(0,1)) = []
A = [1 2; 3 4];
A(double.empty(1,0)) = []
I suppose Cases 3 and 5 are related to deleting a specific (non-empty) element from a matrix
% Case 6
A = [1 2;3 4];
A(3) = []
But I’m surprised that the result is not a column vector.
Are any/all of these results following a general rule? Pointers to relevant documentation would be welcome. I couldn’t find any. I’ve always thought that indexing with an empty array on the LHS of an = is a no-op for the variable on the LHS (there could be side effects of the evaluation of the RHS).
For example
% Case 1
A = [1 2;3 4];
A([]) = 5
But, assigning a non-scalar on the RHS result in an error
% Case 2
try
A([]) = [5,6];
catch ME
ME.message
end
Why doesn’t Case 1 result in an error insofar as it also had a different number of elements on the left and right sides?
Using the deletion operator on the RHS with an empty index on the LHS reshapes the matrix
% Case 3
A = [1 2;3 4];
A([]) = []
Why does a request to delete nothing from A change A?
But that doesn’t happen if A is column vector
% Case 4
A = [1;2;3;4];
A([]) = []
Deletion with a non-zero dimension of an empty index also reshapes the LHS
% Case 5
A = [1 2;3 4];
A(double.empty(0,1)) = []
A = [1 2; 3 4];
A(double.empty(1,0)) = []
I suppose Cases 3 and 5 are related to deleting a specific (non-empty) element from a matrix
% Case 6
A = [1 2;3 4];
A(3) = []
But I’m surprised that the result is not a column vector.
Are any/all of these results following a general rule? Pointers to relevant documentation would be welcome. I couldn’t find any. empty index, deletion, assignment MATLAB Answers — New Questions
Can’t train a custom neural network
Hello,
I am trying to create a neural network of the type shown in the picture. This is a pre-structured network that mimics a certain equation. However, I am having difficulties with creating the network structure using the network function for custom networks.
Here is the code I currently have:
clear; clc; rng(0);
%% 1) Simulink’ten verileri al
simOut = sim(‘MSD_Model’); % Simulink modeli
u_data = simOut.get(‘u’); % To Workspace: u (vektör)
y_data = simOut.get(‘y’); % To Workspace: y (vektör)
u_data = u_data(:)’; % 1xN
y_data = y_data(:)’; % 1xN
% Hücre dizileri (1xN, her hücre skalar)
U = con2seq(u_data);
Y = con2seq(y_data);
%% 2) SSNN-benzeri özel RNN mimarisi
n = 1; % input
s = 2; % state (Layer 2)
h = 4; % hidden S (Layer 1)
h2 = 2; % hidden O (Layer 3)
m = 1; % output
net = network;
net.numInputs = 1;
net.numLayers = 4;
% Bağlantı topolojisi
% L1 <- Input
% L1 <- L2(z^-1) (x̂(t-1) geri besleme)
% L2 <- L1
% L3 <- L2
% L4 <- L3 (çıktı)
net.inputConnect = [1;0;0;0];
net.layerConnect = logical([ …
0 1 0 0; % L1 <- L2 (delayed)
1 0 0 0; % L2 <- L1
0 1 0 0; % L3 <- L2
0 0 1 0]);% L4 <- L3
net.outputConnect = [false false false true];
% Katman boyutları
net.inputs{1}.size = n;
net.layers{1}.size = h; % Hidden S
net.layers{2}.size = s; % State layer (x̂)
net.layers{3}.size = h2; % Hidden O
net.layers{4}.size = m; % Output
% Transfer fonksiyonları (SSNN uyumlu)
net.layers{1}.transferFcn = ‘tansig’;
net.layers{2}.transferFcn = ‘purelin’;
net.layers{3}.transferFcn = ‘tansig’;
net.layers{4}.transferFcn = ‘purelin’;
% Gecikmeler
net.layerWeights{1,2}.delays = 1; % x̂(t-1) -> Hidden S
net.layerWeights{2,1}.delays = 0;
net.layerWeights{3,2}.delays = 1;
net.layerWeights{4,3}.delays = 0;
% Biaslar
net.biasConnect = [1;1;1;1];
% Performans ve eğitim
net.performFcn = ‘mse’;
net.trainFcn = ‘trainlm’;
net.trainParam.epochs = 100;
net.trainParam.goal = 1e-6;
net.trainParam.max_fail = 12;
net.trainParam.showWindow = true;
% Zaman serisi bölme (blok halinde)
net.divideFcn = ‘dividetrain’; % tüm veri train, erken durdurma yok
% Ön-konfigürasyon & init
net = configure(net, U, Y);
net = init(net);
%% 3) Eğitim
[net, tr] = train(net, U, Y);
%% 4) Tahmin ve performans
Y_pred = net(U);
mse_train = perform(net, Y(tr.trainInd), Y_pred(tr.trainInd));
fprintf(‘MSE (train): %.3en’, mse_train);
% Diyagnostik grafikler
figure; plotperform(tr);
figure; plotregression(cell2mat(Y), cell2mat(Y_pred), ‘Regression’);
% Zaman serisi karşılaştırma
figure; hold on; grid on;
plot(cell2mat(Y)’, ‘LineWidth’,1.5);
plot(cell2mat(Y_pred)’, ‘–‘, ‘LineWidth’,1.5);
xlabel(‘Zaman (örnek)’); ylabel(‘Çıkış’);
legend(‘Gerçek Y(t)’,’Tahmin Ŷ(t)’); title(‘SSNN-RNN Zaman Serisi Modelleme’);
%% 5) Kaydet & Simulink bloğu üret
save(‘trained_SSNN.mat’,’net’);
Ts = 0.01; % model örnekleme zamanınla eşleştir
gensim(net, Ts); % Simulink bloğu üretir (mask altından I/O=1×1)
The problem is that I cannot start the training properly — it always stops at the second epoch. I also tried using a Layered Recurrent Network (layrecnet), but the problem remains the same.
Could you please help me understand what I am doing wrong?
Also, are there any good resources or documentation on how to create and train custom neural networks in MATLAB (beyond the standard predefined types)?
Thank you in advance!Hello,
I am trying to create a neural network of the type shown in the picture. This is a pre-structured network that mimics a certain equation. However, I am having difficulties with creating the network structure using the network function for custom networks.
Here is the code I currently have:
clear; clc; rng(0);
%% 1) Simulink’ten verileri al
simOut = sim(‘MSD_Model’); % Simulink modeli
u_data = simOut.get(‘u’); % To Workspace: u (vektör)
y_data = simOut.get(‘y’); % To Workspace: y (vektör)
u_data = u_data(:)’; % 1xN
y_data = y_data(:)’; % 1xN
% Hücre dizileri (1xN, her hücre skalar)
U = con2seq(u_data);
Y = con2seq(y_data);
%% 2) SSNN-benzeri özel RNN mimarisi
n = 1; % input
s = 2; % state (Layer 2)
h = 4; % hidden S (Layer 1)
h2 = 2; % hidden O (Layer 3)
m = 1; % output
net = network;
net.numInputs = 1;
net.numLayers = 4;
% Bağlantı topolojisi
% L1 <- Input
% L1 <- L2(z^-1) (x̂(t-1) geri besleme)
% L2 <- L1
% L3 <- L2
% L4 <- L3 (çıktı)
net.inputConnect = [1;0;0;0];
net.layerConnect = logical([ …
0 1 0 0; % L1 <- L2 (delayed)
1 0 0 0; % L2 <- L1
0 1 0 0; % L3 <- L2
0 0 1 0]);% L4 <- L3
net.outputConnect = [false false false true];
% Katman boyutları
net.inputs{1}.size = n;
net.layers{1}.size = h; % Hidden S
net.layers{2}.size = s; % State layer (x̂)
net.layers{3}.size = h2; % Hidden O
net.layers{4}.size = m; % Output
% Transfer fonksiyonları (SSNN uyumlu)
net.layers{1}.transferFcn = ‘tansig’;
net.layers{2}.transferFcn = ‘purelin’;
net.layers{3}.transferFcn = ‘tansig’;
net.layers{4}.transferFcn = ‘purelin’;
% Gecikmeler
net.layerWeights{1,2}.delays = 1; % x̂(t-1) -> Hidden S
net.layerWeights{2,1}.delays = 0;
net.layerWeights{3,2}.delays = 1;
net.layerWeights{4,3}.delays = 0;
% Biaslar
net.biasConnect = [1;1;1;1];
% Performans ve eğitim
net.performFcn = ‘mse’;
net.trainFcn = ‘trainlm’;
net.trainParam.epochs = 100;
net.trainParam.goal = 1e-6;
net.trainParam.max_fail = 12;
net.trainParam.showWindow = true;
% Zaman serisi bölme (blok halinde)
net.divideFcn = ‘dividetrain’; % tüm veri train, erken durdurma yok
% Ön-konfigürasyon & init
net = configure(net, U, Y);
net = init(net);
%% 3) Eğitim
[net, tr] = train(net, U, Y);
%% 4) Tahmin ve performans
Y_pred = net(U);
mse_train = perform(net, Y(tr.trainInd), Y_pred(tr.trainInd));
fprintf(‘MSE (train): %.3en’, mse_train);
% Diyagnostik grafikler
figure; plotperform(tr);
figure; plotregression(cell2mat(Y), cell2mat(Y_pred), ‘Regression’);
% Zaman serisi karşılaştırma
figure; hold on; grid on;
plot(cell2mat(Y)’, ‘LineWidth’,1.5);
plot(cell2mat(Y_pred)’, ‘–‘, ‘LineWidth’,1.5);
xlabel(‘Zaman (örnek)’); ylabel(‘Çıkış’);
legend(‘Gerçek Y(t)’,’Tahmin Ŷ(t)’); title(‘SSNN-RNN Zaman Serisi Modelleme’);
%% 5) Kaydet & Simulink bloğu üret
save(‘trained_SSNN.mat’,’net’);
Ts = 0.01; % model örnekleme zamanınla eşleştir
gensim(net, Ts); % Simulink bloğu üretir (mask altından I/O=1×1)
The problem is that I cannot start the training properly — it always stops at the second epoch. I also tried using a Layered Recurrent Network (layrecnet), but the problem remains the same.
Could you please help me understand what I am doing wrong?
Also, are there any good resources or documentation on how to create and train custom neural networks in MATLAB (beyond the standard predefined types)?
Thank you in advance! Hello,
I am trying to create a neural network of the type shown in the picture. This is a pre-structured network that mimics a certain equation. However, I am having difficulties with creating the network structure using the network function for custom networks.
Here is the code I currently have:
clear; clc; rng(0);
%% 1) Simulink’ten verileri al
simOut = sim(‘MSD_Model’); % Simulink modeli
u_data = simOut.get(‘u’); % To Workspace: u (vektör)
y_data = simOut.get(‘y’); % To Workspace: y (vektör)
u_data = u_data(:)’; % 1xN
y_data = y_data(:)’; % 1xN
% Hücre dizileri (1xN, her hücre skalar)
U = con2seq(u_data);
Y = con2seq(y_data);
%% 2) SSNN-benzeri özel RNN mimarisi
n = 1; % input
s = 2; % state (Layer 2)
h = 4; % hidden S (Layer 1)
h2 = 2; % hidden O (Layer 3)
m = 1; % output
net = network;
net.numInputs = 1;
net.numLayers = 4;
% Bağlantı topolojisi
% L1 <- Input
% L1 <- L2(z^-1) (x̂(t-1) geri besleme)
% L2 <- L1
% L3 <- L2
% L4 <- L3 (çıktı)
net.inputConnect = [1;0;0;0];
net.layerConnect = logical([ …
0 1 0 0; % L1 <- L2 (delayed)
1 0 0 0; % L2 <- L1
0 1 0 0; % L3 <- L2
0 0 1 0]);% L4 <- L3
net.outputConnect = [false false false true];
% Katman boyutları
net.inputs{1}.size = n;
net.layers{1}.size = h; % Hidden S
net.layers{2}.size = s; % State layer (x̂)
net.layers{3}.size = h2; % Hidden O
net.layers{4}.size = m; % Output
% Transfer fonksiyonları (SSNN uyumlu)
net.layers{1}.transferFcn = ‘tansig’;
net.layers{2}.transferFcn = ‘purelin’;
net.layers{3}.transferFcn = ‘tansig’;
net.layers{4}.transferFcn = ‘purelin’;
% Gecikmeler
net.layerWeights{1,2}.delays = 1; % x̂(t-1) -> Hidden S
net.layerWeights{2,1}.delays = 0;
net.layerWeights{3,2}.delays = 1;
net.layerWeights{4,3}.delays = 0;
% Biaslar
net.biasConnect = [1;1;1;1];
% Performans ve eğitim
net.performFcn = ‘mse’;
net.trainFcn = ‘trainlm’;
net.trainParam.epochs = 100;
net.trainParam.goal = 1e-6;
net.trainParam.max_fail = 12;
net.trainParam.showWindow = true;
% Zaman serisi bölme (blok halinde)
net.divideFcn = ‘dividetrain’; % tüm veri train, erken durdurma yok
% Ön-konfigürasyon & init
net = configure(net, U, Y);
net = init(net);
%% 3) Eğitim
[net, tr] = train(net, U, Y);
%% 4) Tahmin ve performans
Y_pred = net(U);
mse_train = perform(net, Y(tr.trainInd), Y_pred(tr.trainInd));
fprintf(‘MSE (train): %.3en’, mse_train);
% Diyagnostik grafikler
figure; plotperform(tr);
figure; plotregression(cell2mat(Y), cell2mat(Y_pred), ‘Regression’);
% Zaman serisi karşılaştırma
figure; hold on; grid on;
plot(cell2mat(Y)’, ‘LineWidth’,1.5);
plot(cell2mat(Y_pred)’, ‘–‘, ‘LineWidth’,1.5);
xlabel(‘Zaman (örnek)’); ylabel(‘Çıkış’);
legend(‘Gerçek Y(t)’,’Tahmin Ŷ(t)’); title(‘SSNN-RNN Zaman Serisi Modelleme’);
%% 5) Kaydet & Simulink bloğu üret
save(‘trained_SSNN.mat’,’net’);
Ts = 0.01; % model örnekleme zamanınla eşleştir
gensim(net, Ts); % Simulink bloğu üretir (mask altından I/O=1×1)
The problem is that I cannot start the training properly — it always stops at the second epoch. I also tried using a Layered Recurrent Network (layrecnet), but the problem remains the same.
Could you please help me understand what I am doing wrong?
Also, are there any good resources or documentation on how to create and train custom neural networks in MATLAB (beyond the standard predefined types)?
Thank you in advance! deep learning, custom neural network, neural networks, modelling MATLAB Answers — New Questions
Problem in running python function from MATLAB console
Hello
I am new to python but extensive users of MATLAB. I wish to run Python function from MATLAB command prompt, so that the derived output can be utilized in further processing in MATLAB. I am trying to run this function available in this link. I have installed numba and numpy via cmd. As given in different tutorials, I have added my python path to MATLAB, using pyenv command. Then, I tried to call the function using below script for desired values as below:
[Twb] = py.wetbulb_dj08_spedup.WetBulb(25.,100000.,0.015,0),[0]
However, I am getting the following error:
Python Error: IndexError: list index out of range
Kindly help me in this regard. Also, if I wish to run for the time series array, how to define them from the MATLAB console. Do I need to define these vectors using py.numpy.array(A), where A is my time series array? Kindly help.
I am using MATLAB2024b.Hello
I am new to python but extensive users of MATLAB. I wish to run Python function from MATLAB command prompt, so that the derived output can be utilized in further processing in MATLAB. I am trying to run this function available in this link. I have installed numba and numpy via cmd. As given in different tutorials, I have added my python path to MATLAB, using pyenv command. Then, I tried to call the function using below script for desired values as below:
[Twb] = py.wetbulb_dj08_spedup.WetBulb(25.,100000.,0.015,0),[0]
However, I am getting the following error:
Python Error: IndexError: list index out of range
Kindly help me in this regard. Also, if I wish to run for the time series array, how to define them from the MATLAB console. Do I need to define these vectors using py.numpy.array(A), where A is my time series array? Kindly help.
I am using MATLAB2024b. Hello
I am new to python but extensive users of MATLAB. I wish to run Python function from MATLAB command prompt, so that the derived output can be utilized in further processing in MATLAB. I am trying to run this function available in this link. I have installed numba and numpy via cmd. As given in different tutorials, I have added my python path to MATLAB, using pyenv command. Then, I tried to call the function using below script for desired values as below:
[Twb] = py.wetbulb_dj08_spedup.WetBulb(25.,100000.,0.015,0),[0]
However, I am getting the following error:
Python Error: IndexError: list index out of range
Kindly help me in this regard. Also, if I wish to run for the time series array, how to define them from the MATLAB console. Do I need to define these vectors using py.numpy.array(A), where A is my time series array? Kindly help.
I am using MATLAB2024b. matlab – python, arrays, function MATLAB Answers — New Questions
Single Precision Converter Does not work with R2016B
I am using Matlab R2016b. I need to convert a Simulink model to single-precision. When I click Analysis–>Data Type Design –> Single Precision Converter, I got a blank window.
Then I tried to use command line:
>> report = DataTypeWorkflow.Single.convertToSingle("MyModel")
it instantly returns:
report =
Report with no properties.
Which I believe it didn’t do anything, but no error or warning was displayed either.
Any help will be appreciatedI am using Matlab R2016b. I need to convert a Simulink model to single-precision. When I click Analysis–>Data Type Design –> Single Precision Converter, I got a blank window.
Then I tried to use command line:
>> report = DataTypeWorkflow.Single.convertToSingle("MyModel")
it instantly returns:
report =
Report with no properties.
Which I believe it didn’t do anything, but no error or warning was displayed either.
Any help will be appreciated I am using Matlab R2016b. I need to convert a Simulink model to single-precision. When I click Analysis–>Data Type Design –> Single Precision Converter, I got a blank window.
Then I tried to use command line:
>> report = DataTypeWorkflow.Single.convertToSingle("MyModel")
it instantly returns:
report =
Report with no properties.
Which I believe it didn’t do anything, but no error or warning was displayed either.
Any help will be appreciated single precision converter r2016b MATLAB Answers — New Questions