Tag Archives: matlab
Problem to converge a loop in Simulink
Hello , I want to simulate a close circuit that consist on a grinding mill next to hydrocyclon and have the following problem with the code that joins two flows tabla1 of dimension 11×5 and TablaFlujo1 of dimension 2×3 are from the input flow, while tabla2 of dimension 11×5 and TablaFlow2 of dimension 2×3 are from the recirculated flow(very important to remark because it causes a loop) from the whole process and in this code they are added together to form a single flow named TablaGranulometrica and TablaFlujo . i tried to initialize the recirculated flow with the desired size,and so the output stream ,but pops a error instead : "Block ”granulometria4/Subsystem3/MATLAB Function5” does not fully set the dimensions of output ‘TablaFlujo’."
I will give attach a screenshot :
I really dont know how to make it converge or at least give an initial condition so it start running . Below is the function script , will also attach the full file. thanks in advance.
function [TablaGranulometrica, TablaFlujo, total,convergencia] = fcn(tabla1, TablaFlujo1, tabla2, TablaFlujo2,epsilon)
if size(tabla2)~=size(tabla2)
tabla2 = tabla1; % Inicializa tabla2 como matriz de ceros del mismo tamaño que tabla1
end
if size(TablaFlujo1)~=size(TablaFlujo2)
TablaFlujo2 = (TablaFlujo1); % Inicializa TablaFlujo2 como matriz de ceros del mismo tamaño que TablaFlujo1
end
% Tabla Granulométrica
TablaGranulometrica = tabla1;
TablaGranulometrica(:,2) = tabla1(:,2) + tabla2(:,2);
total = sum(TablaGranulometrica(:, 2));
TablaGranulometrica(:, 3) = (TablaGranulometrica(:, 2) / total) * 100;
TablaGranulometrica(:, 4) = cumsum(TablaGranulometrica(:, 3));
TablaGranulometrica(:, 5) = 100 – TablaGranulometrica(:, 4);
% Tabla de Flujo
TablaFlujo = size(2, 3); % Dimensiones fijas [2×3]
TablaFlujo = zeros(size(TablaFlujo1)); % Inicializa la salida
TablaFlujo(1,1) = TablaFlujo1(1,1) + TablaFlujo2(1,1);
TablaFlujo(2,3) = TablaFlujo1(2,3) + TablaFlujo2(2,3);
TablaFlujo(2,2) = (TablaFlujo(1,1) / 2.45) + TablaFlujo(2,3);
TablaFlujo(2,1) = 100 * TablaFlujo(1,1) / (TablaFlujo(1,1) + TablaFlujo(2,3));
TablaFlujo(1,2) = 100 * (TablaFlujo(1,1)) / (TablaFlujo(2,1) * TablaFlujo(2,2));
TablaFlujo(1,3) = 2.45;
% Cálculo final de total
total = sum(TablaGranulometrica(:,2)) * 24;
error_tabla = max(abs(tabla1(:,2) – tabla2(:,2)));
error_flujo = max(abs(TablaFlujo1(:,1) – TablaFlujo2(:,1)));
convergencia = (error_tabla < epsilon) && (error_flujo < epsilon);
endHello , I want to simulate a close circuit that consist on a grinding mill next to hydrocyclon and have the following problem with the code that joins two flows tabla1 of dimension 11×5 and TablaFlujo1 of dimension 2×3 are from the input flow, while tabla2 of dimension 11×5 and TablaFlow2 of dimension 2×3 are from the recirculated flow(very important to remark because it causes a loop) from the whole process and in this code they are added together to form a single flow named TablaGranulometrica and TablaFlujo . i tried to initialize the recirculated flow with the desired size,and so the output stream ,but pops a error instead : "Block ”granulometria4/Subsystem3/MATLAB Function5” does not fully set the dimensions of output ‘TablaFlujo’."
I will give attach a screenshot :
I really dont know how to make it converge or at least give an initial condition so it start running . Below is the function script , will also attach the full file. thanks in advance.
function [TablaGranulometrica, TablaFlujo, total,convergencia] = fcn(tabla1, TablaFlujo1, tabla2, TablaFlujo2,epsilon)
if size(tabla2)~=size(tabla2)
tabla2 = tabla1; % Inicializa tabla2 como matriz de ceros del mismo tamaño que tabla1
end
if size(TablaFlujo1)~=size(TablaFlujo2)
TablaFlujo2 = (TablaFlujo1); % Inicializa TablaFlujo2 como matriz de ceros del mismo tamaño que TablaFlujo1
end
% Tabla Granulométrica
TablaGranulometrica = tabla1;
TablaGranulometrica(:,2) = tabla1(:,2) + tabla2(:,2);
total = sum(TablaGranulometrica(:, 2));
TablaGranulometrica(:, 3) = (TablaGranulometrica(:, 2) / total) * 100;
TablaGranulometrica(:, 4) = cumsum(TablaGranulometrica(:, 3));
TablaGranulometrica(:, 5) = 100 – TablaGranulometrica(:, 4);
% Tabla de Flujo
TablaFlujo = size(2, 3); % Dimensiones fijas [2×3]
TablaFlujo = zeros(size(TablaFlujo1)); % Inicializa la salida
TablaFlujo(1,1) = TablaFlujo1(1,1) + TablaFlujo2(1,1);
TablaFlujo(2,3) = TablaFlujo1(2,3) + TablaFlujo2(2,3);
TablaFlujo(2,2) = (TablaFlujo(1,1) / 2.45) + TablaFlujo(2,3);
TablaFlujo(2,1) = 100 * TablaFlujo(1,1) / (TablaFlujo(1,1) + TablaFlujo(2,3));
TablaFlujo(1,2) = 100 * (TablaFlujo(1,1)) / (TablaFlujo(2,1) * TablaFlujo(2,2));
TablaFlujo(1,3) = 2.45;
% Cálculo final de total
total = sum(TablaGranulometrica(:,2)) * 24;
error_tabla = max(abs(tabla1(:,2) – tabla2(:,2)));
error_flujo = max(abs(TablaFlujo1(:,1) – TablaFlujo2(:,1)));
convergencia = (error_tabla < epsilon) && (error_flujo < epsilon);
end Hello , I want to simulate a close circuit that consist on a grinding mill next to hydrocyclon and have the following problem with the code that joins two flows tabla1 of dimension 11×5 and TablaFlujo1 of dimension 2×3 are from the input flow, while tabla2 of dimension 11×5 and TablaFlow2 of dimension 2×3 are from the recirculated flow(very important to remark because it causes a loop) from the whole process and in this code they are added together to form a single flow named TablaGranulometrica and TablaFlujo . i tried to initialize the recirculated flow with the desired size,and so the output stream ,but pops a error instead : "Block ”granulometria4/Subsystem3/MATLAB Function5” does not fully set the dimensions of output ‘TablaFlujo’."
I will give attach a screenshot :
I really dont know how to make it converge or at least give an initial condition so it start running . Below is the function script , will also attach the full file. thanks in advance.
function [TablaGranulometrica, TablaFlujo, total,convergencia] = fcn(tabla1, TablaFlujo1, tabla2, TablaFlujo2,epsilon)
if size(tabla2)~=size(tabla2)
tabla2 = tabla1; % Inicializa tabla2 como matriz de ceros del mismo tamaño que tabla1
end
if size(TablaFlujo1)~=size(TablaFlujo2)
TablaFlujo2 = (TablaFlujo1); % Inicializa TablaFlujo2 como matriz de ceros del mismo tamaño que TablaFlujo1
end
% Tabla Granulométrica
TablaGranulometrica = tabla1;
TablaGranulometrica(:,2) = tabla1(:,2) + tabla2(:,2);
total = sum(TablaGranulometrica(:, 2));
TablaGranulometrica(:, 3) = (TablaGranulometrica(:, 2) / total) * 100;
TablaGranulometrica(:, 4) = cumsum(TablaGranulometrica(:, 3));
TablaGranulometrica(:, 5) = 100 – TablaGranulometrica(:, 4);
% Tabla de Flujo
TablaFlujo = size(2, 3); % Dimensiones fijas [2×3]
TablaFlujo = zeros(size(TablaFlujo1)); % Inicializa la salida
TablaFlujo(1,1) = TablaFlujo1(1,1) + TablaFlujo2(1,1);
TablaFlujo(2,3) = TablaFlujo1(2,3) + TablaFlujo2(2,3);
TablaFlujo(2,2) = (TablaFlujo(1,1) / 2.45) + TablaFlujo(2,3);
TablaFlujo(2,1) = 100 * TablaFlujo(1,1) / (TablaFlujo(1,1) + TablaFlujo(2,3));
TablaFlujo(1,2) = 100 * (TablaFlujo(1,1)) / (TablaFlujo(2,1) * TablaFlujo(2,2));
TablaFlujo(1,3) = 2.45;
% Cálculo final de total
total = sum(TablaGranulometrica(:,2)) * 24;
error_tabla = max(abs(tabla1(:,2) – tabla2(:,2)));
error_flujo = max(abs(TablaFlujo1(:,1) – TablaFlujo2(:,1)));
convergencia = (error_tabla < epsilon) && (error_flujo < epsilon);
end simulink, loop, converge MATLAB Answers — New Questions
How can I generate the setup of AC sweep for AC Voltage source in either Matlab or simulink?
How can I generate the AC sweep for AC Voltage source? To simulate analog filter such as Low pass filter, high pass filter or EMI filter, we need AC sweep setup to run simulation. These AC Analysis includes Type of Sweep (Decade), Number of points per decade (100), Start frequency (10), Stop Frequency (100MEG). How can I generate these setup of the AC sweep for AC Voltage source in either Matlab or simulink?How can I generate the AC sweep for AC Voltage source? To simulate analog filter such as Low pass filter, high pass filter or EMI filter, we need AC sweep setup to run simulation. These AC Analysis includes Type of Sweep (Decade), Number of points per decade (100), Start frequency (10), Stop Frequency (100MEG). How can I generate these setup of the AC sweep for AC Voltage source in either Matlab or simulink? How can I generate the AC sweep for AC Voltage source? To simulate analog filter such as Low pass filter, high pass filter or EMI filter, we need AC sweep setup to run simulation. These AC Analysis includes Type of Sweep (Decade), Number of points per decade (100), Start frequency (10), Stop Frequency (100MEG). How can I generate these setup of the AC sweep for AC Voltage source in either Matlab or simulink? simulink 2014b MATLAB Answers — New Questions
dq-to-abc block does not work when the input is from three-phase measurement block
The dq-to-abc blocks give a constant Vd and Vq when the input block (60Hz) is used is a three phase sine wave generator (Electrical/Specialised Power System). However, when the input is from a three phase measurement block which measure a balanced three phase system the Vd and Vq is a sinusoidal wave with frequency 120Hz and same magnitude as the phase magnitude of the wave.
With measurement block
With Three phase wave generatorThe dq-to-abc blocks give a constant Vd and Vq when the input block (60Hz) is used is a three phase sine wave generator (Electrical/Specialised Power System). However, when the input is from a three phase measurement block which measure a balanced three phase system the Vd and Vq is a sinusoidal wave with frequency 120Hz and same magnitude as the phase magnitude of the wave.
With measurement block
With Three phase wave generator The dq-to-abc blocks give a constant Vd and Vq when the input block (60Hz) is used is a three phase sine wave generator (Electrical/Specialised Power System). However, when the input is from a three phase measurement block which measure a balanced three phase system the Vd and Vq is a sinusoidal wave with frequency 120Hz and same magnitude as the phase magnitude of the wave.
With measurement block
With Three phase wave generator #dq-abc #clarke-park MATLAB Answers — New Questions
define an objective function with user defined number of variables in fminunc()
Suppose I want to define the following function in matlab which returns the output of fminunc(). The problem here is the number of variables depends on the user input. How do I define the objective function fun() such that it automatically adapts to the number of variables.
function xmin = problem(n)
if n == 1
fun = @(x) x^2+2*x+3;
xmin = fminunc(fun,1);
end
if n == 2
fun = @(x) x(1)^2+x(2)^2+2*(x(1)+x(2))+3;
xmin = fminunc(fun,[1 0]);
end
if n == 3
fun = @(x) x(1)^2+x(2)^2+x(3)^2+2*(x(1)+x(2)+x(3))+3;
xmin = fminunc(fun,[1 0 0]);
end
% n is the number of variables for fun.
% the list goes on. n==4, n==5,…
endSuppose I want to define the following function in matlab which returns the output of fminunc(). The problem here is the number of variables depends on the user input. How do I define the objective function fun() such that it automatically adapts to the number of variables.
function xmin = problem(n)
if n == 1
fun = @(x) x^2+2*x+3;
xmin = fminunc(fun,1);
end
if n == 2
fun = @(x) x(1)^2+x(2)^2+2*(x(1)+x(2))+3;
xmin = fminunc(fun,[1 0]);
end
if n == 3
fun = @(x) x(1)^2+x(2)^2+x(3)^2+2*(x(1)+x(2)+x(3))+3;
xmin = fminunc(fun,[1 0 0]);
end
% n is the number of variables for fun.
% the list goes on. n==4, n==5,…
end Suppose I want to define the following function in matlab which returns the output of fminunc(). The problem here is the number of variables depends on the user input. How do I define the objective function fun() such that it automatically adapts to the number of variables.
function xmin = problem(n)
if n == 1
fun = @(x) x^2+2*x+3;
xmin = fminunc(fun,1);
end
if n == 2
fun = @(x) x(1)^2+x(2)^2+2*(x(1)+x(2))+3;
xmin = fminunc(fun,[1 0]);
end
if n == 3
fun = @(x) x(1)^2+x(2)^2+x(3)^2+2*(x(1)+x(2)+x(3))+3;
xmin = fminunc(fun,[1 0 0]);
end
% n is the number of variables for fun.
% the list goes on. n==4, n==5,…
end fminunc MATLAB Answers — New Questions
Can the number of points in current function in Matlab Antenna Toolbox be manually assigned?
I’ve defined a half-wavelength antenna, and I use the current function in Matlab Antenna Toolbox to get the value of the current over the entire antenna, which is discrete point by point. I found that the current function in Matlab Antenna Toolbox can divide the antenna into several points with different densities according to the physical meaning of the antenna, but I don’t know the inner method of this division. Then I change the position of the feedpoint in this dipole. Each time I change the position of the feedpoint, the number of points divided by the current function changes. But I want to store the current value of each feedpoint in a matrix, so I want the number of points can be manually determined. However, I did not find such an operation in Matlab. I could only change the mesh size of maxEdgeLength, but I could not determine the number of points. Is there a similar operation in Matlab?
ant = dipole(‘Length’, L, ‘Width’, 10e-4*L); % Define length and width
maxEdgeLength = L / 60;
mesh(ant, ‘MaxEdgeLength’, maxEdgeLength);
[currentData, points] = current(ant, f);I’ve defined a half-wavelength antenna, and I use the current function in Matlab Antenna Toolbox to get the value of the current over the entire antenna, which is discrete point by point. I found that the current function in Matlab Antenna Toolbox can divide the antenna into several points with different densities according to the physical meaning of the antenna, but I don’t know the inner method of this division. Then I change the position of the feedpoint in this dipole. Each time I change the position of the feedpoint, the number of points divided by the current function changes. But I want to store the current value of each feedpoint in a matrix, so I want the number of points can be manually determined. However, I did not find such an operation in Matlab. I could only change the mesh size of maxEdgeLength, but I could not determine the number of points. Is there a similar operation in Matlab?
ant = dipole(‘Length’, L, ‘Width’, 10e-4*L); % Define length and width
maxEdgeLength = L / 60;
mesh(ant, ‘MaxEdgeLength’, maxEdgeLength);
[currentData, points] = current(ant, f); I’ve defined a half-wavelength antenna, and I use the current function in Matlab Antenna Toolbox to get the value of the current over the entire antenna, which is discrete point by point. I found that the current function in Matlab Antenna Toolbox can divide the antenna into several points with different densities according to the physical meaning of the antenna, but I don’t know the inner method of this division. Then I change the position of the feedpoint in this dipole. Each time I change the position of the feedpoint, the number of points divided by the current function changes. But I want to store the current value of each feedpoint in a matrix, so I want the number of points can be manually determined. However, I did not find such an operation in Matlab. I could only change the mesh size of maxEdgeLength, but I could not determine the number of points. Is there a similar operation in Matlab?
ant = dipole(‘Length’, L, ‘Width’, 10e-4*L); % Define length and width
maxEdgeLength = L / 60;
mesh(ant, ‘MaxEdgeLength’, maxEdgeLength);
[currentData, points] = current(ant, f); antenna toolbox, current MATLAB Answers — New Questions
Complex multiplication giving incorrect result
I have a vector A of complex numbers but the product of the numbers should result in real value (there complex conjugate values that make sure the product is real). But when I run prod(A) I get an incorrect result.
A = 1.0e+08 *[-1.1051 + 0.0000i -0.4594 + 1.8182i -0.4594 – 1.8182i -0.2933 + 2.8161i -0.2933 – 2.8161i];
prod(A) = -3.1156e+41 – 9.6714e+24i
The correct value should be -3.1156e+41. why is MATLAB giving incorrect result here?I have a vector A of complex numbers but the product of the numbers should result in real value (there complex conjugate values that make sure the product is real). But when I run prod(A) I get an incorrect result.
A = 1.0e+08 *[-1.1051 + 0.0000i -0.4594 + 1.8182i -0.4594 – 1.8182i -0.2933 + 2.8161i -0.2933 – 2.8161i];
prod(A) = -3.1156e+41 – 9.6714e+24i
The correct value should be -3.1156e+41. why is MATLAB giving incorrect result here? I have a vector A of complex numbers but the product of the numbers should result in real value (there complex conjugate values that make sure the product is real). But when I run prod(A) I get an incorrect result.
A = 1.0e+08 *[-1.1051 + 0.0000i -0.4594 + 1.8182i -0.4594 – 1.8182i -0.2933 + 2.8161i -0.2933 – 2.8161i];
prod(A) = -3.1156e+41 – 9.6714e+24i
The correct value should be -3.1156e+41. why is MATLAB giving incorrect result here? matlab, mathematics MATLAB Answers — New Questions
License borrowing without network access
I’m running Matlab 2014b and I need to install Matlab and borrow one of our floating licenses onto a PC which is not allowed to connect to the internet or intranet.
As far as I can determine, in order to use the license borrowing feature, the PC initially has to be connected to the network. This is not an option for me.
Is there any way to transfer a borrowed license onto a PC without network access – like using a memory stick or similar?I’m running Matlab 2014b and I need to install Matlab and borrow one of our floating licenses onto a PC which is not allowed to connect to the internet or intranet.
As far as I can determine, in order to use the license borrowing feature, the PC initially has to be connected to the network. This is not an option for me.
Is there any way to transfer a borrowed license onto a PC without network access – like using a memory stick or similar? I’m running Matlab 2014b and I need to install Matlab and borrow one of our floating licenses onto a PC which is not allowed to connect to the internet or intranet.
As far as I can determine, in order to use the license borrowing feature, the PC initially has to be connected to the network. This is not an option for me.
Is there any way to transfer a borrowed license onto a PC without network access – like using a memory stick or similar? license borrowing, no network MATLAB Answers — New Questions
How to create text editor in matlab?
I dont know how to create a text editor in matlab.Can anybody help me to create simple text editor.I dont know how to create a text editor in matlab.Can anybody help me to create simple text editor. I dont know how to create a text editor in matlab.Can anybody help me to create simple text editor. text, editor MATLAB Answers — New Questions
How can I control the voxel size using ‘imwrite’?
Hello All,
I have an input tiff file image that has 342 slices, and I would like to extract each slice individually and save as a separate file.
% x = imread("inputTiffFile.tif", 100);
% imwrite(x, "slice_100.tif");
% x = imread("inputTiffFile.tif", 163);
% imwrite(x, "slice_163.tif");
However, I have one problem: The voxel spacing in the input image is [1, 1, 1], but the voxel spacing after using ‘imwrite’ is changed to [0.352778, 0.352778, 1]. I require the voxel spacing to be same as input.
Any inputs on how to avoid this change in voxel size would be very helpful.
Thanks,Hello All,
I have an input tiff file image that has 342 slices, and I would like to extract each slice individually and save as a separate file.
% x = imread("inputTiffFile.tif", 100);
% imwrite(x, "slice_100.tif");
% x = imread("inputTiffFile.tif", 163);
% imwrite(x, "slice_163.tif");
However, I have one problem: The voxel spacing in the input image is [1, 1, 1], but the voxel spacing after using ‘imwrite’ is changed to [0.352778, 0.352778, 1]. I require the voxel spacing to be same as input.
Any inputs on how to avoid this change in voxel size would be very helpful.
Thanks, Hello All,
I have an input tiff file image that has 342 slices, and I would like to extract each slice individually and save as a separate file.
% x = imread("inputTiffFile.tif", 100);
% imwrite(x, "slice_100.tif");
% x = imread("inputTiffFile.tif", 163);
% imwrite(x, "slice_163.tif");
However, I have one problem: The voxel spacing in the input image is [1, 1, 1], but the voxel spacing after using ‘imwrite’ is changed to [0.352778, 0.352778, 1]. I require the voxel spacing to be same as input.
Any inputs on how to avoid this change in voxel size would be very helpful.
Thanks, voxel_spacing, imwrite MATLAB Answers — New Questions
How to disable the display of coverage report once the simulation is stopped
I am in a situation where I need to collect cumulative coverage after multiple simulation restarts. Right now, whenever I hit the stop button, the coverage report is getting generated and it consumes some time, instead am wondering if I can disable the coverage report geneartion and instead save it to a workspace variable and generate the reports at once after all my runs?I am in a situation where I need to collect cumulative coverage after multiple simulation restarts. Right now, whenever I hit the stop button, the coverage report is getting generated and it consumes some time, instead am wondering if I can disable the coverage report geneartion and instead save it to a workspace variable and generate the reports at once after all my runs? I am in a situation where I need to collect cumulative coverage after multiple simulation restarts. Right now, whenever I hit the stop button, the coverage report is getting generated and it consumes some time, instead am wondering if I can disable the coverage report geneartion and instead save it to a workspace variable and generate the reports at once after all my runs? coverage report generation MATLAB Answers — New Questions
How to Calculate dominant frequency and centroid frequency and plot them together
please help me, I would like to calculate dominant and centroid frequency and plot them tohether in one plot. Please CMIIW if i have misundertanding the basic concept. As I undertand, dominant freq is higest freq that appear in our signal. I used FFT and get the max power. And about dominant freq I am not quite sure. What makes me don’t understand is, if I take example from weighted mean as basic of centroid freq, based on example in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean, after calculate weighted mean we have weighted mean of the frequencies present in the signal, meaning that is not a single value. I use spectralCentroid to calculate centroid frequency, but then i confuse, if i have single falue for dominant freq and several value from spectralCentroid, how i should plot them together?
i also attach my file, basically the code will doing looping as my file represent one day data, so my goal is plot dominant and centroid freq in one plot for 1 month. I assume my dominant freq has 30 data point, but not sure about spectralCentroid.
this is my attempt to do it.
sig=load(‘signal2023-335.txt’);
%BAND PASS FILTER long range –> can be considered as UNFILTER condition
% Define the parameters
lowcut = 1/400; % Low cutoff frequency in Hz
high1 = 40; % High cutoff frequency in Hz
high2 = 1.25; % Midrange cutoff frequency in Hz
fs = 100; % Sampling frequency in Hz
% Design the Butterworth bandpass filter (UNFILTER)
[bU, aU] = butter(2,[lowcut high1] / (fs / 2), ‘bandpass’);
sigUnfilt= filtfilt(bU,aU,sig);
% calculate FFT UNFILT
n=length(sigUnfilt);
srate=100; %sampling rate
nyq=srate/2;
fftsig=fft(sigUnfilt-mean(sigUnfilt))/n; %dataX is fft result from filtered signal
hz=linspace(0,nyq,floor(n/2)+1);
pow=2*abs(fftsig(1:length(hz)));
Iv = 1:numel(hz);
%get the maximum freq/dominant freq
[~,idx] = max(pow) ;
domfreq = hz(idx)
% Calculate centroid frequency
centroid = spectralCentroid(sigUnfilt,100)please help me, I would like to calculate dominant and centroid frequency and plot them tohether in one plot. Please CMIIW if i have misundertanding the basic concept. As I undertand, dominant freq is higest freq that appear in our signal. I used FFT and get the max power. And about dominant freq I am not quite sure. What makes me don’t understand is, if I take example from weighted mean as basic of centroid freq, based on example in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean, after calculate weighted mean we have weighted mean of the frequencies present in the signal, meaning that is not a single value. I use spectralCentroid to calculate centroid frequency, but then i confuse, if i have single falue for dominant freq and several value from spectralCentroid, how i should plot them together?
i also attach my file, basically the code will doing looping as my file represent one day data, so my goal is plot dominant and centroid freq in one plot for 1 month. I assume my dominant freq has 30 data point, but not sure about spectralCentroid.
this is my attempt to do it.
sig=load(‘signal2023-335.txt’);
%BAND PASS FILTER long range –> can be considered as UNFILTER condition
% Define the parameters
lowcut = 1/400; % Low cutoff frequency in Hz
high1 = 40; % High cutoff frequency in Hz
high2 = 1.25; % Midrange cutoff frequency in Hz
fs = 100; % Sampling frequency in Hz
% Design the Butterworth bandpass filter (UNFILTER)
[bU, aU] = butter(2,[lowcut high1] / (fs / 2), ‘bandpass’);
sigUnfilt= filtfilt(bU,aU,sig);
% calculate FFT UNFILT
n=length(sigUnfilt);
srate=100; %sampling rate
nyq=srate/2;
fftsig=fft(sigUnfilt-mean(sigUnfilt))/n; %dataX is fft result from filtered signal
hz=linspace(0,nyq,floor(n/2)+1);
pow=2*abs(fftsig(1:length(hz)));
Iv = 1:numel(hz);
%get the maximum freq/dominant freq
[~,idx] = max(pow) ;
domfreq = hz(idx)
% Calculate centroid frequency
centroid = spectralCentroid(sigUnfilt,100) please help me, I would like to calculate dominant and centroid frequency and plot them tohether in one plot. Please CMIIW if i have misundertanding the basic concept. As I undertand, dominant freq is higest freq that appear in our signal. I used FFT and get the max power. And about dominant freq I am not quite sure. What makes me don’t understand is, if I take example from weighted mean as basic of centroid freq, based on example in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean, after calculate weighted mean we have weighted mean of the frequencies present in the signal, meaning that is not a single value. I use spectralCentroid to calculate centroid frequency, but then i confuse, if i have single falue for dominant freq and several value from spectralCentroid, how i should plot them together?
i also attach my file, basically the code will doing looping as my file represent one day data, so my goal is plot dominant and centroid freq in one plot for 1 month. I assume my dominant freq has 30 data point, but not sure about spectralCentroid.
this is my attempt to do it.
sig=load(‘signal2023-335.txt’);
%BAND PASS FILTER long range –> can be considered as UNFILTER condition
% Define the parameters
lowcut = 1/400; % Low cutoff frequency in Hz
high1 = 40; % High cutoff frequency in Hz
high2 = 1.25; % Midrange cutoff frequency in Hz
fs = 100; % Sampling frequency in Hz
% Design the Butterworth bandpass filter (UNFILTER)
[bU, aU] = butter(2,[lowcut high1] / (fs / 2), ‘bandpass’);
sigUnfilt= filtfilt(bU,aU,sig);
% calculate FFT UNFILT
n=length(sigUnfilt);
srate=100; %sampling rate
nyq=srate/2;
fftsig=fft(sigUnfilt-mean(sigUnfilt))/n; %dataX is fft result from filtered signal
hz=linspace(0,nyq,floor(n/2)+1);
pow=2*abs(fftsig(1:length(hz)));
Iv = 1:numel(hz);
%get the maximum freq/dominant freq
[~,idx] = max(pow) ;
domfreq = hz(idx)
% Calculate centroid frequency
centroid = spectralCentroid(sigUnfilt,100) centroid frequency, fft, centroid, weighted mean MATLAB Answers — New Questions
Matlab R2019b no window manager on Ubuntu 18.04
Hi,
Recently when I start matlab the application has no window manager i.e. no top bar, minimize/maximize buttons etc. Even the keyboard shortcuts for these actions have no effect. This behaviour started recently and I am not sure why or how to find the root cause. Does anyone have any hints?
Thanks in advance.Hi,
Recently when I start matlab the application has no window manager i.e. no top bar, minimize/maximize buttons etc. Even the keyboard shortcuts for these actions have no effect. This behaviour started recently and I am not sure why or how to find the root cause. Does anyone have any hints?
Thanks in advance. Hi,
Recently when I start matlab the application has no window manager i.e. no top bar, minimize/maximize buttons etc. Even the keyboard shortcuts for these actions have no effect. This behaviour started recently and I am not sure why or how to find the root cause. Does anyone have any hints?
Thanks in advance. ubuntu MATLAB Answers — New Questions
Find imapedance of a circuit with mesured current and voltage and frequency sweep(up to 1MHz). C and L are unknow.
I have a mesured voltage and current. I want to find the impedance magnitude, real and imaginary part then plot yquist and cole-cole plot, but i don’t know to proceed, can someone help please.I have a mesured voltage and current. I want to find the impedance magnitude, real and imaginary part then plot yquist and cole-cole plot, but i don’t know to proceed, can someone help please. I have a mesured voltage and current. I want to find the impedance magnitude, real and imaginary part then plot yquist and cole-cole plot, but i don’t know to proceed, can someone help please. impedance, varying frequency, frequency sweep, nyquist, cole cole plot MATLAB Answers — New Questions
Vertically Concatenating Timetables of Different Sizes
As the title states, I wish to do just that. More specifically, I need to combine n timetables, each with one row, but varying column counts (Dimension counts). There is a nonzero intersection between each timetable, and so there are data being shared between each. However, some may also have data that other’s do not.
The goal here is to vertically concatenate each timetable so that all the data within the intersection are aligned by column/dimension name type. If there are data that are missing and so one timetable is smaller than the other, then that dimension/data type will be populated as a ‘NaN’ within the smaller timetable. In the example I give below, I say there are three timetables of lengths 1×40, 1×36 and 1×30. I wish to get a resulting timetable that is then 3×40.
Method 1:
Obviously doesn’t work as the # of columns are different.
Method 2:
I tried using a solution on another post that does exactly what I want, but with tables instead of timetables. This did not give the correct result as the output is a 3×215, which I don’t understand why. It also combines the dimension labels with “All” which doesn’t make sense to me as I specify “MergeKeys” as “True” which should leave the dimension labels alone according to the documentation. It comes close though in that it does concatenate the datetimes correctly and populates empty data/units with ‘NaN’s. I tried specifying the “Key” variables to align to, but because some timetables do not contain these variables and the Matlab function outerjoin wasn’t built to create missing variable columns that auto populate with NaNs when it encounters this, this does not work.
Method 3:
I tried using the synchronize function as this is specifically geared towards timetables. I get the exact same resulting timetable as Method 2. The synchronize documentation and "Combine Timetables and Synchronize Their Data" documentation give examples that do the exact same thing (Just that I have more columns and different dimension names) as my example from what I can see, so I am even more confused by why this does not produce the same result that I would like.
So I think I am just not employing Methods 2,3 correctly or I may have to create another for-loop prior to concatenation that creates the new variables in the smaller timetables and populates them with NaNs using indexing of the largest timetable.
%Create 3 timetables of different sizes and random dimension names with nonzero intersections
varTypes = {‘string’};
doub = ‘double’;
str = ‘string’;
szList = [40,36,30];
ind = {‘A’,’B’,’C’};
TimeDim = [datetime(‘2023-01-01 20:14:58’),datetime(‘2023-02-21 22:13:04’),datetime(‘2023-03-11 10:12:58’)];
for i = 1:length(szList)
for j = 1:szList(i)
varTypes{end+1} = doub;
varTypes{end+1} = str;
end
ArrayList.ind{i} = varTypes;
varTypes = {‘string’};
end
clear i j
for i = 1:length(szList)
ttSaved.ind{i} = timetable(‘Size’,[1 2*szList(i)+1],’VariableTypes’,ArrayList.ind{1,i},’RowTimes’,TimeDim(i));
ttSaved.ind{i} = renamevars(ttSaved.ind{i},’Var1′,’Exp_ID’);
ttSaved.ind{i}.Exp_ID = i;
end
clear i
%Label each dimenion and populate tables with data
for i = 1:length(ttSaved.ind)
choice = randperm(szList(i));
for j = 1:szList(i)
ttSaved.ind{i} = renamevars(ttSaved.ind{i},sprintf(‘Var%d’,2*j),sprintf(‘Data_%d’,choice(j)));
ttSaved.ind{i} = renamevars(ttSaved.ind{i},sprintf(‘Var%d’,2*j+1),sprintf(‘Units_%d’,choice(j)));
end
Names = ttSaved.ind{i}.Properties.VariableNames;
for k = 1:szList(i)
ttSaved.ind{i}.(Names{2*k}) = rand*100; %Add data
ttSaved.ind{i}.(Names{2*k+1}) = char(choice(k)); %Add Units
end
end
clear i j k
%Method 1
ttAll = [];
for i = 1:length(ttSaved.ind)
ttAll = [ttAll ; ttSaved.ind{i}];
end
clear i
%Method 2
ttAll = ttSaved.ind{1};
AllMeas = ttSaved.ind{1}.Properties.VariableNames;
for i = 2:length(ttSaved.ind)
ttAll = outerjoin(ttAll,ttSaved.ind{i},’Keys’,AllMeas,’MergeKeys’, true);
end
clear i
%Method 3
ttAll2 = ttSaved.ind{1};
for i = 2:length(ttSaved.ind)
ttAll2 = synchronize(ttAll2,ttSaved.ind{i});
end
clear i
Note: This post is somewhat of a continuation of a previous post, but since I marked the last as answered and this one is different enough and contains the same data structures to my actual data, I needed create a new question.As the title states, I wish to do just that. More specifically, I need to combine n timetables, each with one row, but varying column counts (Dimension counts). There is a nonzero intersection between each timetable, and so there are data being shared between each. However, some may also have data that other’s do not.
The goal here is to vertically concatenate each timetable so that all the data within the intersection are aligned by column/dimension name type. If there are data that are missing and so one timetable is smaller than the other, then that dimension/data type will be populated as a ‘NaN’ within the smaller timetable. In the example I give below, I say there are three timetables of lengths 1×40, 1×36 and 1×30. I wish to get a resulting timetable that is then 3×40.
Method 1:
Obviously doesn’t work as the # of columns are different.
Method 2:
I tried using a solution on another post that does exactly what I want, but with tables instead of timetables. This did not give the correct result as the output is a 3×215, which I don’t understand why. It also combines the dimension labels with “All” which doesn’t make sense to me as I specify “MergeKeys” as “True” which should leave the dimension labels alone according to the documentation. It comes close though in that it does concatenate the datetimes correctly and populates empty data/units with ‘NaN’s. I tried specifying the “Key” variables to align to, but because some timetables do not contain these variables and the Matlab function outerjoin wasn’t built to create missing variable columns that auto populate with NaNs when it encounters this, this does not work.
Method 3:
I tried using the synchronize function as this is specifically geared towards timetables. I get the exact same resulting timetable as Method 2. The synchronize documentation and "Combine Timetables and Synchronize Their Data" documentation give examples that do the exact same thing (Just that I have more columns and different dimension names) as my example from what I can see, so I am even more confused by why this does not produce the same result that I would like.
So I think I am just not employing Methods 2,3 correctly or I may have to create another for-loop prior to concatenation that creates the new variables in the smaller timetables and populates them with NaNs using indexing of the largest timetable.
%Create 3 timetables of different sizes and random dimension names with nonzero intersections
varTypes = {‘string’};
doub = ‘double’;
str = ‘string’;
szList = [40,36,30];
ind = {‘A’,’B’,’C’};
TimeDim = [datetime(‘2023-01-01 20:14:58’),datetime(‘2023-02-21 22:13:04’),datetime(‘2023-03-11 10:12:58’)];
for i = 1:length(szList)
for j = 1:szList(i)
varTypes{end+1} = doub;
varTypes{end+1} = str;
end
ArrayList.ind{i} = varTypes;
varTypes = {‘string’};
end
clear i j
for i = 1:length(szList)
ttSaved.ind{i} = timetable(‘Size’,[1 2*szList(i)+1],’VariableTypes’,ArrayList.ind{1,i},’RowTimes’,TimeDim(i));
ttSaved.ind{i} = renamevars(ttSaved.ind{i},’Var1′,’Exp_ID’);
ttSaved.ind{i}.Exp_ID = i;
end
clear i
%Label each dimenion and populate tables with data
for i = 1:length(ttSaved.ind)
choice = randperm(szList(i));
for j = 1:szList(i)
ttSaved.ind{i} = renamevars(ttSaved.ind{i},sprintf(‘Var%d’,2*j),sprintf(‘Data_%d’,choice(j)));
ttSaved.ind{i} = renamevars(ttSaved.ind{i},sprintf(‘Var%d’,2*j+1),sprintf(‘Units_%d’,choice(j)));
end
Names = ttSaved.ind{i}.Properties.VariableNames;
for k = 1:szList(i)
ttSaved.ind{i}.(Names{2*k}) = rand*100; %Add data
ttSaved.ind{i}.(Names{2*k+1}) = char(choice(k)); %Add Units
end
end
clear i j k
%Method 1
ttAll = [];
for i = 1:length(ttSaved.ind)
ttAll = [ttAll ; ttSaved.ind{i}];
end
clear i
%Method 2
ttAll = ttSaved.ind{1};
AllMeas = ttSaved.ind{1}.Properties.VariableNames;
for i = 2:length(ttSaved.ind)
ttAll = outerjoin(ttAll,ttSaved.ind{i},’Keys’,AllMeas,’MergeKeys’, true);
end
clear i
%Method 3
ttAll2 = ttSaved.ind{1};
for i = 2:length(ttSaved.ind)
ttAll2 = synchronize(ttAll2,ttSaved.ind{i});
end
clear i
Note: This post is somewhat of a continuation of a previous post, but since I marked the last as answered and this one is different enough and contains the same data structures to my actual data, I needed create a new question. As the title states, I wish to do just that. More specifically, I need to combine n timetables, each with one row, but varying column counts (Dimension counts). There is a nonzero intersection between each timetable, and so there are data being shared between each. However, some may also have data that other’s do not.
The goal here is to vertically concatenate each timetable so that all the data within the intersection are aligned by column/dimension name type. If there are data that are missing and so one timetable is smaller than the other, then that dimension/data type will be populated as a ‘NaN’ within the smaller timetable. In the example I give below, I say there are three timetables of lengths 1×40, 1×36 and 1×30. I wish to get a resulting timetable that is then 3×40.
Method 1:
Obviously doesn’t work as the # of columns are different.
Method 2:
I tried using a solution on another post that does exactly what I want, but with tables instead of timetables. This did not give the correct result as the output is a 3×215, which I don’t understand why. It also combines the dimension labels with “All” which doesn’t make sense to me as I specify “MergeKeys” as “True” which should leave the dimension labels alone according to the documentation. It comes close though in that it does concatenate the datetimes correctly and populates empty data/units with ‘NaN’s. I tried specifying the “Key” variables to align to, but because some timetables do not contain these variables and the Matlab function outerjoin wasn’t built to create missing variable columns that auto populate with NaNs when it encounters this, this does not work.
Method 3:
I tried using the synchronize function as this is specifically geared towards timetables. I get the exact same resulting timetable as Method 2. The synchronize documentation and "Combine Timetables and Synchronize Their Data" documentation give examples that do the exact same thing (Just that I have more columns and different dimension names) as my example from what I can see, so I am even more confused by why this does not produce the same result that I would like.
So I think I am just not employing Methods 2,3 correctly or I may have to create another for-loop prior to concatenation that creates the new variables in the smaller timetables and populates them with NaNs using indexing of the largest timetable.
%Create 3 timetables of different sizes and random dimension names with nonzero intersections
varTypes = {‘string’};
doub = ‘double’;
str = ‘string’;
szList = [40,36,30];
ind = {‘A’,’B’,’C’};
TimeDim = [datetime(‘2023-01-01 20:14:58’),datetime(‘2023-02-21 22:13:04’),datetime(‘2023-03-11 10:12:58’)];
for i = 1:length(szList)
for j = 1:szList(i)
varTypes{end+1} = doub;
varTypes{end+1} = str;
end
ArrayList.ind{i} = varTypes;
varTypes = {‘string’};
end
clear i j
for i = 1:length(szList)
ttSaved.ind{i} = timetable(‘Size’,[1 2*szList(i)+1],’VariableTypes’,ArrayList.ind{1,i},’RowTimes’,TimeDim(i));
ttSaved.ind{i} = renamevars(ttSaved.ind{i},’Var1′,’Exp_ID’);
ttSaved.ind{i}.Exp_ID = i;
end
clear i
%Label each dimenion and populate tables with data
for i = 1:length(ttSaved.ind)
choice = randperm(szList(i));
for j = 1:szList(i)
ttSaved.ind{i} = renamevars(ttSaved.ind{i},sprintf(‘Var%d’,2*j),sprintf(‘Data_%d’,choice(j)));
ttSaved.ind{i} = renamevars(ttSaved.ind{i},sprintf(‘Var%d’,2*j+1),sprintf(‘Units_%d’,choice(j)));
end
Names = ttSaved.ind{i}.Properties.VariableNames;
for k = 1:szList(i)
ttSaved.ind{i}.(Names{2*k}) = rand*100; %Add data
ttSaved.ind{i}.(Names{2*k+1}) = char(choice(k)); %Add Units
end
end
clear i j k
%Method 1
ttAll = [];
for i = 1:length(ttSaved.ind)
ttAll = [ttAll ; ttSaved.ind{i}];
end
clear i
%Method 2
ttAll = ttSaved.ind{1};
AllMeas = ttSaved.ind{1}.Properties.VariableNames;
for i = 2:length(ttSaved.ind)
ttAll = outerjoin(ttAll,ttSaved.ind{i},’Keys’,AllMeas,’MergeKeys’, true);
end
clear i
%Method 3
ttAll2 = ttSaved.ind{1};
for i = 2:length(ttSaved.ind)
ttAll2 = synchronize(ttAll2,ttSaved.ind{i});
end
clear i
Note: This post is somewhat of a continuation of a previous post, but since I marked the last as answered and this one is different enough and contains the same data structures to my actual data, I needed create a new question. timetables, concatenating timetables, concatenation, synchronize MATLAB Answers — New Questions
Geotagging my coordinates with images
Hi,there . The code that i want to write is :(i have a file of images and each images has a gps coordination in my csv excel file , well i need a code that gets a coordinates from my excel and tags it to it’s own picture… and at the end when i get the properties of my pictures i can see the coordinates in details) … i wrote to many codes but I wasn’t successful …plz help me to solve it ..thank you . And i took an example of my code .
Picfile=(“address”);coordsfile=(“address.csv”);
for i = 1:height(coords)
filename = coords.Filename{i};
lat = coords.Latitude(i);
lon = coords.Longitude(i);
command = sprintf( lat, lon, filename);
system([‘exiftool ‘ command]);
endHi,there . The code that i want to write is :(i have a file of images and each images has a gps coordination in my csv excel file , well i need a code that gets a coordinates from my excel and tags it to it’s own picture… and at the end when i get the properties of my pictures i can see the coordinates in details) … i wrote to many codes but I wasn’t successful …plz help me to solve it ..thank you . And i took an example of my code .
Picfile=(“address”);coordsfile=(“address.csv”);
for i = 1:height(coords)
filename = coords.Filename{i};
lat = coords.Latitude(i);
lon = coords.Longitude(i);
command = sprintf( lat, lon, filename);
system([‘exiftool ‘ command]);
end Hi,there . The code that i want to write is :(i have a file of images and each images has a gps coordination in my csv excel file , well i need a code that gets a coordinates from my excel and tags it to it’s own picture… and at the end when i get the properties of my pictures i can see the coordinates in details) … i wrote to many codes but I wasn’t successful …plz help me to solve it ..thank you . And i took an example of my code .
Picfile=(“address”);coordsfile=(“address.csv”);
for i = 1:height(coords)
filename = coords.Filename{i};
lat = coords.Latitude(i);
lon = coords.Longitude(i);
command = sprintf( lat, lon, filename);
system([‘exiftool ‘ command]);
end tagging MATLAB Answers — New Questions
‘parpool(2)’ fails
Hi, I am testing some MATLAB code via GitHub Action. Strange bug occurs when I was testing `parpool(2)` with MATLAB R2021b and R2022a on Mac and Ubuntu as follows.
Error using parpool
Undefined function ‘pCurrentTaskIsPartOfAPool’ for input arguments of type
‘double’.
Error in solveAllProblems (line 68)
parpool(numJobs);
The code is fine with the latest verion of MATLAB.
Any comment helps.Hi, I am testing some MATLAB code via GitHub Action. Strange bug occurs when I was testing `parpool(2)` with MATLAB R2021b and R2022a on Mac and Ubuntu as follows.
Error using parpool
Undefined function ‘pCurrentTaskIsPartOfAPool’ for input arguments of type
‘double’.
Error in solveAllProblems (line 68)
parpool(numJobs);
The code is fine with the latest verion of MATLAB.
Any comment helps. Hi, I am testing some MATLAB code via GitHub Action. Strange bug occurs when I was testing `parpool(2)` with MATLAB R2021b and R2022a on Mac and Ubuntu as follows.
Error using parpool
Undefined function ‘pCurrentTaskIsPartOfAPool’ for input arguments of type
‘double’.
Error in solveAllProblems (line 68)
parpool(numJobs);
The code is fine with the latest verion of MATLAB.
Any comment helps. parfor, parallel computing, parallel computing toolbox MATLAB Answers — New Questions
How can you add GPS location data to a Image
I am trying to combine GPS data and video. I have a GPS device which gives me gps/nmea format gps data. I am reading each frame from the video and storing it as a image and want to add GPSInfo (metadata) to it. If I use the IMWRITE function, it doesn’t let me add the GPSInfo data since its not a tag which can be edited or changed.
How can I then geotag images using MATLAB?I am trying to combine GPS data and video. I have a GPS device which gives me gps/nmea format gps data. I am reading each frame from the video and storing it as a image and want to add GPSInfo (metadata) to it. If I use the IMWRITE function, it doesn’t let me add the GPSInfo data since its not a tag which can be edited or changed.
How can I then geotag images using MATLAB? I am trying to combine GPS data and video. I have a GPS device which gives me gps/nmea format gps data. I am reading each frame from the video and storing it as a image and want to add GPSInfo (metadata) to it. If I use the IMWRITE function, it doesn’t let me add the GPSInfo data since its not a tag which can be edited or changed.
How can I then geotag images using MATLAB? geotagging images, gps, video processing, gps tagging MATLAB Answers — New Questions
Como evaluar un curso hecho en la plataforma de Matlab?
Estoy organizando un curso de introduccion a Matlab, quero saber el como evaluar el avance y desarrollo de las cursos online, que se enseña en la plataforma.Estoy organizando un curso de introduccion a Matlab, quero saber el como evaluar el avance y desarrollo de las cursos online, que se enseña en la plataforma. Estoy organizando un curso de introduccion a Matlab, quero saber el como evaluar el avance y desarrollo de las cursos online, que se enseña en la plataforma. cursos, online, evaluacion, matlab MATLAB Answers — New Questions
How can I use Createpde to solve a fourth degree partial differential equation?
Hello,
How can I use Createpde to solve the a fourth degree partial differential equation?
∇4(u)=q/D?Hello,
How can I use Createpde to solve the a fourth degree partial differential equation?
∇4(u)=q/D? Hello,
How can I use Createpde to solve the a fourth degree partial differential equation?
∇4(u)=q/D? createpde MATLAB Answers — New Questions
Generation of C++ Code from DAGNetwork fails
Dear cummunity,
I try to generate C/C++ code from an DAGNetwork, which is generated imported from an ONNX model. When I try to run this model in MATLAB itself, no errrors occour. The model is saved as *.mat file. Loading and running the model again is working well.
If I want to generate C/C++ code from the model via the following code (in two separate files gencode.m and myNet_predict.m), I get the error message: ??? Layer hyper-parameters for custom layer ‘PadLayer1183’ must be numeric scalar, scalar logical, character or string array, or a matrix of type double or single.
% codegen.m
cfg = coder.config(‘mex’);
cfg.TargetLang = ‘C++’;
cfg.DeepLearningConfig = coder.DeepLearningConfig(‘mkldnn’);
args = {zeros(1024,1024,3,’single’)};
codegen -config cfg -args args myNet_predict -report
% myNet_predict.m
function out = myNet_predict(img)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork(‘DeepLabV3plus.mat’);
end
pred = predict(mynet, img);
end
Unfortunately the *.mat files of the neural network and PadLayer1183 are to big for uploading here, I uploaded them under https://cloudstore.zih.tu-dresden.de/index.php/s/ajSCte9G9HN2pqP for save downloading. These are all files which are neccessary to reproduce the discribed behaviour.
I tried to debug the code so far, but I do not got an idea why this error occours. As I followed the compilation process, the error appears only when the prediction is called.
The input is every time an image with the dimension 1024x1024x3. I know its very big, but thats a requirement of the neural network. I guess that the problem is the attribute ONNXParams from the type ONNXParameters. Because it would be a very huge workaround to replace this variable with single parameters, I do not think that MATLAB would handle code generations in this way.
Hopefully anyone can help me to figure out whats wrong in the model code or my code.
Thanks in advance.
Best regardsDear cummunity,
I try to generate C/C++ code from an DAGNetwork, which is generated imported from an ONNX model. When I try to run this model in MATLAB itself, no errrors occour. The model is saved as *.mat file. Loading and running the model again is working well.
If I want to generate C/C++ code from the model via the following code (in two separate files gencode.m and myNet_predict.m), I get the error message: ??? Layer hyper-parameters for custom layer ‘PadLayer1183’ must be numeric scalar, scalar logical, character or string array, or a matrix of type double or single.
% codegen.m
cfg = coder.config(‘mex’);
cfg.TargetLang = ‘C++’;
cfg.DeepLearningConfig = coder.DeepLearningConfig(‘mkldnn’);
args = {zeros(1024,1024,3,’single’)};
codegen -config cfg -args args myNet_predict -report
% myNet_predict.m
function out = myNet_predict(img)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork(‘DeepLabV3plus.mat’);
end
pred = predict(mynet, img);
end
Unfortunately the *.mat files of the neural network and PadLayer1183 are to big for uploading here, I uploaded them under https://cloudstore.zih.tu-dresden.de/index.php/s/ajSCte9G9HN2pqP for save downloading. These are all files which are neccessary to reproduce the discribed behaviour.
I tried to debug the code so far, but I do not got an idea why this error occours. As I followed the compilation process, the error appears only when the prediction is called.
The input is every time an image with the dimension 1024x1024x3. I know its very big, but thats a requirement of the neural network. I guess that the problem is the attribute ONNXParams from the type ONNXParameters. Because it would be a very huge workaround to replace this variable with single parameters, I do not think that MATLAB would handle code generations in this way.
Hopefully anyone can help me to figure out whats wrong in the model code or my code.
Thanks in advance.
Best regards Dear cummunity,
I try to generate C/C++ code from an DAGNetwork, which is generated imported from an ONNX model. When I try to run this model in MATLAB itself, no errrors occour. The model is saved as *.mat file. Loading and running the model again is working well.
If I want to generate C/C++ code from the model via the following code (in two separate files gencode.m and myNet_predict.m), I get the error message: ??? Layer hyper-parameters for custom layer ‘PadLayer1183’ must be numeric scalar, scalar logical, character or string array, or a matrix of type double or single.
% codegen.m
cfg = coder.config(‘mex’);
cfg.TargetLang = ‘C++’;
cfg.DeepLearningConfig = coder.DeepLearningConfig(‘mkldnn’);
args = {zeros(1024,1024,3,’single’)};
codegen -config cfg -args args myNet_predict -report
% myNet_predict.m
function out = myNet_predict(img)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork(‘DeepLabV3plus.mat’);
end
pred = predict(mynet, img);
end
Unfortunately the *.mat files of the neural network and PadLayer1183 are to big for uploading here, I uploaded them under https://cloudstore.zih.tu-dresden.de/index.php/s/ajSCte9G9HN2pqP for save downloading. These are all files which are neccessary to reproduce the discribed behaviour.
I tried to debug the code so far, but I do not got an idea why this error occours. As I followed the compilation process, the error appears only when the prediction is called.
The input is every time an image with the dimension 1024x1024x3. I know its very big, but thats a requirement of the neural network. I guess that the problem is the attribute ONNXParams from the type ONNXParameters. Because it would be a very huge workaround to replace this variable with single parameters, I do not think that MATLAB would handle code generations in this way.
Hopefully anyone can help me to figure out whats wrong in the model code or my code.
Thanks in advance.
Best regards deep learning, matlab coder, c++, neural network, onnx, mex MATLAB Answers — New Questions