Category: Matlab
Category Archives: Matlab
How to know what is my Personal Mathworks User Level?
Hi
The next link states of Mathworks policy regarding User Levels
Although I am a an involved community member (File Exchange/Answering etc..) – it looks like I have no User Level, although my "Reputation" exists , see attached images. (or maybe I just don’t know how to find it)
Any idea?Hi
The next link states of Mathworks policy regarding User Levels
Although I am a an involved community member (File Exchange/Answering etc..) – it looks like I have no User Level, although my "Reputation" exists , see attached images. (or maybe I just don’t know how to find it)
Any idea? Hi
The next link states of Mathworks policy regarding User Levels
Although I am a an involved community member (File Exchange/Answering etc..) – it looks like I have no User Level, although my "Reputation" exists , see attached images. (or maybe I just don’t know how to find it)
Any idea? user level MATLAB Answers — New Questions
What is McDStuff 2.0?
McStuff 2.0 is likely an internal system or application used by McDonald’s employees. While there isn’t publicly available information about it. If you’re a McDonald’s employee and require more information about McStuff 2.0 UK, you can try reaching out to your manager or HR department. They’ll be able to provide specific details and resources about how to use the system.McStuff 2.0 is likely an internal system or application used by McDonald’s employees. While there isn’t publicly available information about it. If you’re a McDonald’s employee and require more information about McStuff 2.0 UK, you can try reaching out to your manager or HR department. They’ll be able to provide specific details and resources about how to use the system. McStuff 2.0 is likely an internal system or application used by McDonald’s employees. While there isn’t publicly available information about it. If you’re a McDonald’s employee and require more information about McStuff 2.0 UK, you can try reaching out to your manager or HR department. They’ll be able to provide specific details and resources about how to use the system. mystuff, mcdstuff MATLAB Answers — New Questions
Level-2 S-Function in Simulink subsystem
I’m working with a Level-2 S-Function in a Simulink subsystem and I would like to configure some parameters (IP, sample time) from the subsystem mask so that I don’t have to edit the Matlab code on every change, defining them into the S-Function as a variable. How can these parameters be passed to the S-Function?
The error I get is: "Cannot access data in ‘simulink_pr/Subsystem/ ‘. The probable cause of this error is accessing data that is available only when simulation is running"
Thank you very muchI’m working with a Level-2 S-Function in a Simulink subsystem and I would like to configure some parameters (IP, sample time) from the subsystem mask so that I don’t have to edit the Matlab code on every change, defining them into the S-Function as a variable. How can these parameters be passed to the S-Function?
The error I get is: "Cannot access data in ‘simulink_pr/Subsystem/ ‘. The probable cause of this error is accessing data that is available only when simulation is running"
Thank you very much I’m working with a Level-2 S-Function in a Simulink subsystem and I would like to configure some parameters (IP, sample time) from the subsystem mask so that I don’t have to edit the Matlab code on every change, defining them into the S-Function as a variable. How can these parameters be passed to the S-Function?
The error I get is: "Cannot access data in ‘simulink_pr/Subsystem/ ‘. The probable cause of this error is accessing data that is available only when simulation is running"
Thank you very much s-function, simulink, mask MATLAB Answers — New Questions
Interpreting the results of DWT
Hi, I am currently using the DWT to detect transients in my signal. When doing the DWT on my signal I use the following command:
[cA,cD] = dwt(signal,’db4′)
And when I plot cD and cA respectively, they both look like the original signal. Does this mean that there are both low and high frequency components in the dwt or is there another interpretation of this result?Hi, I am currently using the DWT to detect transients in my signal. When doing the DWT on my signal I use the following command:
[cA,cD] = dwt(signal,’db4′)
And when I plot cD and cA respectively, they both look like the original signal. Does this mean that there are both low and high frequency components in the dwt or is there another interpretation of this result? Hi, I am currently using the DWT to detect transients in my signal. When doing the DWT on my signal I use the following command:
[cA,cD] = dwt(signal,’db4′)
And when I plot cD and cA respectively, they both look like the original signal. Does this mean that there are both low and high frequency components in the dwt or is there another interpretation of this result? frequency MATLAB Answers — New Questions
Individual Activation Issue with maintainence
Dear, All.
When I try to deactive and active the MATLAB to same computer due to my mistake, I am failed to activate MATLAB again.
I showed the following message.
"No more machine transfers available."
So I buy the maintainance support for reactivation two time until 2027 but the activation process doen’t work properly.
Also, I can see the activation computer list in my license management. Currently, I am traveling outside Korea. Is the activation related to nation?
Best regards,Dear, All.
When I try to deactive and active the MATLAB to same computer due to my mistake, I am failed to activate MATLAB again.
I showed the following message.
"No more machine transfers available."
So I buy the maintainance support for reactivation two time until 2027 but the activation process doen’t work properly.
Also, I can see the activation computer list in my license management. Currently, I am traveling outside Korea. Is the activation related to nation?
Best regards, Dear, All.
When I try to deactive and active the MATLAB to same computer due to my mistake, I am failed to activate MATLAB again.
I showed the following message.
"No more machine transfers available."
So I buy the maintainance support for reactivation two time until 2027 but the activation process doen’t work properly.
Also, I can see the activation computer list in my license management. Currently, I am traveling outside Korea. Is the activation related to nation?
Best regards, license, activation, individual MATLAB Answers — New Questions
simulink FMU export fail
I attempted to export an Standalone FMU from Simulink environment, but encountered the following error: "[an installation of Microsoft Visual C++ 2017 cannot be detected]".
I tried installing Microsoft Visual C++ 2015-2020 package, restarted the PC, and retried, but encountered the same error. Installing C++ 2017 separately and retrying also resulted in the same error.
I even tried with a simple model (consisting of only one ramp block and one sum block), suspecting a Simulink model issue, but the error persisted.
I would like to inquire about possible solutions to this problem.
diagnosis viewer text :
Setting ExportedContent to ‘off’. Option to export archived project is not supported if Generate32BitDLL is ‘on’. Setting CreateModelAfterGeneratingFMU to ‘off’. CreateModelAfterGeneratingFMU option is not supported if Generate32BitDLL is ‘on’. ‘GenCodeOnly’ is disabled for Co-Simulation Standalone FMU Export. Setting System Target to FMU Co-Simulation for model ‘ex_26_fchev_simulink’. Setting Hardware Implementation > Device Type to ‘MATLAB Host’ for model ‘ex_26_fchev_simulink’. Generating 32-bit MSVC toolchain.
An installation of Microsoft Visual C++ 2017 cannot be detecteI attempted to export an Standalone FMU from Simulink environment, but encountered the following error: "[an installation of Microsoft Visual C++ 2017 cannot be detected]".
I tried installing Microsoft Visual C++ 2015-2020 package, restarted the PC, and retried, but encountered the same error. Installing C++ 2017 separately and retrying also resulted in the same error.
I even tried with a simple model (consisting of only one ramp block and one sum block), suspecting a Simulink model issue, but the error persisted.
I would like to inquire about possible solutions to this problem.
diagnosis viewer text :
Setting ExportedContent to ‘off’. Option to export archived project is not supported if Generate32BitDLL is ‘on’. Setting CreateModelAfterGeneratingFMU to ‘off’. CreateModelAfterGeneratingFMU option is not supported if Generate32BitDLL is ‘on’. ‘GenCodeOnly’ is disabled for Co-Simulation Standalone FMU Export. Setting System Target to FMU Co-Simulation for model ‘ex_26_fchev_simulink’. Setting Hardware Implementation > Device Type to ‘MATLAB Host’ for model ‘ex_26_fchev_simulink’. Generating 32-bit MSVC toolchain.
An installation of Microsoft Visual C++ 2017 cannot be detecte I attempted to export an Standalone FMU from Simulink environment, but encountered the following error: "[an installation of Microsoft Visual C++ 2017 cannot be detected]".
I tried installing Microsoft Visual C++ 2015-2020 package, restarted the PC, and retried, but encountered the same error. Installing C++ 2017 separately and retrying also resulted in the same error.
I even tried with a simple model (consisting of only one ramp block and one sum block), suspecting a Simulink model issue, but the error persisted.
I would like to inquire about possible solutions to this problem.
diagnosis viewer text :
Setting ExportedContent to ‘off’. Option to export archived project is not supported if Generate32BitDLL is ‘on’. Setting CreateModelAfterGeneratingFMU to ‘off’. CreateModelAfterGeneratingFMU option is not supported if Generate32BitDLL is ‘on’. ‘GenCodeOnly’ is disabled for Co-Simulation Standalone FMU Export. Setting System Target to FMU Co-Simulation for model ‘ex_26_fchev_simulink’. Setting Hardware Implementation > Device Type to ‘MATLAB Host’ for model ‘ex_26_fchev_simulink’. Generating 32-bit MSVC toolchain.
An installation of Microsoft Visual C++ 2017 cannot be detecte fmu, simulink, visual c++ MATLAB Answers — New Questions
Why can’t I see the component library when I open my app designer?
Post Content Post Content app designer MATLAB Answers — New Questions
installation problems with trial version
can’t start trial version without a licensecan’t start trial version without a license can’t start trial version without a license trial version MATLAB Answers — New Questions
Deleting range of rows in a time series data
I have time series of rainfall data. The column 1=year, 2=month, 3=date (from 1 to 31), 4=daily rainfall value. I want to remove the rows which have range of data from year 1995 to 2016. I managed to do for one year. But not for range. How can I do so? Many thanks in advance.
RF(find(RF==1([1995:2016],:)=[] I did this code, but says error of using : inbetween 1995 & 2016I have time series of rainfall data. The column 1=year, 2=month, 3=date (from 1 to 31), 4=daily rainfall value. I want to remove the rows which have range of data from year 1995 to 2016. I managed to do for one year. But not for range. How can I do so? Many thanks in advance.
RF(find(RF==1([1995:2016],:)=[] I did this code, but says error of using : inbetween 1995 & 2016 I have time series of rainfall data. The column 1=year, 2=month, 3=date (from 1 to 31), 4=daily rainfall value. I want to remove the rows which have range of data from year 1995 to 2016. I managed to do for one year. But not for range. How can I do so? Many thanks in advance.
RF(find(RF==1([1995:2016],:)=[] I did this code, but says error of using : inbetween 1995 & 2016 deleting range of rows MATLAB Answers — New Questions
How to nest and call the fmincon function in Simulink?
Hello everyone, I’m currently trying to nest and call the fmincon function within a MATLAB Function block in Simulink. However, I’ve encountered several errors. Below, I’ll explain my code in detail. The first 53 lines involve calculating various Jacobian matrices such as G, H, and D_asterisk. Once these calculations are complete, I use these matrices along with predefined functions to compute balambda. If balambda <= 1, I define a matrix k as k = eye(7). If balambda > 1, I need to optimize and solve for matrix k using the fmincon function. The initial value for k is set as k = diag([ones(1,4) lambda(1,1) lambda(2,2) lambda(3,3)]). Thus, I need to optimize lambda using fmincon, where k is implicit in the objective function. To obtain my objective function, a series of intermediate variables such as p_, k_gain, and xr need to be derived from k matrix. Currently, my approach is resulting in errors. How can I achieve my goal? I understand fmincon cannot be called directly and requires setting up a wrapper. How should I set up this wrapper?
function [x,xr,G1,G2,G,H,D_asterisk,V,balambda]=AEKF_UI(x,Ts,ks,kt,cs,mb,mw,y,xr_asterisk,G10,G20)
% x is the input vector
% Define the nonlinear function f(x)
% Ts是离散时间
% 单位矩阵定义得有2个,因为状态维数和观测维数不一致
Q=diag([0.1^2,0.005^2,0.1^2,0.001^2 0.1^2,0.005^2,0.1^2]);%
R=diag([0.001^2,0.001^2]);
g=@(x,xr_asterisk)[x(2);cs/mb*(x(4)-x(2))+ks/mb*(x(3)-x(1));
x(4);cs/mw*(x(2)-x(4))+ks/mw*(x(1)-x(3))+kt/mw*xr_asterisk-kt/mw*x(3);0;0;0;];
h=@(x,xr_asterisk)[cs/mb*(x(4)-x(2))+ks/mb*(x(3)-x(1));cs/mw*(x(2)-x(4))+ks/mw*(x(1)-x(3))+kt/mw*xr_asterisk-kt/mw*x(3)];
% Number of variables
n=numel(x);
p=eye(n);
f=numel(xr_asterisk);
% Number of functions
m=numel(g(x,xr_asterisk));%numel用来计算元素的个数,3*4矩阵元素共有12个
l=numel(h(x,xr_asterisk));
I1=eye(n);
I2=eye(l);
% Initialize the Jacobian matrix
G=zeros(m,n);
H=zeros(l,n);
D_asterisk=zeros(l,f);
%D矩阵要对未知输入求偏导
% Small perturbation value for finite difference
delta=1e-6;
% Compute the Jacobian matrix using central difference approximation
x_=x+Ts*g(x,xr_asterisk);
% 对x求偏导
for i=1:n
x1=x;
x2=x;
x3=x_;
x4=x_;
x1(i)=x1(i)+delta;
x2(i)=x2(i)-delta;
x3(i)=x3(i)+delta;
x4(i)=x4(i)-delta;
g1=g(x1,xr_asterisk);
g2=g(x2,xr_asterisk);
h1=h(x3,xr_asterisk);
h2=h(x4,xr_asterisk);
% Finite difference approximation
G(:,i)=(g1-g2)/(2*delta);
H(:,i)=(h1-h2)/(2*delta);
end
for i=1:f
x5=xr_asterisk;
x6=xr_asterisk;
x5(i)=x5(i)+delta;
x6(i)=x6(i)-delta;
D_asterisk(:,i)=(h(x_,x5)-h(x_,x6))/(2*delta);
end
gamma=y-h(x_,xr_asterisk);
mu=0.95;
persistent balambda
if isempty(balambda)
balambda=0.999;
end
G1=gamma*gamma’+mu*(G10/balambda);
G2=1+mu*(G20/balambda);
V=G1/G2;
T1=H*(I1+Ts*G)*p*(I1+Ts*G)’*H’;
T2=H*Q*H’+R;
Ta=trace(T1*inv(R)*T1′);
Tb=trace(T1*inv(R)*T2’+T2*inv(R)*T1′);
Tc=trace(T2*inv(R)*T2′)-trace(V)
balambda=(-Tb+sqrt(Tb^2-4*Ta*Tc))/(2*Ta);
if balambda>1
k=eye(7);%lambda矩阵
else
lambda=diag([balambda*ones(1,3)]);
k=diag([ones(1,4) lambda(1,1) lambda(2,2) lambda(3,3)]);
%定义目标函数
%创建一个自适应因子对角矩阵,前面状态量都是1,后面识别参数都是lambda
initial_values=[lambda(1,1),lambda(2,2),lambda(3,3)];
x_chushi=x;
lb=[1,1,1]; % 下界
ub=[Inf,Inf,Inf]; % 上界
options=optimoptions(‘fmincon’,’Display’,’iter’);
lambda_opt=fmincon(@(lambda)objective_function(lambda,x_chushi,I1,I2,Ts,G,D_asterisk,R,h,x_,xr_asterisk,Q,p,H,y),initial_values,[],[],[],[],lb,ub,@(lambda)nonlcon(V,R,H,p_),options);
%更新lambda 值
lambda(1,1)=lambda_opt(1);
lambda(2,2)=lambda_opt(2);
lambda(3,3)=lambda_opt(3);
end
function J_value=objective_function(lambda,x_chushi,I1,I2,Ts,G,D_asterisk,R,h,x_,xr_asterisk,Q,p,H,y,k)
% objective_function k=diag([ones(1,4) lambda(1) lambda(2) lambda(3)]);
p_=k*(I1+Ts*G)*p*(I1+Ts*G)’*k’+Q;
k_gain=p_*H’/(H*p_*H’+R);
S=inv(D_asterisk’*inv(R)*(I2-H*k_gain)*D_asterisk);
xr=S*(D_asterisk’)*inv(R)*(I2-H*k_gain)*(y-h(x_,xr_asterisk)+D_asterisk*xr_asterisk);
x=x_+k_gain*(y-h(x_,xr_asterisk)-D_asterisk*(xr-xr_asterisk));
J_value=sum(abs((x(4:7)-x_chushi(4:7))./x_chushi(4:7)));
end
function [c,ceq] = nonlcon(V,R,H,p_)
% 非线性约束函数,计算状态量与观测量之间的差异
c=norm(V-(H*p_*H’+R)*inv(R)*(H*p_*H’+R)’,"fro")-0.01;
ceq=[];Hello everyone, I’m currently trying to nest and call the fmincon function within a MATLAB Function block in Simulink. However, I’ve encountered several errors. Below, I’ll explain my code in detail. The first 53 lines involve calculating various Jacobian matrices such as G, H, and D_asterisk. Once these calculations are complete, I use these matrices along with predefined functions to compute balambda. If balambda <= 1, I define a matrix k as k = eye(7). If balambda > 1, I need to optimize and solve for matrix k using the fmincon function. The initial value for k is set as k = diag([ones(1,4) lambda(1,1) lambda(2,2) lambda(3,3)]). Thus, I need to optimize lambda using fmincon, where k is implicit in the objective function. To obtain my objective function, a series of intermediate variables such as p_, k_gain, and xr need to be derived from k matrix. Currently, my approach is resulting in errors. How can I achieve my goal? I understand fmincon cannot be called directly and requires setting up a wrapper. How should I set up this wrapper?
function [x,xr,G1,G2,G,H,D_asterisk,V,balambda]=AEKF_UI(x,Ts,ks,kt,cs,mb,mw,y,xr_asterisk,G10,G20)
% x is the input vector
% Define the nonlinear function f(x)
% Ts是离散时间
% 单位矩阵定义得有2个,因为状态维数和观测维数不一致
Q=diag([0.1^2,0.005^2,0.1^2,0.001^2 0.1^2,0.005^2,0.1^2]);%
R=diag([0.001^2,0.001^2]);
g=@(x,xr_asterisk)[x(2);cs/mb*(x(4)-x(2))+ks/mb*(x(3)-x(1));
x(4);cs/mw*(x(2)-x(4))+ks/mw*(x(1)-x(3))+kt/mw*xr_asterisk-kt/mw*x(3);0;0;0;];
h=@(x,xr_asterisk)[cs/mb*(x(4)-x(2))+ks/mb*(x(3)-x(1));cs/mw*(x(2)-x(4))+ks/mw*(x(1)-x(3))+kt/mw*xr_asterisk-kt/mw*x(3)];
% Number of variables
n=numel(x);
p=eye(n);
f=numel(xr_asterisk);
% Number of functions
m=numel(g(x,xr_asterisk));%numel用来计算元素的个数,3*4矩阵元素共有12个
l=numel(h(x,xr_asterisk));
I1=eye(n);
I2=eye(l);
% Initialize the Jacobian matrix
G=zeros(m,n);
H=zeros(l,n);
D_asterisk=zeros(l,f);
%D矩阵要对未知输入求偏导
% Small perturbation value for finite difference
delta=1e-6;
% Compute the Jacobian matrix using central difference approximation
x_=x+Ts*g(x,xr_asterisk);
% 对x求偏导
for i=1:n
x1=x;
x2=x;
x3=x_;
x4=x_;
x1(i)=x1(i)+delta;
x2(i)=x2(i)-delta;
x3(i)=x3(i)+delta;
x4(i)=x4(i)-delta;
g1=g(x1,xr_asterisk);
g2=g(x2,xr_asterisk);
h1=h(x3,xr_asterisk);
h2=h(x4,xr_asterisk);
% Finite difference approximation
G(:,i)=(g1-g2)/(2*delta);
H(:,i)=(h1-h2)/(2*delta);
end
for i=1:f
x5=xr_asterisk;
x6=xr_asterisk;
x5(i)=x5(i)+delta;
x6(i)=x6(i)-delta;
D_asterisk(:,i)=(h(x_,x5)-h(x_,x6))/(2*delta);
end
gamma=y-h(x_,xr_asterisk);
mu=0.95;
persistent balambda
if isempty(balambda)
balambda=0.999;
end
G1=gamma*gamma’+mu*(G10/balambda);
G2=1+mu*(G20/balambda);
V=G1/G2;
T1=H*(I1+Ts*G)*p*(I1+Ts*G)’*H’;
T2=H*Q*H’+R;
Ta=trace(T1*inv(R)*T1′);
Tb=trace(T1*inv(R)*T2’+T2*inv(R)*T1′);
Tc=trace(T2*inv(R)*T2′)-trace(V)
balambda=(-Tb+sqrt(Tb^2-4*Ta*Tc))/(2*Ta);
if balambda>1
k=eye(7);%lambda矩阵
else
lambda=diag([balambda*ones(1,3)]);
k=diag([ones(1,4) lambda(1,1) lambda(2,2) lambda(3,3)]);
%定义目标函数
%创建一个自适应因子对角矩阵,前面状态量都是1,后面识别参数都是lambda
initial_values=[lambda(1,1),lambda(2,2),lambda(3,3)];
x_chushi=x;
lb=[1,1,1]; % 下界
ub=[Inf,Inf,Inf]; % 上界
options=optimoptions(‘fmincon’,’Display’,’iter’);
lambda_opt=fmincon(@(lambda)objective_function(lambda,x_chushi,I1,I2,Ts,G,D_asterisk,R,h,x_,xr_asterisk,Q,p,H,y),initial_values,[],[],[],[],lb,ub,@(lambda)nonlcon(V,R,H,p_),options);
%更新lambda 值
lambda(1,1)=lambda_opt(1);
lambda(2,2)=lambda_opt(2);
lambda(3,3)=lambda_opt(3);
end
function J_value=objective_function(lambda,x_chushi,I1,I2,Ts,G,D_asterisk,R,h,x_,xr_asterisk,Q,p,H,y,k)
% objective_function k=diag([ones(1,4) lambda(1) lambda(2) lambda(3)]);
p_=k*(I1+Ts*G)*p*(I1+Ts*G)’*k’+Q;
k_gain=p_*H’/(H*p_*H’+R);
S=inv(D_asterisk’*inv(R)*(I2-H*k_gain)*D_asterisk);
xr=S*(D_asterisk’)*inv(R)*(I2-H*k_gain)*(y-h(x_,xr_asterisk)+D_asterisk*xr_asterisk);
x=x_+k_gain*(y-h(x_,xr_asterisk)-D_asterisk*(xr-xr_asterisk));
J_value=sum(abs((x(4:7)-x_chushi(4:7))./x_chushi(4:7)));
end
function [c,ceq] = nonlcon(V,R,H,p_)
% 非线性约束函数,计算状态量与观测量之间的差异
c=norm(V-(H*p_*H’+R)*inv(R)*(H*p_*H’+R)’,"fro")-0.01;
ceq=[]; Hello everyone, I’m currently trying to nest and call the fmincon function within a MATLAB Function block in Simulink. However, I’ve encountered several errors. Below, I’ll explain my code in detail. The first 53 lines involve calculating various Jacobian matrices such as G, H, and D_asterisk. Once these calculations are complete, I use these matrices along with predefined functions to compute balambda. If balambda <= 1, I define a matrix k as k = eye(7). If balambda > 1, I need to optimize and solve for matrix k using the fmincon function. The initial value for k is set as k = diag([ones(1,4) lambda(1,1) lambda(2,2) lambda(3,3)]). Thus, I need to optimize lambda using fmincon, where k is implicit in the objective function. To obtain my objective function, a series of intermediate variables such as p_, k_gain, and xr need to be derived from k matrix. Currently, my approach is resulting in errors. How can I achieve my goal? I understand fmincon cannot be called directly and requires setting up a wrapper. How should I set up this wrapper?
function [x,xr,G1,G2,G,H,D_asterisk,V,balambda]=AEKF_UI(x,Ts,ks,kt,cs,mb,mw,y,xr_asterisk,G10,G20)
% x is the input vector
% Define the nonlinear function f(x)
% Ts是离散时间
% 单位矩阵定义得有2个,因为状态维数和观测维数不一致
Q=diag([0.1^2,0.005^2,0.1^2,0.001^2 0.1^2,0.005^2,0.1^2]);%
R=diag([0.001^2,0.001^2]);
g=@(x,xr_asterisk)[x(2);cs/mb*(x(4)-x(2))+ks/mb*(x(3)-x(1));
x(4);cs/mw*(x(2)-x(4))+ks/mw*(x(1)-x(3))+kt/mw*xr_asterisk-kt/mw*x(3);0;0;0;];
h=@(x,xr_asterisk)[cs/mb*(x(4)-x(2))+ks/mb*(x(3)-x(1));cs/mw*(x(2)-x(4))+ks/mw*(x(1)-x(3))+kt/mw*xr_asterisk-kt/mw*x(3)];
% Number of variables
n=numel(x);
p=eye(n);
f=numel(xr_asterisk);
% Number of functions
m=numel(g(x,xr_asterisk));%numel用来计算元素的个数,3*4矩阵元素共有12个
l=numel(h(x,xr_asterisk));
I1=eye(n);
I2=eye(l);
% Initialize the Jacobian matrix
G=zeros(m,n);
H=zeros(l,n);
D_asterisk=zeros(l,f);
%D矩阵要对未知输入求偏导
% Small perturbation value for finite difference
delta=1e-6;
% Compute the Jacobian matrix using central difference approximation
x_=x+Ts*g(x,xr_asterisk);
% 对x求偏导
for i=1:n
x1=x;
x2=x;
x3=x_;
x4=x_;
x1(i)=x1(i)+delta;
x2(i)=x2(i)-delta;
x3(i)=x3(i)+delta;
x4(i)=x4(i)-delta;
g1=g(x1,xr_asterisk);
g2=g(x2,xr_asterisk);
h1=h(x3,xr_asterisk);
h2=h(x4,xr_asterisk);
% Finite difference approximation
G(:,i)=(g1-g2)/(2*delta);
H(:,i)=(h1-h2)/(2*delta);
end
for i=1:f
x5=xr_asterisk;
x6=xr_asterisk;
x5(i)=x5(i)+delta;
x6(i)=x6(i)-delta;
D_asterisk(:,i)=(h(x_,x5)-h(x_,x6))/(2*delta);
end
gamma=y-h(x_,xr_asterisk);
mu=0.95;
persistent balambda
if isempty(balambda)
balambda=0.999;
end
G1=gamma*gamma’+mu*(G10/balambda);
G2=1+mu*(G20/balambda);
V=G1/G2;
T1=H*(I1+Ts*G)*p*(I1+Ts*G)’*H’;
T2=H*Q*H’+R;
Ta=trace(T1*inv(R)*T1′);
Tb=trace(T1*inv(R)*T2’+T2*inv(R)*T1′);
Tc=trace(T2*inv(R)*T2′)-trace(V)
balambda=(-Tb+sqrt(Tb^2-4*Ta*Tc))/(2*Ta);
if balambda>1
k=eye(7);%lambda矩阵
else
lambda=diag([balambda*ones(1,3)]);
k=diag([ones(1,4) lambda(1,1) lambda(2,2) lambda(3,3)]);
%定义目标函数
%创建一个自适应因子对角矩阵,前面状态量都是1,后面识别参数都是lambda
initial_values=[lambda(1,1),lambda(2,2),lambda(3,3)];
x_chushi=x;
lb=[1,1,1]; % 下界
ub=[Inf,Inf,Inf]; % 上界
options=optimoptions(‘fmincon’,’Display’,’iter’);
lambda_opt=fmincon(@(lambda)objective_function(lambda,x_chushi,I1,I2,Ts,G,D_asterisk,R,h,x_,xr_asterisk,Q,p,H,y),initial_values,[],[],[],[],lb,ub,@(lambda)nonlcon(V,R,H,p_),options);
%更新lambda 值
lambda(1,1)=lambda_opt(1);
lambda(2,2)=lambda_opt(2);
lambda(3,3)=lambda_opt(3);
end
function J_value=objective_function(lambda,x_chushi,I1,I2,Ts,G,D_asterisk,R,h,x_,xr_asterisk,Q,p,H,y,k)
% objective_function k=diag([ones(1,4) lambda(1) lambda(2) lambda(3)]);
p_=k*(I1+Ts*G)*p*(I1+Ts*G)’*k’+Q;
k_gain=p_*H’/(H*p_*H’+R);
S=inv(D_asterisk’*inv(R)*(I2-H*k_gain)*D_asterisk);
xr=S*(D_asterisk’)*inv(R)*(I2-H*k_gain)*(y-h(x_,xr_asterisk)+D_asterisk*xr_asterisk);
x=x_+k_gain*(y-h(x_,xr_asterisk)-D_asterisk*(xr-xr_asterisk));
J_value=sum(abs((x(4:7)-x_chushi(4:7))./x_chushi(4:7)));
end
function [c,ceq] = nonlcon(V,R,H,p_)
% 非线性约束函数,计算状态量与观测量之间的差异
c=norm(V-(H*p_*H’+R)*inv(R)*(H*p_*H’+R)’,"fro")-0.01;
ceq=[]; fmincon, optimization MATLAB Answers — New Questions
Why do the external parameters in stereo calibration differ between the ‘visual values’ and the ‘output T value of PoseCamera2’?
Currently, I am using two cameras to capture images of a checkerboard and performing stereo calibration to obtain external parameters. The results are shown in the attached image. Since the heights of the two cameras are almost the same, this image shows the x-axis and z-axis to highlight the current issue. The current issure is that the values on the x and z axes differ between the visual values in the image and the output PoseCamera2’s ‘T’ values.
Specifically, the values in the image are: about[1300, 150, 1000] while the PoseCamera2’s T = [1706, 81.48, 363].
When measured with a tape measure, the actual distance between the two cameras almost matches the values in the image. I would like to understand why the visually output results differ from the PoseCamera2 data results.Currently, I am using two cameras to capture images of a checkerboard and performing stereo calibration to obtain external parameters. The results are shown in the attached image. Since the heights of the two cameras are almost the same, this image shows the x-axis and z-axis to highlight the current issue. The current issure is that the values on the x and z axes differ between the visual values in the image and the output PoseCamera2’s ‘T’ values.
Specifically, the values in the image are: about[1300, 150, 1000] while the PoseCamera2’s T = [1706, 81.48, 363].
When measured with a tape measure, the actual distance between the two cameras almost matches the values in the image. I would like to understand why the visually output results differ from the PoseCamera2 data results. Currently, I am using two cameras to capture images of a checkerboard and performing stereo calibration to obtain external parameters. The results are shown in the attached image. Since the heights of the two cameras are almost the same, this image shows the x-axis and z-axis to highlight the current issue. The current issure is that the values on the x and z axes differ between the visual values in the image and the output PoseCamera2’s ‘T’ values.
Specifically, the values in the image are: about[1300, 150, 1000] while the PoseCamera2’s T = [1706, 81.48, 363].
When measured with a tape measure, the actual distance between the two cameras almost matches the values in the image. I would like to understand why the visually output results differ from the PoseCamera2 data results. stereocalibration, stereoparameters MATLAB Answers — New Questions
How do you disable Matlab update notifications?
How do you disable Matlab update notifications?How do you disable Matlab update notifications? How do you disable Matlab update notifications? configuration, update, notification MATLAB Answers — New Questions
How do I get the “Base Data Types” of the block Input/Output interface?
I want to get the "Base Data Types" of the Simulink module, what should I do?I want to get the "Base Data Types" of the Simulink module, what should I do? I want to get the "Base Data Types" of the Simulink module, what should I do? database MATLAB Answers — New Questions
Feasibility of using FDTD simulation with Openstreetmap
Hi,
I am doing some work on propagation of radio waves within a built up environment. I have looked at the following examples: https://uk.mathworks.com/help/antenna/ref/rfprop.raytracing.html and https://uk.mathworks.com/help/antenna/ug/urban-channel-link-analysis-and-visualization-using-ray-tracing.html where Openstreetmap has been used to set up the model for the propagation from a real world scenarios. I would like to take this a stage further with a more accurate simulation.
What I wanted to ask was, would it be feasible to use Matlab to import a Openstreetmap map containing buildings,roads, objects etc., just like in the example, and then apply the relevant boundary conditions to enable a FDTD simulation of a electromagentic wave to enable radio progation to be simulated? Obviously, I reliase this would be extremely computationally demanding.
Best regards,
AndyHi,
I am doing some work on propagation of radio waves within a built up environment. I have looked at the following examples: https://uk.mathworks.com/help/antenna/ref/rfprop.raytracing.html and https://uk.mathworks.com/help/antenna/ug/urban-channel-link-analysis-and-visualization-using-ray-tracing.html where Openstreetmap has been used to set up the model for the propagation from a real world scenarios. I would like to take this a stage further with a more accurate simulation.
What I wanted to ask was, would it be feasible to use Matlab to import a Openstreetmap map containing buildings,roads, objects etc., just like in the example, and then apply the relevant boundary conditions to enable a FDTD simulation of a electromagentic wave to enable radio progation to be simulated? Obviously, I reliase this would be extremely computationally demanding.
Best regards,
Andy Hi,
I am doing some work on propagation of radio waves within a built up environment. I have looked at the following examples: https://uk.mathworks.com/help/antenna/ref/rfprop.raytracing.html and https://uk.mathworks.com/help/antenna/ug/urban-channel-link-analysis-and-visualization-using-ray-tracing.html where Openstreetmap has been used to set up the model for the propagation from a real world scenarios. I would like to take this a stage further with a more accurate simulation.
What I wanted to ask was, would it be feasible to use Matlab to import a Openstreetmap map containing buildings,roads, objects etc., just like in the example, and then apply the relevant boundary conditions to enable a FDTD simulation of a electromagentic wave to enable radio progation to be simulated? Obviously, I reliase this would be extremely computationally demanding.
Best regards,
Andy matlab openstreetmap MATLAB Answers — New Questions
Simulink Onramp tutorial video issue
Hello everyone,
I want to start Simulink Onramp but after going into menu i am not able to find the tutorial videos. Can anyone help me regarding this?Hello everyone,
I want to start Simulink Onramp but after going into menu i am not able to find the tutorial videos. Can anyone help me regarding this? Hello everyone,
I want to start Simulink Onramp but after going into menu i am not able to find the tutorial videos. Can anyone help me regarding this? simulink MATLAB Answers — New Questions
I’m confused about how to determine the delimiter between columns for data like this
Hello, Community
I have a simple question but it was actually difficult to me. So i have data like this :
To extract the above data column by column, I used the readtable function with the detectImportOptions like this :
cek_web_kyoto_quicklook = detectImportOptions(pathfile_web_kyoto_quicklook{bul_quicklook},’ReadVariableNames’,false, ‘Delimiter’, " ", ‘EmptyFieldRule’, ‘missing’, ‘EmptyLineRule’, ‘skip’,…
‘Whitespace’, {‘bt ‘,”}, ‘FileType’,’text’,…
‘ConsecutiveDelimitersRule’, ‘join’);
cek_web_kyoto_quicklook.VariableTypes = {‘string’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’};
cek_web_kyoto_quicklook.VariableNames = {‘waktu’, ‘baseval’, ‘dst1’, ‘dst2’, ‘dst3’, ‘dst4’, ‘dst5’, ‘dst6’, ‘dst7’, ‘dst8’, ‘dst9’, ‘dst10’, ‘dst11’, ‘dst12’, ‘dst13’, ‘dst14’, ‘dst15’, ‘dst16’, ‘dst17’, ‘dst18’, ‘dst19’, ‘dst20’, ‘dst21’, ‘dst22’, ‘dst23’, ‘dst24’, ‘mean_dst’};
Tabel_Web_kyoto_quicklook0 = readtable(pathfile_web_kyoto_quicklook, cek_web_kyoto_quicklook);
Nan_tabeldst_quicklook = standardizeMissing(Tabel_Web_kyoto_quicklook0(:,2:end), {9999});
Tabel_Web_kyoto_quicklook0(:,2:end) = Nan_tabeldst_quicklook;
Tabel_Web_kyoto_quicklook = Tabel_Web_kyoto_quicklook0(1:end-1,:);
However, i dont know how to fix one of nargin inside of the detectImportOptions function, specifically " Delimiter ". I just set the Delimiter with ‘ ‘, and the result becomes like this :
From the above result in command window, numbers without separated by spaces (-127-120-120-128-124-112-112-112-110-120-117) will be NaN data, but numbers separated by spaces (-96 -88 -80 -76 -71 -75 -78 -73) will still be correct data.
The question is: How to make the data that is not separated by spaces (-127-120-120-128-124-112-112-110-120-117) can still be extracted/retrieved into complete data, which is as follows: -127 -120 -120 -128 -124 -112 -112 -112 -110 -120 -117
Any answer will be very helpful to me in finding this solution, for example by using other functions other than readtable or detectImportOptions
Thus submitted a question from me, thank for your attention and cooperationHello, Community
I have a simple question but it was actually difficult to me. So i have data like this :
To extract the above data column by column, I used the readtable function with the detectImportOptions like this :
cek_web_kyoto_quicklook = detectImportOptions(pathfile_web_kyoto_quicklook{bul_quicklook},’ReadVariableNames’,false, ‘Delimiter’, " ", ‘EmptyFieldRule’, ‘missing’, ‘EmptyLineRule’, ‘skip’,…
‘Whitespace’, {‘bt ‘,”}, ‘FileType’,’text’,…
‘ConsecutiveDelimitersRule’, ‘join’);
cek_web_kyoto_quicklook.VariableTypes = {‘string’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’};
cek_web_kyoto_quicklook.VariableNames = {‘waktu’, ‘baseval’, ‘dst1’, ‘dst2’, ‘dst3’, ‘dst4’, ‘dst5’, ‘dst6’, ‘dst7’, ‘dst8’, ‘dst9’, ‘dst10’, ‘dst11’, ‘dst12’, ‘dst13’, ‘dst14’, ‘dst15’, ‘dst16’, ‘dst17’, ‘dst18’, ‘dst19’, ‘dst20’, ‘dst21’, ‘dst22’, ‘dst23’, ‘dst24’, ‘mean_dst’};
Tabel_Web_kyoto_quicklook0 = readtable(pathfile_web_kyoto_quicklook, cek_web_kyoto_quicklook);
Nan_tabeldst_quicklook = standardizeMissing(Tabel_Web_kyoto_quicklook0(:,2:end), {9999});
Tabel_Web_kyoto_quicklook0(:,2:end) = Nan_tabeldst_quicklook;
Tabel_Web_kyoto_quicklook = Tabel_Web_kyoto_quicklook0(1:end-1,:);
However, i dont know how to fix one of nargin inside of the detectImportOptions function, specifically " Delimiter ". I just set the Delimiter with ‘ ‘, and the result becomes like this :
From the above result in command window, numbers without separated by spaces (-127-120-120-128-124-112-112-112-110-120-117) will be NaN data, but numbers separated by spaces (-96 -88 -80 -76 -71 -75 -78 -73) will still be correct data.
The question is: How to make the data that is not separated by spaces (-127-120-120-128-124-112-112-110-120-117) can still be extracted/retrieved into complete data, which is as follows: -127 -120 -120 -128 -124 -112 -112 -112 -110 -120 -117
Any answer will be very helpful to me in finding this solution, for example by using other functions other than readtable or detectImportOptions
Thus submitted a question from me, thank for your attention and cooperation Hello, Community
I have a simple question but it was actually difficult to me. So i have data like this :
To extract the above data column by column, I used the readtable function with the detectImportOptions like this :
cek_web_kyoto_quicklook = detectImportOptions(pathfile_web_kyoto_quicklook{bul_quicklook},’ReadVariableNames’,false, ‘Delimiter’, " ", ‘EmptyFieldRule’, ‘missing’, ‘EmptyLineRule’, ‘skip’,…
‘Whitespace’, {‘bt ‘,”}, ‘FileType’,’text’,…
‘ConsecutiveDelimitersRule’, ‘join’);
cek_web_kyoto_quicklook.VariableTypes = {‘string’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’, ‘double’};
cek_web_kyoto_quicklook.VariableNames = {‘waktu’, ‘baseval’, ‘dst1’, ‘dst2’, ‘dst3’, ‘dst4’, ‘dst5’, ‘dst6’, ‘dst7’, ‘dst8’, ‘dst9’, ‘dst10’, ‘dst11’, ‘dst12’, ‘dst13’, ‘dst14’, ‘dst15’, ‘dst16’, ‘dst17’, ‘dst18’, ‘dst19’, ‘dst20’, ‘dst21’, ‘dst22’, ‘dst23’, ‘dst24’, ‘mean_dst’};
Tabel_Web_kyoto_quicklook0 = readtable(pathfile_web_kyoto_quicklook, cek_web_kyoto_quicklook);
Nan_tabeldst_quicklook = standardizeMissing(Tabel_Web_kyoto_quicklook0(:,2:end), {9999});
Tabel_Web_kyoto_quicklook0(:,2:end) = Nan_tabeldst_quicklook;
Tabel_Web_kyoto_quicklook = Tabel_Web_kyoto_quicklook0(1:end-1,:);
However, i dont know how to fix one of nargin inside of the detectImportOptions function, specifically " Delimiter ". I just set the Delimiter with ‘ ‘, and the result becomes like this :
From the above result in command window, numbers without separated by spaces (-127-120-120-128-124-112-112-112-110-120-117) will be NaN data, but numbers separated by spaces (-96 -88 -80 -76 -71 -75 -78 -73) will still be correct data.
The question is: How to make the data that is not separated by spaces (-127-120-120-128-124-112-112-110-120-117) can still be extracted/retrieved into complete data, which is as follows: -127 -120 -120 -128 -124 -112 -112 -112 -110 -120 -117
Any answer will be very helpful to me in finding this solution, for example by using other functions other than readtable or detectImportOptions
Thus submitted a question from me, thank for your attention and cooperation space delimiter MATLAB Answers — New Questions
The plot for Frequency Domain Signal wont show up, where is the problem?
t = readmatrix(’10pc_NFhpf.csv’);
%sample rate
dt = 2.5e-07
%sample FREQUENCY
fs = 1/dt;
%time domain signal
figure
plot(t(1:2002,2));
title(‘Time Domain Signal’);
xlabel(‘Time (t)’);
ylabel(‘Amplitude’);
t = t(1:2002,2);
t_f = fft(t);
m = length(t_f);
freq = (-m/2:(m/2-1))*fs/(m-1);
figure
plot(freq,fftshift(abs(t_f)));
title(‘Frequency Domain Signal’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Amplitude’);t = readmatrix(’10pc_NFhpf.csv’);
%sample rate
dt = 2.5e-07
%sample FREQUENCY
fs = 1/dt;
%time domain signal
figure
plot(t(1:2002,2));
title(‘Time Domain Signal’);
xlabel(‘Time (t)’);
ylabel(‘Amplitude’);
t = t(1:2002,2);
t_f = fft(t);
m = length(t_f);
freq = (-m/2:(m/2-1))*fs/(m-1);
figure
plot(freq,fftshift(abs(t_f)));
title(‘Frequency Domain Signal’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Amplitude’); t = readmatrix(’10pc_NFhpf.csv’);
%sample rate
dt = 2.5e-07
%sample FREQUENCY
fs = 1/dt;
%time domain signal
figure
plot(t(1:2002,2));
title(‘Time Domain Signal’);
xlabel(‘Time (t)’);
ylabel(‘Amplitude’);
t = t(1:2002,2);
t_f = fft(t);
m = length(t_f);
freq = (-m/2:(m/2-1))*fs/(m-1);
figure
plot(freq,fftshift(abs(t_f)));
title(‘Frequency Domain Signal’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Amplitude’); fft, frequency domain, osclloscope MATLAB Answers — New Questions
How to convert matlab to python?
I use library compiler to convert matlab code to python, my code listed. The conversion is successful but I can’t use the code in python.
Matlab Code:
classdef testApp
properties
a1 = 0;
a2 = 0;
end
methods
function obj = start(obj,x1,x2)
obj.a1 = x1;
obj.a2 = x2;
end
end
end
Python Code:
import matlab
import testApp
aaa = testApp.initialize()
a = aaa.start(1,2)
vv = 1
Error:
SystemError: Error in MATLAB Compiler SDK for Python. Details: An error occurred during evaluation of the function start. Details: Function start not found in Python package.I use library compiler to convert matlab code to python, my code listed. The conversion is successful but I can’t use the code in python.
Matlab Code:
classdef testApp
properties
a1 = 0;
a2 = 0;
end
methods
function obj = start(obj,x1,x2)
obj.a1 = x1;
obj.a2 = x2;
end
end
end
Python Code:
import matlab
import testApp
aaa = testApp.initialize()
a = aaa.start(1,2)
vv = 1
Error:
SystemError: Error in MATLAB Compiler SDK for Python. Details: An error occurred during evaluation of the function start. Details: Function start not found in Python package. I use library compiler to convert matlab code to python, my code listed. The conversion is successful but I can’t use the code in python.
Matlab Code:
classdef testApp
properties
a1 = 0;
a2 = 0;
end
methods
function obj = start(obj,x1,x2)
obj.a1 = x1;
obj.a2 = x2;
end
end
end
Python Code:
import matlab
import testApp
aaa = testApp.initialize()
a = aaa.start(1,2)
vv = 1
Error:
SystemError: Error in MATLAB Compiler SDK for Python. Details: An error occurred during evaluation of the function start. Details: Function start not found in Python package. matlab, python MATLAB Answers — New Questions
Generate Low Frequency using ePWM module
Dear Sir,
I would like to generate low frequency PWM using ePWM module. I use F28377D to generate it in simulink as [1].
I try to generate 50 hz frequency using prescaller divider as shown [2], the detail implementation purposed in simulation of as shown in [3].Also the ePWM setting as in [4]
"however, there is no output in ePWM pinout"
Could you please to assist me pelase ?Dear Sir,
I would like to generate low frequency PWM using ePWM module. I use F28377D to generate it in simulink as [1].
I try to generate 50 hz frequency using prescaller divider as shown [2], the detail implementation purposed in simulation of as shown in [3].Also the ePWM setting as in [4]
"however, there is no output in ePWM pinout"
Could you please to assist me pelase ? Dear Sir,
I would like to generate low frequency PWM using ePWM module. I use F28377D to generate it in simulink as [1].
I try to generate 50 hz frequency using prescaller divider as shown [2], the detail implementation purposed in simulation of as shown in [3].Also the ePWM setting as in [4]
"however, there is no output in ePWM pinout"
Could you please to assist me pelase ? c2000, f28377d, epwm MATLAB Answers — New Questions
Generate deadband smaller than Ts (sample time)
Hi,
I am working with MPC for control inverter.
the output MPC connected to GPIO DO.
however i need to add deadband between MPC and GPIO.
Ts = 50e-6. and i would like to generate deadband 1e-6.
1.how to generate deadband smaller than Ts in C2000 Simulink ?
2. If there is possible to use ePWM module, hiw to set up ePWM module ?Hi,
I am working with MPC for control inverter.
the output MPC connected to GPIO DO.
however i need to add deadband between MPC and GPIO.
Ts = 50e-6. and i would like to generate deadband 1e-6.
1.how to generate deadband smaller than Ts in C2000 Simulink ?
2. If there is possible to use ePWM module, hiw to set up ePWM module ? Hi,
I am working with MPC for control inverter.
the output MPC connected to GPIO DO.
however i need to add deadband between MPC and GPIO.
Ts = 50e-6. and i would like to generate deadband 1e-6.
1.how to generate deadband smaller than Ts in C2000 Simulink ?
2. If there is possible to use ePWM module, hiw to set up ePWM module ? c2000, mpc, gpio, epwm, simulink MATLAB Answers — New Questions