Category: Matlab
Category Archives: Matlab
Error while calling a Keras Model from Matlab
Basically, I have regression neural network saved in .H5 format. I want to use the NN model’s prediction in my simulink model. I am trying to call the python where the NN model is imported using Keras.load_model. When I call the python with NN model imported I am getting an error but if I call it without the NN model its working fine.
Matlab function to call python:
function y = fcn(in1,in2)
y = 0; % Has to be preassigned, otherwise Simulink throws an error
coder.extrinsic(‘py.final10.test’) % Python functions have to be run extrinsically, meaning no C code generated
y = double(py.final10.test(in1,in2));
end
Python :final10.py
from tensorflow import keras
from keras.models import load_model
import numpy as np
model = load_model(‘model.h5’)
def test(in1,in2):
x1 = in1
x2 = in2
a = np.asarray(x1)
b = np.asarray(x2)
G = np.asarray([a,b])
x3 = G.reshape(1,2)
x4 = model.predict(x3)
print(x4)
y = x1+x2;
return y
If I didn’t include the load_model line, I am able to call the python from Matlab. Can anyone help me to solve this issue.
Below is the error, I am getting:
Undefined function ‘py.finalv10.test’ for input arguments of type ‘double’. Error in ‘active_vehicleV1/Vehicle/MATLAB Function’ (line 4) y = double(py.finalv10.test(in1,in2));Basically, I have regression neural network saved in .H5 format. I want to use the NN model’s prediction in my simulink model. I am trying to call the python where the NN model is imported using Keras.load_model. When I call the python with NN model imported I am getting an error but if I call it without the NN model its working fine.
Matlab function to call python:
function y = fcn(in1,in2)
y = 0; % Has to be preassigned, otherwise Simulink throws an error
coder.extrinsic(‘py.final10.test’) % Python functions have to be run extrinsically, meaning no C code generated
y = double(py.final10.test(in1,in2));
end
Python :final10.py
from tensorflow import keras
from keras.models import load_model
import numpy as np
model = load_model(‘model.h5’)
def test(in1,in2):
x1 = in1
x2 = in2
a = np.asarray(x1)
b = np.asarray(x2)
G = np.asarray([a,b])
x3 = G.reshape(1,2)
x4 = model.predict(x3)
print(x4)
y = x1+x2;
return y
If I didn’t include the load_model line, I am able to call the python from Matlab. Can anyone help me to solve this issue.
Below is the error, I am getting:
Undefined function ‘py.finalv10.test’ for input arguments of type ‘double’. Error in ‘active_vehicleV1/Vehicle/MATLAB Function’ (line 4) y = double(py.finalv10.test(in1,in2)); Basically, I have regression neural network saved in .H5 format. I want to use the NN model’s prediction in my simulink model. I am trying to call the python where the NN model is imported using Keras.load_model. When I call the python with NN model imported I am getting an error but if I call it without the NN model its working fine.
Matlab function to call python:
function y = fcn(in1,in2)
y = 0; % Has to be preassigned, otherwise Simulink throws an error
coder.extrinsic(‘py.final10.test’) % Python functions have to be run extrinsically, meaning no C code generated
y = double(py.final10.test(in1,in2));
end
Python :final10.py
from tensorflow import keras
from keras.models import load_model
import numpy as np
model = load_model(‘model.h5’)
def test(in1,in2):
x1 = in1
x2 = in2
a = np.asarray(x1)
b = np.asarray(x2)
G = np.asarray([a,b])
x3 = G.reshape(1,2)
x4 = model.predict(x3)
print(x4)
y = x1+x2;
return y
If I didn’t include the load_model line, I am able to call the python from Matlab. Can anyone help me to solve this issue.
Below is the error, I am getting:
Undefined function ‘py.finalv10.test’ for input arguments of type ‘double’. Error in ‘active_vehicleV1/Vehicle/MATLAB Function’ (line 4) y = double(py.finalv10.test(in1,in2)); python MATLAB Answers — New Questions
Convert Simulink to m file
A lot (or most or all?) of the configuration of a simulink file can be done programmatically. Is there a way to convert an existing simulink slx file into an m file that contains all (important) steps necessary to build the slx file? I do not care so much about the visual documentation that the simulink file inherently comes with (routing of signals, position of blocks). So, an m file containing all commands to build an slx file is enough for me. The advantage would be that one can more easily track the text-based m file in programs like git (I am aware that there are ways to track simulink files as well but I prefer text-based files).A lot (or most or all?) of the configuration of a simulink file can be done programmatically. Is there a way to convert an existing simulink slx file into an m file that contains all (important) steps necessary to build the slx file? I do not care so much about the visual documentation that the simulink file inherently comes with (routing of signals, position of blocks). So, an m file containing all commands to build an slx file is enough for me. The advantage would be that one can more easily track the text-based m file in programs like git (I am aware that there are ways to track simulink files as well but I prefer text-based files). A lot (or most or all?) of the configuration of a simulink file can be done programmatically. Is there a way to convert an existing simulink slx file into an m file that contains all (important) steps necessary to build the slx file? I do not care so much about the visual documentation that the simulink file inherently comes with (routing of signals, position of blocks). So, an m file containing all commands to build an slx file is enough for me. The advantage would be that one can more easily track the text-based m file in programs like git (I am aware that there are ways to track simulink files as well but I prefer text-based files). simulink, convert, text file MATLAB Answers — New Questions
Acquire data from a python device in continuous (synchronuous) mode on a PC with Matlab installed.
Hi.
I’ve a raspberry device on wich I’ve installed Python.
My raspberry reads in realtime data from an MLX 90640 IR Thermal Camera and write it on a txt file.
If I copy this txt file on a PC with Matlab installed, I can read thermal data and process it in Matlab to produce, i.e., an heatmap.
This process, however, is an asynchronous process since I must :
acquire thermal data on raspberry
stop the acquisition
copy the data on the PC with Matlab installed
run the matlab application to view the heatmap
Obviuosly I’d like to trasforf this process from asynchronous to synchronous so that I can view real time data acquired from raspberry-Python device on Matlab in the same time that they are acquired and in contunuous mode.
The question is: is there any way to do this? And if yes, how?
Any idea?
Thanks in advanceHi.
I’ve a raspberry device on wich I’ve installed Python.
My raspberry reads in realtime data from an MLX 90640 IR Thermal Camera and write it on a txt file.
If I copy this txt file on a PC with Matlab installed, I can read thermal data and process it in Matlab to produce, i.e., an heatmap.
This process, however, is an asynchronous process since I must :
acquire thermal data on raspberry
stop the acquisition
copy the data on the PC with Matlab installed
run the matlab application to view the heatmap
Obviuosly I’d like to trasforf this process from asynchronous to synchronous so that I can view real time data acquired from raspberry-Python device on Matlab in the same time that they are acquired and in contunuous mode.
The question is: is there any way to do this? And if yes, how?
Any idea?
Thanks in advance Hi.
I’ve a raspberry device on wich I’ve installed Python.
My raspberry reads in realtime data from an MLX 90640 IR Thermal Camera and write it on a txt file.
If I copy this txt file on a PC with Matlab installed, I can read thermal data and process it in Matlab to produce, i.e., an heatmap.
This process, however, is an asynchronous process since I must :
acquire thermal data on raspberry
stop the acquisition
copy the data on the PC with Matlab installed
run the matlab application to view the heatmap
Obviuosly I’d like to trasforf this process from asynchronous to synchronous so that I can view real time data acquired from raspberry-Python device on Matlab in the same time that they are acquired and in contunuous mode.
The question is: is there any way to do this? And if yes, how?
Any idea?
Thanks in advance raspberry, phython MATLAB Answers — New Questions
What is algorithm of Support vector parameter optimization
How to find the parameter such cost function, epsilon and gamma in epsilon-SVRHow to find the parameter such cost function, epsilon and gamma in epsilon-SVR How to find the parameter such cost function, epsilon and gamma in epsilon-SVR svr, matalb, machine learning MATLAB Answers — New Questions
Why does this code give error?
clear;clc
%%
fc = 3e8;% Carrier frequency
Nb = 1000;% Number of snapshots
c = 3e8;
wavelength = c/fc;% The wavelength of the received signal
d = 0.5*wavelength;
theta = [5 40];
M = length(theta);% Number of signals
N = 10;% Number of antennas
% Wavenumber
beta = 2*pi/wavelength;
% Signal amplitude
A = 1;
% SNR (dB)
snr = 5;
% Variance of noise
sigma=sqrt((A^2)/(2*10^(snr/10)));
% Source signal
D = randi(M,Nb,1);
S =A*(2*D – 1);
% The electrical phase shift from element to element along the array
phi=beta*d*cos(theta*pi/180);
% Matrix of steering vectors
for i=1:M
for k=1:N;
VecteurDirectionnel(k,i)= exp(j*(k-1)*phi(i));
end
end
% White Gaussien noise
B = (sigma^2)*(randn(N,Nb)+j*randn(N,Nb))/sqrt(2);
% Array output:signal plus noise
X = VecteurDirectionnel*S+B;
% Estimation of the spatial correlation matrix of the observed signal
Rxx = X*X’/Nb;
% Eigen decomposition
[Vi,Li] = eig(Rxx);
[L,I] = sort(diag(Li),’descend’);
V = Vi(:,I);
Vs = V(:,1:M);
Vs1=Vs(1:N-1,:);
Vs2=Vs(2:N,:);
% Direction Of Arrival
% Least square
xsi=linsolve(Vs(1:N-1,:),Vs(2:N,:));
% DOA estimation
doa=acosd((angle(eig(xsi))/(2*pi*d)))clear;clc
%%
fc = 3e8;% Carrier frequency
Nb = 1000;% Number of snapshots
c = 3e8;
wavelength = c/fc;% The wavelength of the received signal
d = 0.5*wavelength;
theta = [5 40];
M = length(theta);% Number of signals
N = 10;% Number of antennas
% Wavenumber
beta = 2*pi/wavelength;
% Signal amplitude
A = 1;
% SNR (dB)
snr = 5;
% Variance of noise
sigma=sqrt((A^2)/(2*10^(snr/10)));
% Source signal
D = randi(M,Nb,1);
S =A*(2*D – 1);
% The electrical phase shift from element to element along the array
phi=beta*d*cos(theta*pi/180);
% Matrix of steering vectors
for i=1:M
for k=1:N;
VecteurDirectionnel(k,i)= exp(j*(k-1)*phi(i));
end
end
% White Gaussien noise
B = (sigma^2)*(randn(N,Nb)+j*randn(N,Nb))/sqrt(2);
% Array output:signal plus noise
X = VecteurDirectionnel*S+B;
% Estimation of the spatial correlation matrix of the observed signal
Rxx = X*X’/Nb;
% Eigen decomposition
[Vi,Li] = eig(Rxx);
[L,I] = sort(diag(Li),’descend’);
V = Vi(:,I);
Vs = V(:,1:M);
Vs1=Vs(1:N-1,:);
Vs2=Vs(2:N,:);
% Direction Of Arrival
% Least square
xsi=linsolve(Vs(1:N-1,:),Vs(2:N,:));
% DOA estimation
doa=acosd((angle(eig(xsi))/(2*pi*d))) clear;clc
%%
fc = 3e8;% Carrier frequency
Nb = 1000;% Number of snapshots
c = 3e8;
wavelength = c/fc;% The wavelength of the received signal
d = 0.5*wavelength;
theta = [5 40];
M = length(theta);% Number of signals
N = 10;% Number of antennas
% Wavenumber
beta = 2*pi/wavelength;
% Signal amplitude
A = 1;
% SNR (dB)
snr = 5;
% Variance of noise
sigma=sqrt((A^2)/(2*10^(snr/10)));
% Source signal
D = randi(M,Nb,1);
S =A*(2*D – 1);
% The electrical phase shift from element to element along the array
phi=beta*d*cos(theta*pi/180);
% Matrix of steering vectors
for i=1:M
for k=1:N;
VecteurDirectionnel(k,i)= exp(j*(k-1)*phi(i));
end
end
% White Gaussien noise
B = (sigma^2)*(randn(N,Nb)+j*randn(N,Nb))/sqrt(2);
% Array output:signal plus noise
X = VecteurDirectionnel*S+B;
% Estimation of the spatial correlation matrix of the observed signal
Rxx = X*X’/Nb;
% Eigen decomposition
[Vi,Li] = eig(Rxx);
[L,I] = sort(diag(Li),’descend’);
V = Vi(:,I);
Vs = V(:,1:M);
Vs1=Vs(1:N-1,:);
Vs2=Vs(2:N,:);
% Direction Of Arrival
% Least square
xsi=linsolve(Vs(1:N-1,:),Vs(2:N,:));
% DOA estimation
doa=acosd((angle(eig(xsi))/(2*pi*d))) why error MATLAB Answers — New Questions
How to determe the Fatigue Damage according Miner’s Rule via rainflow counting
Dear Matlab Users,
I have difficulties calculating the total accumulated fatique damage for a set of data (see Attachements). I have determined the histogram based on Rainflow counting, and determined the line for the SN-curve (maximum allowable stress per cycle). The SN-curve has only one slope in this case.
To calculate the total accumulated fatique damage according Miner’s Rule, the number of cycles of the SN curve should be divided by the number of cycles of the histogram per stress range, and then be summed up.
My question is: How do I divide the values from the number of cycles of the SN-curve by the the values from the number of cycles of the histogram? How do I make the values of the same size? I want to divide the following (see script for clarification):
N=10.^(L_a1-m1*log(cigma_delta*(T/T_ref)^k)); with cigma_delta= [0:0.05:710]; % N-cycles SN-curve
by
C_7=histogram(‘BinEdges’,edges’,’BinCounts’,sum(hist,2), Orientation=’horizontal’) % Rainflow counting histogram
Thanks in advance!Dear Matlab Users,
I have difficulties calculating the total accumulated fatique damage for a set of data (see Attachements). I have determined the histogram based on Rainflow counting, and determined the line for the SN-curve (maximum allowable stress per cycle). The SN-curve has only one slope in this case.
To calculate the total accumulated fatique damage according Miner’s Rule, the number of cycles of the SN curve should be divided by the number of cycles of the histogram per stress range, and then be summed up.
My question is: How do I divide the values from the number of cycles of the SN-curve by the the values from the number of cycles of the histogram? How do I make the values of the same size? I want to divide the following (see script for clarification):
N=10.^(L_a1-m1*log(cigma_delta*(T/T_ref)^k)); with cigma_delta= [0:0.05:710]; % N-cycles SN-curve
by
C_7=histogram(‘BinEdges’,edges’,’BinCounts’,sum(hist,2), Orientation=’horizontal’) % Rainflow counting histogram
Thanks in advance! Dear Matlab Users,
I have difficulties calculating the total accumulated fatique damage for a set of data (see Attachements). I have determined the histogram based on Rainflow counting, and determined the line for the SN-curve (maximum allowable stress per cycle). The SN-curve has only one slope in this case.
To calculate the total accumulated fatique damage according Miner’s Rule, the number of cycles of the SN curve should be divided by the number of cycles of the histogram per stress range, and then be summed up.
My question is: How do I divide the values from the number of cycles of the SN-curve by the the values from the number of cycles of the histogram? How do I make the values of the same size? I want to divide the following (see script for clarification):
N=10.^(L_a1-m1*log(cigma_delta*(T/T_ref)^k)); with cigma_delta= [0:0.05:710]; % N-cycles SN-curve
by
C_7=histogram(‘BinEdges’,edges’,’BinCounts’,sum(hist,2), Orientation=’horizontal’) % Rainflow counting histogram
Thanks in advance! rainflow counting, miner’s rule, histogram, sn-curve, fatigue MATLAB Answers — New Questions
Parallel Processing is better than buying another MATLAB licence?
Hello,
I’m considering whether it’s more beneficial to purchase 2 or more MATLAB licenses or to invest in the Parallel Processing Toolbox. How many GPUs can we utilize with the Parallel Processing Toolbox, and is it worth the investment? I would greatly appreciate insights from someone with experience in this matter. Thank you!Hello,
I’m considering whether it’s more beneficial to purchase 2 or more MATLAB licenses or to invest in the Parallel Processing Toolbox. How many GPUs can we utilize with the Parallel Processing Toolbox, and is it worth the investment? I would greatly appreciate insights from someone with experience in this matter. Thank you! Hello,
I’m considering whether it’s more beneficial to purchase 2 or more MATLAB licenses or to invest in the Parallel Processing Toolbox. How many GPUs can we utilize with the Parallel Processing Toolbox, and is it worth the investment? I would greatly appreciate insights from someone with experience in this matter. Thank you! parallel computing toolbox, matlab MATLAB Answers — New Questions
importing CAD geometry over .STEP or .IGS Files
Hello dear Matlab Answer Members,
im looking for a way to import .STEP or/and .IGS Files into Matlab and be able to plot them at the end. I have already tried my luck with ‘IGES Toolbox’ but I am only getting error messages from that one. Do you guys know any better way to archive my goal or is the Toolbox I have already been using the one I want to get to work?
Thank you for your help in advance 🙂
FredericHello dear Matlab Answer Members,
im looking for a way to import .STEP or/and .IGS Files into Matlab and be able to plot them at the end. I have already tried my luck with ‘IGES Toolbox’ but I am only getting error messages from that one. Do you guys know any better way to archive my goal or is the Toolbox I have already been using the one I want to get to work?
Thank you for your help in advance 🙂
Frederic Hello dear Matlab Answer Members,
im looking for a way to import .STEP or/and .IGS Files into Matlab and be able to plot them at the end. I have already tried my luck with ‘IGES Toolbox’ but I am only getting error messages from that one. Do you guys know any better way to archive my goal or is the Toolbox I have already been using the one I want to get to work?
Thank you for your help in advance 🙂
Frederic step, iges, plot, iges toolbox, igs, cad, geometry MATLAB Answers — New Questions
Do we have option in Polyspace to generate report for Code Prover/ BugFinder in Excel or Spreadsheet format ?
I wanted to generate report for BugFinder and Code Prover in Excel format since the result generated from the analysis are too huge which causing Word format to hang or not responding most of the time.I wanted to generate report for BugFinder and Code Prover in Excel format since the result generated from the analysis are too huge which causing Word format to hang or not responding most of the time. I wanted to generate report for BugFinder and Code Prover in Excel format since the result generated from the analysis are too huge which causing Word format to hang or not responding most of the time. polyspace, bugfinder, codeprover, report MATLAB Answers — New Questions
Integro-differential equation solutions
I wanted to solve it for C, any suggestions to proceed with coding?I wanted to solve it for C, any suggestions to proceed with coding? I wanted to solve it for C, any suggestions to proceed with coding? how this type of equation can be solved in matlab? MATLAB Answers — New Questions
Curve Fitting for a Rational Polynomial Model.
Dear all,
I want to find the best rational Polynomial model that can fit the data shown.
any help would be appreciated.
Data are in dB.Dear all,
I want to find the best rational Polynomial model that can fit the data shown.
any help would be appreciated.
Data are in dB. Dear all,
I want to find the best rational Polynomial model that can fit the data shown.
any help would be appreciated.
Data are in dB. curve fitting MATLAB Answers — New Questions