Tag Archives: matlab
Adding a .mex file to App Designer app
I’d like to use Shuffle to shuffle the rows of a UITable.
https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle
Hopefully it will keep the columns in a row together and can shuffle Var3 along with the numbers since it is a category (‘L’ or ‘R’)
I’ll have to experiment unless someone knows how to call it:
will Y = Shuffle(X, Dim) only shuffle the Dim’ed column leaving the rest alone?
Uh oh separate question: will repose as another ask
If I have to use X(RANDPERM(LENGTH(X)) as the doc shows will that do it?
How?I’d like to use Shuffle to shuffle the rows of a UITable.
https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle
Hopefully it will keep the columns in a row together and can shuffle Var3 along with the numbers since it is a category (‘L’ or ‘R’)
I’ll have to experiment unless someone knows how to call it:
will Y = Shuffle(X, Dim) only shuffle the Dim’ed column leaving the rest alone?
Uh oh separate question: will repose as another ask
If I have to use X(RANDPERM(LENGTH(X)) as the doc shows will that do it?
How? I’d like to use Shuffle to shuffle the rows of a UITable.
https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle
Hopefully it will keep the columns in a row together and can shuffle Var3 along with the numbers since it is a category (‘L’ or ‘R’)
I’ll have to experiment unless someone knows how to call it:
will Y = Shuffle(X, Dim) only shuffle the Dim’ed column leaving the rest alone?
Uh oh separate question: will repose as another ask
If I have to use X(RANDPERM(LENGTH(X)) as the doc shows will that do it?
How? .mex file, app designer MATLAB Answers — New Questions
kindly help in debugging the following code for optimization
function [ f, g ] = problem_function( x )
D1=x(1);D2=x(2);D3=x(3);D4=x(4);D5=x(5);P1=x(6);P2=x(7);P3=x(8);P4=x(9);P5=x(10);V1=x(11);V2=x(12);V3=x(13);V4=x(14);V5=x(15);
L1=2;L2=3;L3=4;L4=5;L5=6;
L=[L1 L2 L3 L4 L5];
D=[D1 D2 D3 D4 D5];
%%%%%%%%%%%%%%%%%%%%%%%%%
Q1=V1*(3.14/4)*D1^2;
Q2=V2*(3.14/4)*D2^2;
Q3=V3*(3.14/4)*D3^2;
Q4=V4*(3.14/4)*D4^2;
Q5=V5*(3.14/4)*D5^2;
% Objective functions F(X)
CT=2.05*L*D’.^3;
%%%%%%%%%%%%%%%%%%%%%%%
if all(P(1:5)>=18)
CPP=0;
else
CPP=(CT/5)*sum(18-P(1:5));
end
%%%%%%%%%%%%%%%%%%%%
if all(V(1:5)<=10)
CPV=0;
else
CPV=(CT/5)*sum(V(1:5).^2-100);
end
%%%%%%
f=CT+CPV+CPP;
% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)
g(1)=P1-P2-11.7*(L1*Q1^3/D1^5);
g(2)=P2-P3-11.7*(L2*Q2^3/D2^5);
g(3)=P3-P4-11.7*(L3*Q3^3/D3^5);
g(4)=P2-P4-11.7*(L4*Q4^3/D4^5);
g(5)=P4-P5-11.7*(L5*Q5^3/D5^5);
g(6)= 40-Q1;
g(7)=Q1-Q2-Q4;
g(8)=Q2-14-Q3;
g(9)=Q3+Q4-Q5;
end
%%%% the result say Undefined function or variable ‘P’.
Error in example>problem_function (line 82)
if all(P(1:5)>=18)
any helps plz.function [ f, g ] = problem_function( x )
D1=x(1);D2=x(2);D3=x(3);D4=x(4);D5=x(5);P1=x(6);P2=x(7);P3=x(8);P4=x(9);P5=x(10);V1=x(11);V2=x(12);V3=x(13);V4=x(14);V5=x(15);
L1=2;L2=3;L3=4;L4=5;L5=6;
L=[L1 L2 L3 L4 L5];
D=[D1 D2 D3 D4 D5];
%%%%%%%%%%%%%%%%%%%%%%%%%
Q1=V1*(3.14/4)*D1^2;
Q2=V2*(3.14/4)*D2^2;
Q3=V3*(3.14/4)*D3^2;
Q4=V4*(3.14/4)*D4^2;
Q5=V5*(3.14/4)*D5^2;
% Objective functions F(X)
CT=2.05*L*D’.^3;
%%%%%%%%%%%%%%%%%%%%%%%
if all(P(1:5)>=18)
CPP=0;
else
CPP=(CT/5)*sum(18-P(1:5));
end
%%%%%%%%%%%%%%%%%%%%
if all(V(1:5)<=10)
CPV=0;
else
CPV=(CT/5)*sum(V(1:5).^2-100);
end
%%%%%%
f=CT+CPV+CPP;
% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)
g(1)=P1-P2-11.7*(L1*Q1^3/D1^5);
g(2)=P2-P3-11.7*(L2*Q2^3/D2^5);
g(3)=P3-P4-11.7*(L3*Q3^3/D3^5);
g(4)=P2-P4-11.7*(L4*Q4^3/D4^5);
g(5)=P4-P5-11.7*(L5*Q5^3/D5^5);
g(6)= 40-Q1;
g(7)=Q1-Q2-Q4;
g(8)=Q2-14-Q3;
g(9)=Q3+Q4-Q5;
end
%%%% the result say Undefined function or variable ‘P’.
Error in example>problem_function (line 82)
if all(P(1:5)>=18)
any helps plz. function [ f, g ] = problem_function( x )
D1=x(1);D2=x(2);D3=x(3);D4=x(4);D5=x(5);P1=x(6);P2=x(7);P3=x(8);P4=x(9);P5=x(10);V1=x(11);V2=x(12);V3=x(13);V4=x(14);V5=x(15);
L1=2;L2=3;L3=4;L4=5;L5=6;
L=[L1 L2 L3 L4 L5];
D=[D1 D2 D3 D4 D5];
%%%%%%%%%%%%%%%%%%%%%%%%%
Q1=V1*(3.14/4)*D1^2;
Q2=V2*(3.14/4)*D2^2;
Q3=V3*(3.14/4)*D3^2;
Q4=V4*(3.14/4)*D4^2;
Q5=V5*(3.14/4)*D5^2;
% Objective functions F(X)
CT=2.05*L*D’.^3;
%%%%%%%%%%%%%%%%%%%%%%%
if all(P(1:5)>=18)
CPP=0;
else
CPP=(CT/5)*sum(18-P(1:5));
end
%%%%%%%%%%%%%%%%%%%%
if all(V(1:5)<=10)
CPV=0;
else
CPV=(CT/5)*sum(V(1:5).^2-100);
end
%%%%%%
f=CT+CPV+CPP;
% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)
g(1)=P1-P2-11.7*(L1*Q1^3/D1^5);
g(2)=P2-P3-11.7*(L2*Q2^3/D2^5);
g(3)=P3-P4-11.7*(L3*Q3^3/D3^5);
g(4)=P2-P4-11.7*(L4*Q4^3/D4^5);
g(5)=P4-P5-11.7*(L5*Q5^3/D5^5);
g(6)= 40-Q1;
g(7)=Q1-Q2-Q4;
g(8)=Q2-14-Q3;
g(9)=Q3+Q4-Q5;
end
%%%% the result say Undefined function or variable ‘P’.
Error in example>problem_function (line 82)
if all(P(1:5)>=18)
any helps plz. optimization MATLAB Answers — New Questions
imagesc color map for gridded value
Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,……
length(X)=length(Y)=length(Z).Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,……
length(X)=length(Y)=length(Z). Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,……
length(X)=length(Y)=length(Z). imagesc, colorplot, gridded data plot, matlab MATLAB Answers — New Questions
I am facing an issue in FONT style in the MATLAB 2024a editor window.
While I am keeping the Font style ‘Monospace’, I am getting the different Font styles in the command window and editor window. This is happening especially with the Font name called ‘Monospace’. Can anyone help me in this regard?While I am keeping the Font style ‘Monospace’, I am getting the different Font styles in the command window and editor window. This is happening especially with the Font name called ‘Monospace’. Can anyone help me in this regard? While I am keeping the Font style ‘Monospace’, I am getting the different Font styles in the command window and editor window. This is happening especially with the Font name called ‘Monospace’. Can anyone help me in this regard? font MATLAB Answers — New Questions
Is there a way to log variables from a Matlab Function Block (in Simulink), that is not output?
I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)?I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)? I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)? simulink, save, data MATLAB Answers — New Questions
simulation wind profile in simulink
I want to simulate Cp related to wind turbine in Simulink MATLAB, I have the Excel file related to wind speed, I would be grateful if you have the link related to the simulation or if you have a source, please let me knowI want to simulate Cp related to wind turbine in Simulink MATLAB, I have the Excel file related to wind speed, I would be grateful if you have the link related to the simulation or if you have a source, please let me know I want to simulate Cp related to wind turbine in Simulink MATLAB, I have the Excel file related to wind speed, I would be grateful if you have the link related to the simulation or if you have a source, please let me know wind speed profile? MATLAB Answers — New Questions
Can’t find battery on simulink
I am trying to use a battery with measurement outport but I cant find it. I dont know if MATLAB removed it newer versions. This is what I am referring to:I am trying to use a battery with measurement outport but I cant find it. I dont know if MATLAB removed it newer versions. This is what I am referring to: I am trying to use a battery with measurement outport but I cant find it. I dont know if MATLAB removed it newer versions. This is what I am referring to: battery_system_management, simulink MATLAB Answers — New Questions
How can I use the data of a set of matrices labelled in order
Hi, I managed to open all files in a folder which leaves me with the matrices data_1, data_2, data_3 …..data_n.
Now I want to add one of the row from each of the n matrices into one single set of data but I don’t know how i can address the matrix in a for loop.
for i=1:1:n
ag((((i-1)*n)+1):i*ni)=data’i’;
endHi, I managed to open all files in a folder which leaves me with the matrices data_1, data_2, data_3 …..data_n.
Now I want to add one of the row from each of the n matrices into one single set of data but I don’t know how i can address the matrix in a for loop.
for i=1:1:n
ag((((i-1)*n)+1):i*ni)=data’i’;
end Hi, I managed to open all files in a folder which leaves me with the matrices data_1, data_2, data_3 …..data_n.
Now I want to add one of the row from each of the n matrices into one single set of data but I don’t know how i can address the matrix in a for loop.
for i=1:1:n
ag((((i-1)*n)+1):i*ni)=data’i’;
end data set, variables MATLAB Answers — New Questions
Comparing difference in values between values in an array – Using For Loop
Hello,
I have a question about comparing values between elements of an array. I keep getting the error that says
Index exceeds the number of array elements. Index must not exceed 1.
I attached my code but I also put the section of the code I’m having an issue with.
See MATLAB code attached:
E_Plane.m
theta = 0:0.01:pi/2
% The size of theta is 1 x 315
% E_Plane_norm_dB is an array that is also 1 x 315 with numbers
%{
Essentially, I am trying to see which number in the E_Plane_norm_dB array is the closest to -3.
Whichever number is closest to -3, I would need to output the "theta" value
that corresponds to that number in E_Plane_norm_dB
The way I’m doing this is by finding the "distance" from that element to -3
I keep comparing the "distances" to -3 between each element, until I find
the "smallest distance". Whichever element in E_Plane_norm_dB has the
smallest "distance", I would like to output that "theta" value.
%}
% Solving for the theta angle.
for j = 1:length(theta)
loop_theta = theta(j);
distance(j) = E_Plane_norm_dB(j) – (-3);
if (distance(j) < distance(j+1:length(theta)))
theta_angle = loop_theta;
end
endHello,
I have a question about comparing values between elements of an array. I keep getting the error that says
Index exceeds the number of array elements. Index must not exceed 1.
I attached my code but I also put the section of the code I’m having an issue with.
See MATLAB code attached:
E_Plane.m
theta = 0:0.01:pi/2
% The size of theta is 1 x 315
% E_Plane_norm_dB is an array that is also 1 x 315 with numbers
%{
Essentially, I am trying to see which number in the E_Plane_norm_dB array is the closest to -3.
Whichever number is closest to -3, I would need to output the "theta" value
that corresponds to that number in E_Plane_norm_dB
The way I’m doing this is by finding the "distance" from that element to -3
I keep comparing the "distances" to -3 between each element, until I find
the "smallest distance". Whichever element in E_Plane_norm_dB has the
smallest "distance", I would like to output that "theta" value.
%}
% Solving for the theta angle.
for j = 1:length(theta)
loop_theta = theta(j);
distance(j) = E_Plane_norm_dB(j) – (-3);
if (distance(j) < distance(j+1:length(theta)))
theta_angle = loop_theta;
end
end Hello,
I have a question about comparing values between elements of an array. I keep getting the error that says
Index exceeds the number of array elements. Index must not exceed 1.
I attached my code but I also put the section of the code I’m having an issue with.
See MATLAB code attached:
E_Plane.m
theta = 0:0.01:pi/2
% The size of theta is 1 x 315
% E_Plane_norm_dB is an array that is also 1 x 315 with numbers
%{
Essentially, I am trying to see which number in the E_Plane_norm_dB array is the closest to -3.
Whichever number is closest to -3, I would need to output the "theta" value
that corresponds to that number in E_Plane_norm_dB
The way I’m doing this is by finding the "distance" from that element to -3
I keep comparing the "distances" to -3 between each element, until I find
the "smallest distance". Whichever element in E_Plane_norm_dB has the
smallest "distance", I would like to output that "theta" value.
%}
% Solving for the theta angle.
for j = 1:length(theta)
loop_theta = theta(j);
distance(j) = E_Plane_norm_dB(j) – (-3);
if (distance(j) < distance(j+1:length(theta)))
theta_angle = loop_theta;
end
end comparing values, arrays, for loops MATLAB Answers — New Questions
Trouble simulating an RC low and high pass filter with trapoziodal aproximation
Hi,
I have been working to recreate the example code found in Andrew Simper’s 2020 lecture at Cytomic but have run into a roadblock. I can’t seem to get a reasonable capacitor approximation and am not sure why. You can see the relevant code on page 45 of the PDF here (lecture). I’ve attached my code below as well.
If you have any suggestions, please let me know. Thank you for your time.
%% circuit variables
Is=1e-12; % Saturation current (in Amperes)
n = 2; % Ideality factor (typically between 1 and 2)
temp = 300; % Temperature in Kelvin
k = 1.380649e-23; % Boltzmann constant (J/K)
q = 1.602176634e-19; % Electron charge (C)
% Calculate thermal voltage
vt=(k*temp)/q; % Thermal voltage (in Volts)
R1=2.2e3;
R2=6.8e3;
C1=0.47e-6;
C2=0.01e-6;
%% simulation loop
fs=48e3; %sample rate
Fd=1000; %input frequnecy
T=(1/1000)*10;
time=0:1/fs:T; %create time vector
vs=2.*sawtooth(Fd*2*pi*time); %create sawtooth input
%figure,plot(time,vs), title(‘input wavefrom (voltage v time’)
gr1=1/R1;%deinfe gr1 as the reciprocal of r1 for easier eq formation
gr2=1/R2;
m=1/2; %define division integral aproximation
h=1/fs; %define hight of the traps
gc1=C1/(h*m);
gc2=C2/(h*m);
ic1eq=0;
ic2eq=0;
%initalize vectors
v1=zeros(1,length(vs));
v2=zeros(1,length(vs));
v3=zeros(1,length(vs));
va1=0;
va2=0;
va3=0;
for k=1:length(vs)
va1=vs(k);
v1(k)=va1;
va2=(gr1*va1+gc1*va3-ic1eq)/(gr1+gc1);
v2(k)=va2;
va3=(gc1*va2+ic1eq+ic2eq)/(gc2+gc1+gr2);
%va3=(gc1*ic2eq+gr1*(ic1eq+ic2eq+gc1*va1))/(gr1*(gc2+gr2)+gc1*(gc2+gr1+gr2));
v3(k)=va3;
ic1eq = ic1eq + (1/m)*(gc1*(va3-va2)-ic1eq);
ic2eq = ic2eq + (1/m)*(gc2*(va3)-ic2eq);
end
figure, plot(time,v3)
title(‘input wave form vs output’), xlabel(‘time’), ylabel(‘voltage’)
hold on
plot(time,v1), legend(‘v3′,’v1’)Hi,
I have been working to recreate the example code found in Andrew Simper’s 2020 lecture at Cytomic but have run into a roadblock. I can’t seem to get a reasonable capacitor approximation and am not sure why. You can see the relevant code on page 45 of the PDF here (lecture). I’ve attached my code below as well.
If you have any suggestions, please let me know. Thank you for your time.
%% circuit variables
Is=1e-12; % Saturation current (in Amperes)
n = 2; % Ideality factor (typically between 1 and 2)
temp = 300; % Temperature in Kelvin
k = 1.380649e-23; % Boltzmann constant (J/K)
q = 1.602176634e-19; % Electron charge (C)
% Calculate thermal voltage
vt=(k*temp)/q; % Thermal voltage (in Volts)
R1=2.2e3;
R2=6.8e3;
C1=0.47e-6;
C2=0.01e-6;
%% simulation loop
fs=48e3; %sample rate
Fd=1000; %input frequnecy
T=(1/1000)*10;
time=0:1/fs:T; %create time vector
vs=2.*sawtooth(Fd*2*pi*time); %create sawtooth input
%figure,plot(time,vs), title(‘input wavefrom (voltage v time’)
gr1=1/R1;%deinfe gr1 as the reciprocal of r1 for easier eq formation
gr2=1/R2;
m=1/2; %define division integral aproximation
h=1/fs; %define hight of the traps
gc1=C1/(h*m);
gc2=C2/(h*m);
ic1eq=0;
ic2eq=0;
%initalize vectors
v1=zeros(1,length(vs));
v2=zeros(1,length(vs));
v3=zeros(1,length(vs));
va1=0;
va2=0;
va3=0;
for k=1:length(vs)
va1=vs(k);
v1(k)=va1;
va2=(gr1*va1+gc1*va3-ic1eq)/(gr1+gc1);
v2(k)=va2;
va3=(gc1*va2+ic1eq+ic2eq)/(gc2+gc1+gr2);
%va3=(gc1*ic2eq+gr1*(ic1eq+ic2eq+gc1*va1))/(gr1*(gc2+gr2)+gc1*(gc2+gr1+gr2));
v3(k)=va3;
ic1eq = ic1eq + (1/m)*(gc1*(va3-va2)-ic1eq);
ic2eq = ic2eq + (1/m)*(gc2*(va3)-ic2eq);
end
figure, plot(time,v3)
title(‘input wave form vs output’), xlabel(‘time’), ylabel(‘voltage’)
hold on
plot(time,v1), legend(‘v3′,’v1’) Hi,
I have been working to recreate the example code found in Andrew Simper’s 2020 lecture at Cytomic but have run into a roadblock. I can’t seem to get a reasonable capacitor approximation and am not sure why. You can see the relevant code on page 45 of the PDF here (lecture). I’ve attached my code below as well.
If you have any suggestions, please let me know. Thank you for your time.
%% circuit variables
Is=1e-12; % Saturation current (in Amperes)
n = 2; % Ideality factor (typically between 1 and 2)
temp = 300; % Temperature in Kelvin
k = 1.380649e-23; % Boltzmann constant (J/K)
q = 1.602176634e-19; % Electron charge (C)
% Calculate thermal voltage
vt=(k*temp)/q; % Thermal voltage (in Volts)
R1=2.2e3;
R2=6.8e3;
C1=0.47e-6;
C2=0.01e-6;
%% simulation loop
fs=48e3; %sample rate
Fd=1000; %input frequnecy
T=(1/1000)*10;
time=0:1/fs:T; %create time vector
vs=2.*sawtooth(Fd*2*pi*time); %create sawtooth input
%figure,plot(time,vs), title(‘input wavefrom (voltage v time’)
gr1=1/R1;%deinfe gr1 as the reciprocal of r1 for easier eq formation
gr2=1/R2;
m=1/2; %define division integral aproximation
h=1/fs; %define hight of the traps
gc1=C1/(h*m);
gc2=C2/(h*m);
ic1eq=0;
ic2eq=0;
%initalize vectors
v1=zeros(1,length(vs));
v2=zeros(1,length(vs));
v3=zeros(1,length(vs));
va1=0;
va2=0;
va3=0;
for k=1:length(vs)
va1=vs(k);
v1(k)=va1;
va2=(gr1*va1+gc1*va3-ic1eq)/(gr1+gc1);
v2(k)=va2;
va3=(gc1*va2+ic1eq+ic2eq)/(gc2+gc1+gr2);
%va3=(gc1*ic2eq+gr1*(ic1eq+ic2eq+gc1*va1))/(gr1*(gc2+gr2)+gc1*(gc2+gr1+gr2));
v3(k)=va3;
ic1eq = ic1eq + (1/m)*(gc1*(va3-va2)-ic1eq);
ic2eq = ic2eq + (1/m)*(gc2*(va3)-ic2eq);
end
figure, plot(time,v3)
title(‘input wave form vs output’), xlabel(‘time’), ylabel(‘voltage’)
hold on
plot(time,v1), legend(‘v3′,’v1’) signal processing, filters MATLAB Answers — New Questions
How can we read CAN message through Kvaser’s CAN Device by Packet Input block in Simulink Desktop Real-Time?
I’m trying to read IMU output, 8byte, though a Kvaser Leaf Light HS V2. I’ve installed Kvaser’s drivers and i can read data by software supplied with the IMU.
Now, I’d like to read the output data in MATLAB. I’ve installed Simulink Desktop Real-Time and use the Packet Input block.
Although we can choose a Kvaser’s CAN Device in the Packet block’s parameter, "Install new board", do we need the Vehicle Network Toolbox?
I noticed that the similar problem is posted in the link bellow, but the posted date is 2015. Is this situation still the same today?
https://jp.mathworks.com/matlabcentral/answers/194604-is-the-kvaser-leaf-light-hs-supported-by-both-vehicle-network-toolbox-and-real-time-windows-targetI’m trying to read IMU output, 8byte, though a Kvaser Leaf Light HS V2. I’ve installed Kvaser’s drivers and i can read data by software supplied with the IMU.
Now, I’d like to read the output data in MATLAB. I’ve installed Simulink Desktop Real-Time and use the Packet Input block.
Although we can choose a Kvaser’s CAN Device in the Packet block’s parameter, "Install new board", do we need the Vehicle Network Toolbox?
I noticed that the similar problem is posted in the link bellow, but the posted date is 2015. Is this situation still the same today?
https://jp.mathworks.com/matlabcentral/answers/194604-is-the-kvaser-leaf-light-hs-supported-by-both-vehicle-network-toolbox-and-real-time-windows-target I’m trying to read IMU output, 8byte, though a Kvaser Leaf Light HS V2. I’ve installed Kvaser’s drivers and i can read data by software supplied with the IMU.
Now, I’d like to read the output data in MATLAB. I’ve installed Simulink Desktop Real-Time and use the Packet Input block.
Although we can choose a Kvaser’s CAN Device in the Packet block’s parameter, "Install new board", do we need the Vehicle Network Toolbox?
I noticed that the similar problem is posted in the link bellow, but the posted date is 2015. Is this situation still the same today?
https://jp.mathworks.com/matlabcentral/answers/194604-is-the-kvaser-leaf-light-hs-supported-by-both-vehicle-network-toolbox-and-real-time-windows-target simulink desktop real-time, can, kvaser leaf light hs v2 MATLAB Answers — New Questions
How do I plot the receivedFlag from Simulink?
https://kr.mathworks.com/help/driving/ug/truck-platooning-with-roadrunner-scenario.html
classdef HelperV2VReceiver < matlab.System
% HelperV2VReceiver Models a V2V receiver.
% The V2V Receiver receives the Basic Safety Message transmitted by the
% target vehicles based on SNR graphs. The SNR data is adjusted based
% on the range and loaded during simulation.
% NOTE: The name of this System Object and its functionality may
% change without notice in a future release,
% or the System Object itself may be removed.
% Copyright 2021-2023 The MathWorks, Inc.
properties(Nontunable)
% V2V Channel Info
SnrCurves = struct;
% Output Struct
OutputStruct = struct;
end
% Pre-computed constants
properties(Access = private)
% Holds the information of precomputed snr curves
DistanceToSnrInfo
SnrToTputInfo
% Holds the information of snr & distance limits
MaxVehDist;
SnrMin;
SnrMax;
% Maximum range
MaxRange = 1000;
% Output Bus
BSMOut
% Minimum Throughput Percentage
MinTput = 60;
end
methods(Access = protected)
function sts = getSampleTimeImpl(obj)
sts = createSampleTime(obj,’Type’,’Inherited’);
end
function setupImpl(obj)
% Distance to SNR Relation
obj.DistanceToSnrInfo = obj.SnrCurves.dist2snr;
% SNR to Throughput Relation
obj.SnrToTputInfo = obj.SnrCurves.snr2tput;
% Get the limits for Distance & SNR
obj.MaxVehDist = obj.DistanceToSnrInfo(end,1);
obj.SnrMin = obj.SnrToTputInfo(1,1);
obj.SnrMax = obj.SnrToTputInfo(end,1);
% Initialize Output Bus
obj.BSMOut = obj.OutputStruct;
end
function bsmOut = stepImpl(obj,bsm,egoPose,sceneOrigin)
numReceivedSignal = 0;
bsmOut = obj.BSMOut;
bsmOutIdx = 1;
for i = 1:bsm.NumOfBSM
if bsm.BSMCoreData(i).Id > 0
% Compute the Ego to Target Vehicle distance
vehPos = [0,0,0];
lla = [double(bsm.BSMCoreData(i).Lattitude)*10^-7,double(bsm.BSMCoreData(i).Longitude)*10^-7,double(bsm.BSMCoreData(i).Elevation)*0.1];
% Convert geographic coordinates to local Cartesian coordinates
[vehPos(1),vehPos(2),vehPos(3)] = latlon2local(lla(1),lla(2),lla(3),sceneOrigin);
v2vdist = norm(egoPose.Position – vehPos);
% Find the throughput percentage for the v2vdist using
% the precomputed snr curves.
if v2vdist<obj.MaxVehDist
v2vdist = max(1,round(v2vdist));
snrEstimate = min(max(obj.SnrMin,interp1(obj.DistanceToSnrInfo(:,1),obj.DistanceToSnrInfo(:,2),v2vdist)),obj.SnrMax);
tput = interp1(obj.SnrToTputInfo(:,1),obj.SnrToTputInfo(:,2),snrEstimate);
else
tput = 0;
end
% Receive the signal based on throughput
receivedFlag = randi([obj.MinTput 100]) <= tput;
if receivedFlag
numReceivedSignal = numReceivedSignal+1;
bsmOut.IsValidTime = true;
bsmOut.BSMCoreData(bsmOutIdx) = bsm.BSMCoreData(i);
bsmOutIdx = bsmOutIdx+1;
end
end
end
bsmOut.NumOfBSM = numReceivedSignal;
end
function bsmOut = getOutputSizeImpl(obj) %#ok<MANU>
% Return size for each output port
bsmOut = 1;
end
function bsmOut = getOutputDataTypeImpl(obj) %#ok<MANU>
% Return data type for each output port
bsmOut = ‘BusBSM’;
end
function bsmOut = isOutputComplexImpl(obj) %#ok<MANU>
% Return true for each output port with complex data
bsmOut = false;
end
function bsmOut = isOutputFixedSizeImpl(obj) %#ok<MANU>
% Return true for each output port with fixed size
bsmOut = true;
end
end
methods(Access = protected, Static)
function flag = showSimulateUsingImpl
% Return false if simulation mode hidden in System block dialog
flag = true;
end
end
end
I would like to obtain the receivedFlag value from the HelperV2VReceiver code in the Follower1 Simulink example and plot it in platooning.mlx. What should I do?https://kr.mathworks.com/help/driving/ug/truck-platooning-with-roadrunner-scenario.html
classdef HelperV2VReceiver < matlab.System
% HelperV2VReceiver Models a V2V receiver.
% The V2V Receiver receives the Basic Safety Message transmitted by the
% target vehicles based on SNR graphs. The SNR data is adjusted based
% on the range and loaded during simulation.
% NOTE: The name of this System Object and its functionality may
% change without notice in a future release,
% or the System Object itself may be removed.
% Copyright 2021-2023 The MathWorks, Inc.
properties(Nontunable)
% V2V Channel Info
SnrCurves = struct;
% Output Struct
OutputStruct = struct;
end
% Pre-computed constants
properties(Access = private)
% Holds the information of precomputed snr curves
DistanceToSnrInfo
SnrToTputInfo
% Holds the information of snr & distance limits
MaxVehDist;
SnrMin;
SnrMax;
% Maximum range
MaxRange = 1000;
% Output Bus
BSMOut
% Minimum Throughput Percentage
MinTput = 60;
end
methods(Access = protected)
function sts = getSampleTimeImpl(obj)
sts = createSampleTime(obj,’Type’,’Inherited’);
end
function setupImpl(obj)
% Distance to SNR Relation
obj.DistanceToSnrInfo = obj.SnrCurves.dist2snr;
% SNR to Throughput Relation
obj.SnrToTputInfo = obj.SnrCurves.snr2tput;
% Get the limits for Distance & SNR
obj.MaxVehDist = obj.DistanceToSnrInfo(end,1);
obj.SnrMin = obj.SnrToTputInfo(1,1);
obj.SnrMax = obj.SnrToTputInfo(end,1);
% Initialize Output Bus
obj.BSMOut = obj.OutputStruct;
end
function bsmOut = stepImpl(obj,bsm,egoPose,sceneOrigin)
numReceivedSignal = 0;
bsmOut = obj.BSMOut;
bsmOutIdx = 1;
for i = 1:bsm.NumOfBSM
if bsm.BSMCoreData(i).Id > 0
% Compute the Ego to Target Vehicle distance
vehPos = [0,0,0];
lla = [double(bsm.BSMCoreData(i).Lattitude)*10^-7,double(bsm.BSMCoreData(i).Longitude)*10^-7,double(bsm.BSMCoreData(i).Elevation)*0.1];
% Convert geographic coordinates to local Cartesian coordinates
[vehPos(1),vehPos(2),vehPos(3)] = latlon2local(lla(1),lla(2),lla(3),sceneOrigin);
v2vdist = norm(egoPose.Position – vehPos);
% Find the throughput percentage for the v2vdist using
% the precomputed snr curves.
if v2vdist<obj.MaxVehDist
v2vdist = max(1,round(v2vdist));
snrEstimate = min(max(obj.SnrMin,interp1(obj.DistanceToSnrInfo(:,1),obj.DistanceToSnrInfo(:,2),v2vdist)),obj.SnrMax);
tput = interp1(obj.SnrToTputInfo(:,1),obj.SnrToTputInfo(:,2),snrEstimate);
else
tput = 0;
end
% Receive the signal based on throughput
receivedFlag = randi([obj.MinTput 100]) <= tput;
if receivedFlag
numReceivedSignal = numReceivedSignal+1;
bsmOut.IsValidTime = true;
bsmOut.BSMCoreData(bsmOutIdx) = bsm.BSMCoreData(i);
bsmOutIdx = bsmOutIdx+1;
end
end
end
bsmOut.NumOfBSM = numReceivedSignal;
end
function bsmOut = getOutputSizeImpl(obj) %#ok<MANU>
% Return size for each output port
bsmOut = 1;
end
function bsmOut = getOutputDataTypeImpl(obj) %#ok<MANU>
% Return data type for each output port
bsmOut = ‘BusBSM’;
end
function bsmOut = isOutputComplexImpl(obj) %#ok<MANU>
% Return true for each output port with complex data
bsmOut = false;
end
function bsmOut = isOutputFixedSizeImpl(obj) %#ok<MANU>
% Return true for each output port with fixed size
bsmOut = true;
end
end
methods(Access = protected, Static)
function flag = showSimulateUsingImpl
% Return false if simulation mode hidden in System block dialog
flag = true;
end
end
end
I would like to obtain the receivedFlag value from the HelperV2VReceiver code in the Follower1 Simulink example and plot it in platooning.mlx. What should I do? https://kr.mathworks.com/help/driving/ug/truck-platooning-with-roadrunner-scenario.html
classdef HelperV2VReceiver < matlab.System
% HelperV2VReceiver Models a V2V receiver.
% The V2V Receiver receives the Basic Safety Message transmitted by the
% target vehicles based on SNR graphs. The SNR data is adjusted based
% on the range and loaded during simulation.
% NOTE: The name of this System Object and its functionality may
% change without notice in a future release,
% or the System Object itself may be removed.
% Copyright 2021-2023 The MathWorks, Inc.
properties(Nontunable)
% V2V Channel Info
SnrCurves = struct;
% Output Struct
OutputStruct = struct;
end
% Pre-computed constants
properties(Access = private)
% Holds the information of precomputed snr curves
DistanceToSnrInfo
SnrToTputInfo
% Holds the information of snr & distance limits
MaxVehDist;
SnrMin;
SnrMax;
% Maximum range
MaxRange = 1000;
% Output Bus
BSMOut
% Minimum Throughput Percentage
MinTput = 60;
end
methods(Access = protected)
function sts = getSampleTimeImpl(obj)
sts = createSampleTime(obj,’Type’,’Inherited’);
end
function setupImpl(obj)
% Distance to SNR Relation
obj.DistanceToSnrInfo = obj.SnrCurves.dist2snr;
% SNR to Throughput Relation
obj.SnrToTputInfo = obj.SnrCurves.snr2tput;
% Get the limits for Distance & SNR
obj.MaxVehDist = obj.DistanceToSnrInfo(end,1);
obj.SnrMin = obj.SnrToTputInfo(1,1);
obj.SnrMax = obj.SnrToTputInfo(end,1);
% Initialize Output Bus
obj.BSMOut = obj.OutputStruct;
end
function bsmOut = stepImpl(obj,bsm,egoPose,sceneOrigin)
numReceivedSignal = 0;
bsmOut = obj.BSMOut;
bsmOutIdx = 1;
for i = 1:bsm.NumOfBSM
if bsm.BSMCoreData(i).Id > 0
% Compute the Ego to Target Vehicle distance
vehPos = [0,0,0];
lla = [double(bsm.BSMCoreData(i).Lattitude)*10^-7,double(bsm.BSMCoreData(i).Longitude)*10^-7,double(bsm.BSMCoreData(i).Elevation)*0.1];
% Convert geographic coordinates to local Cartesian coordinates
[vehPos(1),vehPos(2),vehPos(3)] = latlon2local(lla(1),lla(2),lla(3),sceneOrigin);
v2vdist = norm(egoPose.Position – vehPos);
% Find the throughput percentage for the v2vdist using
% the precomputed snr curves.
if v2vdist<obj.MaxVehDist
v2vdist = max(1,round(v2vdist));
snrEstimate = min(max(obj.SnrMin,interp1(obj.DistanceToSnrInfo(:,1),obj.DistanceToSnrInfo(:,2),v2vdist)),obj.SnrMax);
tput = interp1(obj.SnrToTputInfo(:,1),obj.SnrToTputInfo(:,2),snrEstimate);
else
tput = 0;
end
% Receive the signal based on throughput
receivedFlag = randi([obj.MinTput 100]) <= tput;
if receivedFlag
numReceivedSignal = numReceivedSignal+1;
bsmOut.IsValidTime = true;
bsmOut.BSMCoreData(bsmOutIdx) = bsm.BSMCoreData(i);
bsmOutIdx = bsmOutIdx+1;
end
end
end
bsmOut.NumOfBSM = numReceivedSignal;
end
function bsmOut = getOutputSizeImpl(obj) %#ok<MANU>
% Return size for each output port
bsmOut = 1;
end
function bsmOut = getOutputDataTypeImpl(obj) %#ok<MANU>
% Return data type for each output port
bsmOut = ‘BusBSM’;
end
function bsmOut = isOutputComplexImpl(obj) %#ok<MANU>
% Return true for each output port with complex data
bsmOut = false;
end
function bsmOut = isOutputFixedSizeImpl(obj) %#ok<MANU>
% Return true for each output port with fixed size
bsmOut = true;
end
end
methods(Access = protected, Static)
function flag = showSimulateUsingImpl
% Return false if simulation mode hidden in System block dialog
flag = true;
end
end
end
I would like to obtain the receivedFlag value from the HelperV2VReceiver code in the Follower1 Simulink example and plot it in platooning.mlx. What should I do? simulink, roadrunner, matlab MATLAB Answers — New Questions
trainnet gives training loss is NaN
Hello, I’m currently working on semantic segmentation with Unet architecture on matlab. As version R2024a, I tried to train my model with the trainnet command. But after I ran my script, it gives me this result in Command Window.
I tried to change the MiniBatchSize and MaxEpoch but none seem to be working, it seemed like the training never happened because my GPU doesn’t seem to have any activity. Does anyone know how to resolve this? Is Matlab R2024a still buggy so this happens?Hello, I’m currently working on semantic segmentation with Unet architecture on matlab. As version R2024a, I tried to train my model with the trainnet command. But after I ran my script, it gives me this result in Command Window.
I tried to change the MiniBatchSize and MaxEpoch but none seem to be working, it seemed like the training never happened because my GPU doesn’t seem to have any activity. Does anyone know how to resolve this? Is Matlab R2024a still buggy so this happens? Hello, I’m currently working on semantic segmentation with Unet architecture on matlab. As version R2024a, I tried to train my model with the trainnet command. But after I ran my script, it gives me this result in Command Window.
I tried to change the MiniBatchSize and MaxEpoch but none seem to be working, it seemed like the training never happened because my GPU doesn’t seem to have any activity. Does anyone know how to resolve this? Is Matlab R2024a still buggy so this happens? deep learning MATLAB Answers — New Questions
Set vector direction to point away from a closed surface (or a point coordinate)?
Dear all,
I am plotting a closed potato-shaped surface using "patch", then adding some tangent planes using
plane=surf(x,y,z)
But when I am plotting the normals of those planes, using
normals=plane.FaceNormals
some of them are pointing "inwards" towards the potato, while others point outward away from it. How can I make them all point away from the surface (or the center) of the potato?
Thank you kindly!Dear all,
I am plotting a closed potato-shaped surface using "patch", then adding some tangent planes using
plane=surf(x,y,z)
But when I am plotting the normals of those planes, using
normals=plane.FaceNormals
some of them are pointing "inwards" towards the potato, while others point outward away from it. How can I make them all point away from the surface (or the center) of the potato?
Thank you kindly! Dear all,
I am plotting a closed potato-shaped surface using "patch", then adding some tangent planes using
plane=surf(x,y,z)
But when I am plotting the normals of those planes, using
normals=plane.FaceNormals
some of them are pointing "inwards" towards the potato, while others point outward away from it. How can I make them all point away from the surface (or the center) of the potato?
Thank you kindly! surf, patch, normal vectors MATLAB Answers — New Questions
Modeling a pde on matlab
How do I model the given pde on matlabHow do I model the given pde on matlab How do I model the given pde on matlab pde MATLAB Answers — New Questions
How to manually edit located peaks using findpeaks function?
I’m trying to use findpeaks to localize R peaks from electrocardiogram signal. I’m getting good results but there are some missing and false positive peaks. So, I would like to know if there is an option to manually edit the located peaks. If it is not possible to manually edit the data I would be glad reciving any other suggestion. Thanks.I’m trying to use findpeaks to localize R peaks from electrocardiogram signal. I’m getting good results but there are some missing and false positive peaks. So, I would like to know if there is an option to manually edit the located peaks. If it is not possible to manually edit the data I would be glad reciving any other suggestion. Thanks. I’m trying to use findpeaks to localize R peaks from electrocardiogram signal. I’m getting good results but there are some missing and false positive peaks. So, I would like to know if there is an option to manually edit the located peaks. If it is not possible to manually edit the data I would be glad reciving any other suggestion. Thanks. manually edit peaks, findpeaks, missing peaks MATLAB Answers — New Questions
Save struct field names with hyphens/dash in JSON?
It is quite common to use hyphens/dashes (-) in the field names of JSON, like this:
{
"file-series-version" : "1.0",
"files" : [
{ "name" : "foo1.vtk", "time" : 0 },
{ "name" : "foo2.vtk", "time" : 5.5 },
{ "name" : "foo3.vtk", "time" : 11.2 }
]
}
However, I haven’t found a way to get a hyphen character into the JSON with the JSON encoder https://se.mathworks.com/help/matlab/ref/jsonencode.html as that has to be done through the field names of a struct, incorrectly like this
jsonObj = struct(‘file-series-version’, 1); % This will generate ‘Invalid field name "file-series-version".’
jsonencode(jsonObj)
So, is there any standardized way of creating these kind of JSON objects with the jsonencode function? My alternative would be to use camelCase on the field names, and regex over the JSON-string after encoding to convert them into kebab-case, but that is not a generally good idea.It is quite common to use hyphens/dashes (-) in the field names of JSON, like this:
{
"file-series-version" : "1.0",
"files" : [
{ "name" : "foo1.vtk", "time" : 0 },
{ "name" : "foo2.vtk", "time" : 5.5 },
{ "name" : "foo3.vtk", "time" : 11.2 }
]
}
However, I haven’t found a way to get a hyphen character into the JSON with the JSON encoder https://se.mathworks.com/help/matlab/ref/jsonencode.html as that has to be done through the field names of a struct, incorrectly like this
jsonObj = struct(‘file-series-version’, 1); % This will generate ‘Invalid field name "file-series-version".’
jsonencode(jsonObj)
So, is there any standardized way of creating these kind of JSON objects with the jsonencode function? My alternative would be to use camelCase on the field names, and regex over the JSON-string after encoding to convert them into kebab-case, but that is not a generally good idea. It is quite common to use hyphens/dashes (-) in the field names of JSON, like this:
{
"file-series-version" : "1.0",
"files" : [
{ "name" : "foo1.vtk", "time" : 0 },
{ "name" : "foo2.vtk", "time" : 5.5 },
{ "name" : "foo3.vtk", "time" : 11.2 }
]
}
However, I haven’t found a way to get a hyphen character into the JSON with the JSON encoder https://se.mathworks.com/help/matlab/ref/jsonencode.html as that has to be done through the field names of a struct, incorrectly like this
jsonObj = struct(‘file-series-version’, 1); % This will generate ‘Invalid field name "file-series-version".’
jsonencode(jsonObj)
So, is there any standardized way of creating these kind of JSON objects with the jsonencode function? My alternative would be to use camelCase on the field names, and regex over the JSON-string after encoding to convert them into kebab-case, but that is not a generally good idea. json hyphen dash MATLAB Answers — New Questions
Matlab run_functional test r2022a is failing with “unrecognized function or variable ‘ippl'”
Matlab test suite r2021b is passing but when we run r2022a, run_functional.m fails almost immediately with the error message in the Summary. Here is the code where the issue is found at the beginning of run_functional.
%% Show info about IPP
[isIPPOn, ippVersion] = ippl; disp(‘IPP enabled: ‘); disp(isIPPOn); disp(‘IPP version:’); disp(ippVersion);
Has the function ippl been replaced by another function to detect the presence of Intel® Integrated Performance Primitives on the test system?Matlab test suite r2021b is passing but when we run r2022a, run_functional.m fails almost immediately with the error message in the Summary. Here is the code where the issue is found at the beginning of run_functional.
%% Show info about IPP
[isIPPOn, ippVersion] = ippl; disp(‘IPP enabled: ‘); disp(isIPPOn); disp(‘IPP version:’); disp(ippVersion);
Has the function ippl been replaced by another function to detect the presence of Intel® Integrated Performance Primitives on the test system? Matlab test suite r2021b is passing but when we run r2022a, run_functional.m fails almost immediately with the error message in the Summary. Here is the code where the issue is found at the beginning of run_functional.
%% Show info about IPP
[isIPPOn, ippVersion] = ippl; disp(‘IPP enabled: ‘); disp(isIPPOn); disp(‘IPP version:’); disp(ippVersion);
Has the function ippl been replaced by another function to detect the presence of Intel® Integrated Performance Primitives on the test system? r2022a MATLAB Answers — New Questions
Where can I find a good example of using tied weights in nested layers?
I could use some guidance on how to use tied weights for an autoencoder. The example provided in the documentation throws several errors within the dlnetwork object it uses. I would appreciate an-up-to-date example of weight tying or guidance on how to update the MathWorks example to function again.I could use some guidance on how to use tied weights for an autoencoder. The example provided in the documentation throws several errors within the dlnetwork object it uses. I would appreciate an-up-to-date example of weight tying or guidance on how to update the MathWorks example to function again. I could use some guidance on how to use tied weights for an autoencoder. The example provided in the documentation throws several errors within the dlnetwork object it uses. I would appreciate an-up-to-date example of weight tying or guidance on how to update the MathWorks example to function again. deep learning, weight-tying, nested networks MATLAB Answers — New Questions
Analyze MIMIC III waveform data directly in Matlab
I would like to analyze MIMIC III waveform data (mainly PPG and ABP) directly in Matlab on a MacOS without going through Google or AWS database queries. Has anyone done this? Can you advise me on the best way?
Thanks
RamI would like to analyze MIMIC III waveform data (mainly PPG and ABP) directly in Matlab on a MacOS without going through Google or AWS database queries. Has anyone done this? Can you advise me on the best way?
Thanks
Ram I would like to analyze MIMIC III waveform data (mainly PPG and ABP) directly in Matlab on a MacOS without going through Google or AWS database queries. Has anyone done this? Can you advise me on the best way?
Thanks
Ram mimic MATLAB Answers — New Questions