Tag Archives: matlab
How to plot the loss function on the overall dataset in Training Progress
I am writing a Convolutional Neural Network for regression in MATLAB R2021b. I’m using the trainNetwork function in Deep Learning Toolbox and in options I have ‘Plots’,’training-progress’.
I have understood that in the Training Progress, for each iteration, I have the MSE value computed on the mini-batch.
I wuold like to know whether I can plot in the training progress the MSE value on the overall Training Set and Validation Set respectively and not on the mini-batch.
Thanks in advance.I am writing a Convolutional Neural Network for regression in MATLAB R2021b. I’m using the trainNetwork function in Deep Learning Toolbox and in options I have ‘Plots’,’training-progress’.
I have understood that in the Training Progress, for each iteration, I have the MSE value computed on the mini-batch.
I wuold like to know whether I can plot in the training progress the MSE value on the overall Training Set and Validation Set respectively and not on the mini-batch.
Thanks in advance. I am writing a Convolutional Neural Network for regression in MATLAB R2021b. I’m using the trainNetwork function in Deep Learning Toolbox and in options I have ‘Plots’,’training-progress’.
I have understood that in the Training Progress, for each iteration, I have the MSE value computed on the mini-batch.
I wuold like to know whether I can plot in the training progress the MSE value on the overall Training Set and Validation Set respectively and not on the mini-batch.
Thanks in advance. training progress, trainnetwork MATLAB Answers — New Questions
Connecting mesh to merge two surfaces
Hello,
Is there a way to connect the mesh of these two surfaces, transforming into just one(surface)?
Thanks in advance.
clear all;
% Welding parameters
%—————————-
U = 33; %Voltage (V)
I = 325; %Current (A)
n = 0.75; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%————————
a = 4.645; %Metade da largura (mm)
b = 6.5; %Penetração (mm)
C1 = 4.645;
C2 = 16;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
z1 = [-10:.2:0];
z2 = [0:.2:10];
[xx,zz] = meshgrid(x,z1);
A1 = ((6*sqrt(3)*FF*Q)/(a*b*C1*pi*sqrt(pi)));
B1 = exp(-1.7*(xx.^2/a.^2)).*exp(-5.0*(zz.^2/C1.^2));
[xa,za] = meshgrid (x,z2);
A2 = ((6*sqrt(3)*FR*Q)/(a*b*C2*pi*sqrt(pi)));
B2 = exp(-1.7*(xa.^2/a.^2)).*exp(-5.0*(za.^2/C2.^2));
q1 = A1.*B1;
q2 = A2.*B2;
[X,Z] = meshgrid (x,-15:.05:15);
mesh(xx,zz,q1);
hold on
mesh(xx,za,q2);
shading interp
colormap jet
xlabel(‘ x (mm)’)
ylabel(‘ Welding direction (mm)’)
zlabel(‘ Power Density (W/mm³)’)
<</matlabcentral/answers/uploaded_files/81300/DE.jpg>>Hello,
Is there a way to connect the mesh of these two surfaces, transforming into just one(surface)?
Thanks in advance.
clear all;
% Welding parameters
%—————————-
U = 33; %Voltage (V)
I = 325; %Current (A)
n = 0.75; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%————————
a = 4.645; %Metade da largura (mm)
b = 6.5; %Penetração (mm)
C1 = 4.645;
C2 = 16;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
z1 = [-10:.2:0];
z2 = [0:.2:10];
[xx,zz] = meshgrid(x,z1);
A1 = ((6*sqrt(3)*FF*Q)/(a*b*C1*pi*sqrt(pi)));
B1 = exp(-1.7*(xx.^2/a.^2)).*exp(-5.0*(zz.^2/C1.^2));
[xa,za] = meshgrid (x,z2);
A2 = ((6*sqrt(3)*FR*Q)/(a*b*C2*pi*sqrt(pi)));
B2 = exp(-1.7*(xa.^2/a.^2)).*exp(-5.0*(za.^2/C2.^2));
q1 = A1.*B1;
q2 = A2.*B2;
[X,Z] = meshgrid (x,-15:.05:15);
mesh(xx,zz,q1);
hold on
mesh(xx,za,q2);
shading interp
colormap jet
xlabel(‘ x (mm)’)
ylabel(‘ Welding direction (mm)’)
zlabel(‘ Power Density (W/mm³)’)
<</matlabcentral/answers/uploaded_files/81300/DE.jpg>> Hello,
Is there a way to connect the mesh of these two surfaces, transforming into just one(surface)?
Thanks in advance.
clear all;
% Welding parameters
%—————————-
U = 33; %Voltage (V)
I = 325; %Current (A)
n = 0.75; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%————————
a = 4.645; %Metade da largura (mm)
b = 6.5; %Penetração (mm)
C1 = 4.645;
C2 = 16;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
z1 = [-10:.2:0];
z2 = [0:.2:10];
[xx,zz] = meshgrid(x,z1);
A1 = ((6*sqrt(3)*FF*Q)/(a*b*C1*pi*sqrt(pi)));
B1 = exp(-1.7*(xx.^2/a.^2)).*exp(-5.0*(zz.^2/C1.^2));
[xa,za] = meshgrid (x,z2);
A2 = ((6*sqrt(3)*FR*Q)/(a*b*C2*pi*sqrt(pi)));
B2 = exp(-1.7*(xa.^2/a.^2)).*exp(-5.0*(za.^2/C2.^2));
q1 = A1.*B1;
q2 = A2.*B2;
[X,Z] = meshgrid (x,-15:.05:15);
mesh(xx,zz,q1);
hold on
mesh(xx,za,q2);
shading interp
colormap jet
xlabel(‘ x (mm)’)
ylabel(‘ Welding direction (mm)’)
zlabel(‘ Power Density (W/mm³)’)
<</matlabcentral/answers/uploaded_files/81300/DE.jpg>> merge surfaces MATLAB Answers — New Questions
Problems with slrttest in the reboot
Hello, I’m trying to connect to a custom target computer via a LAN cable at MATLAB/Simulink R2017b, but when I run the srttest an error comes out:.
## Simulink Real-Time Test Suite
### Host-Target interface is: TcpIp
### Test 1, Ping target computer ‘TargetPC1’ using system ping: … OK
### Test 2, Ping target computer ‘TargetPC1’ using SLRTPINGTARGET: … OK
### Test 3, Software reboot the target computer ‘TargetPC1’: error: slrttest (line 181)
message: "The input string format is not correct."
source: "mscorlib"
181 error( booterror.message );Hello, I’m trying to connect to a custom target computer via a LAN cable at MATLAB/Simulink R2017b, but when I run the srttest an error comes out:.
## Simulink Real-Time Test Suite
### Host-Target interface is: TcpIp
### Test 1, Ping target computer ‘TargetPC1’ using system ping: … OK
### Test 2, Ping target computer ‘TargetPC1’ using SLRTPINGTARGET: … OK
### Test 3, Software reboot the target computer ‘TargetPC1’: error: slrttest (line 181)
message: "The input string format is not correct."
source: "mscorlib"
181 error( booterror.message ); Hello, I’m trying to connect to a custom target computer via a LAN cable at MATLAB/Simulink R2017b, but when I run the srttest an error comes out:.
## Simulink Real-Time Test Suite
### Host-Target interface is: TcpIp
### Test 1, Ping target computer ‘TargetPC1’ using system ping: … OK
### Test 2, Ping target computer ‘TargetPC1’ using SLRTPINGTARGET: … OK
### Test 3, Software reboot the target computer ‘TargetPC1’: error: slrttest (line 181)
message: "The input string format is not correct."
source: "mscorlib"
181 error( booterror.message ); srttest MATLAB Answers — New Questions
Recessionplot not including 2020
Dear Experts,
I am having a challenge with recessionplot. I have plotted this monthly time series data (1971M1-2021M10) and clicked ‘recessionplot’.
However, the recessionplot algorithm does not shade (grey) the COVID-19 recession (2020M02-2020M04).
How do I add the COVID-19 recession to the graph?
Thank you,
MphoDear Experts,
I am having a challenge with recessionplot. I have plotted this monthly time series data (1971M1-2021M10) and clicked ‘recessionplot’.
However, the recessionplot algorithm does not shade (grey) the COVID-19 recession (2020M02-2020M04).
How do I add the COVID-19 recession to the graph?
Thank you,
Mpho Dear Experts,
I am having a challenge with recessionplot. I have plotted this monthly time series data (1971M1-2021M10) and clicked ‘recessionplot’.
However, the recessionplot algorithm does not shade (grey) the COVID-19 recession (2020M02-2020M04).
How do I add the COVID-19 recession to the graph?
Thank you,
Mpho recessionplot MATLAB Answers — New Questions
my graph won’t show the exponential graph as the alpha value is 0, can someone help fix this problem?
%a
cockrach=importdata(‘cockroach_population.xlsx’);
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf(‘parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f’,p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf(‘exponential-cockraches rate: cockraches= %.2fe^%.2fxn’,alpha, Beta);
figure
plot(days,cockraches,’b.’);
hold on
plot(days,polyval(p,days),’r-‘,’LineWidth’,3);
plot(days,exponential_curve,’g-‘,’LineWidth’,3)
title(‘numbers of cockraches vs times(days)’);
xlabel(‘cockraches’);
ylabel(‘days’);
legend(‘unlinearised’,text1,text2)%a
cockrach=importdata(‘cockroach_population.xlsx’);
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf(‘parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f’,p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf(‘exponential-cockraches rate: cockraches= %.2fe^%.2fxn’,alpha, Beta);
figure
plot(days,cockraches,’b.’);
hold on
plot(days,polyval(p,days),’r-‘,’LineWidth’,3);
plot(days,exponential_curve,’g-‘,’LineWidth’,3)
title(‘numbers of cockraches vs times(days)’);
xlabel(‘cockraches’);
ylabel(‘days’);
legend(‘unlinearised’,text1,text2) %a
cockrach=importdata(‘cockroach_population.xlsx’);
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf(‘parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f’,p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf(‘exponential-cockraches rate: cockraches= %.2fe^%.2fxn’,alpha, Beta);
figure
plot(days,cockraches,’b.’);
hold on
plot(days,polyval(p,days),’r-‘,’LineWidth’,3);
plot(days,exponential_curve,’g-‘,’LineWidth’,3)
title(‘numbers of cockraches vs times(days)’);
xlabel(‘cockraches’);
ylabel(‘days’);
legend(‘unlinearised’,text1,text2) exponential curve, nonlinear, linear MATLAB Answers — New Questions
Get properties from Aspen Plus
Hello Matlab community,
I want to use material properties from Aspen Properties V9 to calculate some dimensionless numbers. For example I want to get out the heat capacity, thermal heat conductivity, etc. of water at different temperatures and pressures. Is this possible?
Thank you for helping an inexperienced user.Hello Matlab community,
I want to use material properties from Aspen Properties V9 to calculate some dimensionless numbers. For example I want to get out the heat capacity, thermal heat conductivity, etc. of water at different temperatures and pressures. Is this possible?
Thank you for helping an inexperienced user. Hello Matlab community,
I want to use material properties from Aspen Properties V9 to calculate some dimensionless numbers. For example I want to get out the heat capacity, thermal heat conductivity, etc. of water at different temperatures and pressures. Is this possible?
Thank you for helping an inexperienced user. aspen plus, properties MATLAB Answers — New Questions
This is face morphing. Now I want to save and convert to a gif image format.
close all
iter=10;
A=im2double(imread(‘1.JPG’));
B=im2double(imread(‘2.JPG’));
A=imresize(A, [512 512]);
B=imresize(B, [512 512]);
D=B-A;
D=D./iter;
for i=1:iter
A=A+D;
imshow(A);
pause (0.1);
endclose all
iter=10;
A=im2double(imread(‘1.JPG’));
B=im2double(imread(‘2.JPG’));
A=imresize(A, [512 512]);
B=imresize(B, [512 512]);
D=B-A;
D=D./iter;
for i=1:iter
A=A+D;
imshow(A);
pause (0.1);
end close all
iter=10;
A=im2double(imread(‘1.JPG’));
B=im2double(imread(‘2.JPG’));
A=imresize(A, [512 512]);
B=imresize(B, [512 512]);
D=B-A;
D=D./iter;
for i=1:iter
A=A+D;
imshow(A);
pause (0.1);
end image processing, morphing, morph images MATLAB Answers — New Questions
I need help validating my forward kinematic using Simulink and the Robotic Systems Toolbox for a surgical robot.
Hi all,
I am a student and I am working on a surgical eye robot which utilises a remote centre of motion mechanism (RCM). I have found the forward kinematics for it using the DH method and another method. I have also found the Jacobian velocity matrix for it. However, my Jacobian seems a bit off and I am looking to validate it and the forward kinematic using RST. I have exported the CAD model as XML and created an slx file for it. The robot composes of multiple joints. However, in reality, only 4 joints are actuation joints, the rest are closed loop joints that reduce the robots DOF to 1 or 2 DOF (pitch and translation).
I have set up the robots and actuated it fine using a constant block connected a degree to radians block which is then connected to the robot, which is connected to a MATLAB function script which is then connected to a display to show me the homogenous matrix.
I am now at the stage where I am looking to connect a GetTransform block in order to retrieve the forward kinematic. Below is the way I am connecting the blocks. My apologies since I am using a different computer and can’t screenshot my layout.
3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it’s connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope.
All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?
My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?
Thank you so much for the help in advance!Hi all,
I am a student and I am working on a surgical eye robot which utilises a remote centre of motion mechanism (RCM). I have found the forward kinematics for it using the DH method and another method. I have also found the Jacobian velocity matrix for it. However, my Jacobian seems a bit off and I am looking to validate it and the forward kinematic using RST. I have exported the CAD model as XML and created an slx file for it. The robot composes of multiple joints. However, in reality, only 4 joints are actuation joints, the rest are closed loop joints that reduce the robots DOF to 1 or 2 DOF (pitch and translation).
I have set up the robots and actuated it fine using a constant block connected a degree to radians block which is then connected to the robot, which is connected to a MATLAB function script which is then connected to a display to show me the homogenous matrix.
I am now at the stage where I am looking to connect a GetTransform block in order to retrieve the forward kinematic. Below is the way I am connecting the blocks. My apologies since I am using a different computer and can’t screenshot my layout.
3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it’s connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope.
All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?
My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?
Thank you so much for the help in advance! Hi all,
I am a student and I am working on a surgical eye robot which utilises a remote centre of motion mechanism (RCM). I have found the forward kinematics for it using the DH method and another method. I have also found the Jacobian velocity matrix for it. However, my Jacobian seems a bit off and I am looking to validate it and the forward kinematic using RST. I have exported the CAD model as XML and created an slx file for it. The robot composes of multiple joints. However, in reality, only 4 joints are actuation joints, the rest are closed loop joints that reduce the robots DOF to 1 or 2 DOF (pitch and translation).
I have set up the robots and actuated it fine using a constant block connected a degree to radians block which is then connected to the robot, which is connected to a MATLAB function script which is then connected to a display to show me the homogenous matrix.
I am now at the stage where I am looking to connect a GetTransform block in order to retrieve the forward kinematic. Below is the way I am connecting the blocks. My apologies since I am using a different computer and can’t screenshot my layout.
3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it’s connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope.
All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?
My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?
Thank you so much for the help in advance! robotic, robotic system toolbox, matlab, forward kinematic, jacobian, simulink, simscape, setup MATLAB Answers — New Questions
%I encountered the following problem in the calculation: 1. The calculated H is negative, %and I am unsure if the calculation is correct. Some formulas cannot be simplified and still %exist in the form of 5000/51166. 3. Poor overall code fluency clea
clear all
close
%% 参数定义parameter definition
P = 42;
c = 800;
E = 15000000;
K = 1.8;
P_ya = 18000;
F = 2;
y = 26.8;
R = 20; % radius
syms H B
%H=100;
% 计算破裂角 a Calculate the rupture angle
if K <= 0.5
a = 90;
elseif K <= 1
a = -90 * K + 135;
elseif K <= 3
a = -22.5 * K + 67.5;
else
a = 0;
end
% 显示计算得到的 a 的值
disp([‘当 K = ‘, num2str(K), ‘ 时,破裂角 a = ‘, num2str(a), ‘°’]);
%% 求解初始破裂角相关量 Solving the initial rupture angle related quantities
L = H + R * (1 – sind(a));
G_1 = (y * L^2) / (2 * tand(B)); % 三角形块体的自重
p = atan2(tand(P), F); % 折减后的内摩擦角
p = rad2deg(p); % 将结果转换为度,便于后面统一计算
C = c * L; % 竖直面上粘聚力合力
C_s = c * L / (F * sind(B)); % 破裂面上粘聚力合力
G_0 = 2 * y * H * cosd(a);
z = 0.9 * P; % 按照围岩等级取值,三级围岩取0.9
%% 定义目标函数 E(B) Define the objective function E (B)
%E_func = @(B) (y ./ (2 .* tand(B))) .* sind(B + p) ./ cosd(B + p – z);
E_func=@(B) (cosd(B+p).*sind(B)).*cosd(B).*cosd(B+p-z)+sind(B+p).*sind(B).*(sind(B+p-z).*cosd(B)+cosd(B+p-z).*sind(B));
%% 数值求导函数 Numerical derivative function
% 使用中心差分法计算导数
dE_func = @(B) (E_func(B + 1e-6) – E_func(B – 1e-6)) / (2e-6);
%% 数值寻找导数为零的 B 值
% 只寻找一个接近的 B 值
B_range = [0, 90]; % B 的取值范围
B_init = 45; % 初始猜测值,设置为 45 度
% 使用 fzero 寻找导数为零的 B 值
try
B_zero = fzero(dE_func, B_init);
% 检查找到的 B 值是否满足条件
if abs(dE_func(B_zero)) < 1e-6
disp([‘找到满足条件的 B 值为:’, num2str(B_zero)]);
else
disp(‘没有找到导数接近零的 B 值’);
end
catch
disp(‘fzero 计算失败,未找到满足条件的 B 值’);
end
B=B_zero
%% 计算埋深 Calculate burial depth
f1 = ((G_1 – C) .* sind(p + B_zero) + C_s .* cosd(p)) ./ cosd(B_zero + p – z);
f2 = (P_ya – G_0 – 2 .* C) / (2 * sind(z));
% 定义控制方程,解出 H
eqn = f1 – f2 == 0;
% 使用 solve 反解出 H
sol_H_sym = solve(eqn, H);
% 将符号解转换为具体的数值
sol_H_num = double(subs(sol_H_sym));
% 显示结果
disp([‘解出的 H 的值为:’, num2str(sol_H_num)]);clear all
close
%% 参数定义parameter definition
P = 42;
c = 800;
E = 15000000;
K = 1.8;
P_ya = 18000;
F = 2;
y = 26.8;
R = 20; % radius
syms H B
%H=100;
% 计算破裂角 a Calculate the rupture angle
if K <= 0.5
a = 90;
elseif K <= 1
a = -90 * K + 135;
elseif K <= 3
a = -22.5 * K + 67.5;
else
a = 0;
end
% 显示计算得到的 a 的值
disp([‘当 K = ‘, num2str(K), ‘ 时,破裂角 a = ‘, num2str(a), ‘°’]);
%% 求解初始破裂角相关量 Solving the initial rupture angle related quantities
L = H + R * (1 – sind(a));
G_1 = (y * L^2) / (2 * tand(B)); % 三角形块体的自重
p = atan2(tand(P), F); % 折减后的内摩擦角
p = rad2deg(p); % 将结果转换为度,便于后面统一计算
C = c * L; % 竖直面上粘聚力合力
C_s = c * L / (F * sind(B)); % 破裂面上粘聚力合力
G_0 = 2 * y * H * cosd(a);
z = 0.9 * P; % 按照围岩等级取值,三级围岩取0.9
%% 定义目标函数 E(B) Define the objective function E (B)
%E_func = @(B) (y ./ (2 .* tand(B))) .* sind(B + p) ./ cosd(B + p – z);
E_func=@(B) (cosd(B+p).*sind(B)).*cosd(B).*cosd(B+p-z)+sind(B+p).*sind(B).*(sind(B+p-z).*cosd(B)+cosd(B+p-z).*sind(B));
%% 数值求导函数 Numerical derivative function
% 使用中心差分法计算导数
dE_func = @(B) (E_func(B + 1e-6) – E_func(B – 1e-6)) / (2e-6);
%% 数值寻找导数为零的 B 值
% 只寻找一个接近的 B 值
B_range = [0, 90]; % B 的取值范围
B_init = 45; % 初始猜测值,设置为 45 度
% 使用 fzero 寻找导数为零的 B 值
try
B_zero = fzero(dE_func, B_init);
% 检查找到的 B 值是否满足条件
if abs(dE_func(B_zero)) < 1e-6
disp([‘找到满足条件的 B 值为:’, num2str(B_zero)]);
else
disp(‘没有找到导数接近零的 B 值’);
end
catch
disp(‘fzero 计算失败,未找到满足条件的 B 值’);
end
B=B_zero
%% 计算埋深 Calculate burial depth
f1 = ((G_1 – C) .* sind(p + B_zero) + C_s .* cosd(p)) ./ cosd(B_zero + p – z);
f2 = (P_ya – G_0 – 2 .* C) / (2 * sind(z));
% 定义控制方程,解出 H
eqn = f1 – f2 == 0;
% 使用 solve 反解出 H
sol_H_sym = solve(eqn, H);
% 将符号解转换为具体的数值
sol_H_num = double(subs(sol_H_sym));
% 显示结果
disp([‘解出的 H 的值为:’, num2str(sol_H_num)]); clear all
close
%% 参数定义parameter definition
P = 42;
c = 800;
E = 15000000;
K = 1.8;
P_ya = 18000;
F = 2;
y = 26.8;
R = 20; % radius
syms H B
%H=100;
% 计算破裂角 a Calculate the rupture angle
if K <= 0.5
a = 90;
elseif K <= 1
a = -90 * K + 135;
elseif K <= 3
a = -22.5 * K + 67.5;
else
a = 0;
end
% 显示计算得到的 a 的值
disp([‘当 K = ‘, num2str(K), ‘ 时,破裂角 a = ‘, num2str(a), ‘°’]);
%% 求解初始破裂角相关量 Solving the initial rupture angle related quantities
L = H + R * (1 – sind(a));
G_1 = (y * L^2) / (2 * tand(B)); % 三角形块体的自重
p = atan2(tand(P), F); % 折减后的内摩擦角
p = rad2deg(p); % 将结果转换为度,便于后面统一计算
C = c * L; % 竖直面上粘聚力合力
C_s = c * L / (F * sind(B)); % 破裂面上粘聚力合力
G_0 = 2 * y * H * cosd(a);
z = 0.9 * P; % 按照围岩等级取值,三级围岩取0.9
%% 定义目标函数 E(B) Define the objective function E (B)
%E_func = @(B) (y ./ (2 .* tand(B))) .* sind(B + p) ./ cosd(B + p – z);
E_func=@(B) (cosd(B+p).*sind(B)).*cosd(B).*cosd(B+p-z)+sind(B+p).*sind(B).*(sind(B+p-z).*cosd(B)+cosd(B+p-z).*sind(B));
%% 数值求导函数 Numerical derivative function
% 使用中心差分法计算导数
dE_func = @(B) (E_func(B + 1e-6) – E_func(B – 1e-6)) / (2e-6);
%% 数值寻找导数为零的 B 值
% 只寻找一个接近的 B 值
B_range = [0, 90]; % B 的取值范围
B_init = 45; % 初始猜测值,设置为 45 度
% 使用 fzero 寻找导数为零的 B 值
try
B_zero = fzero(dE_func, B_init);
% 检查找到的 B 值是否满足条件
if abs(dE_func(B_zero)) < 1e-6
disp([‘找到满足条件的 B 值为:’, num2str(B_zero)]);
else
disp(‘没有找到导数接近零的 B 值’);
end
catch
disp(‘fzero 计算失败,未找到满足条件的 B 值’);
end
B=B_zero
%% 计算埋深 Calculate burial depth
f1 = ((G_1 – C) .* sind(p + B_zero) + C_s .* cosd(p)) ./ cosd(B_zero + p – z);
f2 = (P_ya – G_0 – 2 .* C) / (2 * sind(z));
% 定义控制方程,解出 H
eqn = f1 – f2 == 0;
% 使用 solve 反解出 H
sol_H_sym = solve(eqn, H);
% 将符号解转换为具体的数值
sol_H_num = double(subs(sol_H_sym));
% 显示结果
disp([‘解出的 H 的值为:’, num2str(sol_H_num)]); transferred, syms, symbolic MATLAB Answers — New Questions
MATLAB/Simulink FPGA-In-The-Loop (FIL) Connection Issue with Zybo Z7 20
I encountered an issue when attempting to send a bitstream file to program my Zybo Z7 board using Vivado 2020.1 for an FPGA-in-loop with Simulink. Below is the error message I received:
I am aware that the Zybo board is not yet supported by MATLAB. What steps should I take to resolve this issue? Additionally, if I purchase the Arty A7-100T board (https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/?srsltid=AfmBOoqSJZFmnN32QqiorkfpDJpZGWHxxwa_fzSc0o1MpIyNG6jYYAag), will I encounter the same error?"I encountered an issue when attempting to send a bitstream file to program my Zybo Z7 board using Vivado 2020.1 for an FPGA-in-loop with Simulink. Below is the error message I received:
I am aware that the Zybo board is not yet supported by MATLAB. What steps should I take to resolve this issue? Additionally, if I purchase the Arty A7-100T board (https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/?srsltid=AfmBOoqSJZFmnN32QqiorkfpDJpZGWHxxwa_fzSc0o1MpIyNG6jYYAag), will I encounter the same error?" I encountered an issue when attempting to send a bitstream file to program my Zybo Z7 board using Vivado 2020.1 for an FPGA-in-loop with Simulink. Below is the error message I received:
I am aware that the Zybo board is not yet supported by MATLAB. What steps should I take to resolve this issue? Additionally, if I purchase the Arty A7-100T board (https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/?srsltid=AfmBOoqSJZFmnN32QqiorkfpDJpZGWHxxwa_fzSc0o1MpIyNG6jYYAag), will I encounter the same error?" zybo, fil MATLAB Answers — New Questions
how to sort dlarrays
How to sort dlarrays like in
sort(a)
, where a is a numeric array? Is there a way of sorting next(mbq) by specifying some options in the following code?
mbq = minibatchqueue(ads,MiniBatchSize=miniBatchSize,MiniBatchFormat="BC");
next(mbq)How to sort dlarrays like in
sort(a)
, where a is a numeric array? Is there a way of sorting next(mbq) by specifying some options in the following code?
mbq = minibatchqueue(ads,MiniBatchSize=miniBatchSize,MiniBatchFormat="BC");
next(mbq) How to sort dlarrays like in
sort(a)
, where a is a numeric array? Is there a way of sorting next(mbq) by specifying some options in the following code?
mbq = minibatchqueue(ads,MiniBatchSize=miniBatchSize,MiniBatchFormat="BC");
next(mbq) deep learning MATLAB Answers — New Questions
What can I do to make the output characteristic of the network is two value, that is the implement multivariate input and multivariable output
I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn)I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn) I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn) neural network, cnn, lstm, signal predict, predict MATLAB Answers — New Questions
Spectrogram output versus figure
When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks!When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks! When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks! spectrogram, spectral analysis, signal processing MATLAB Answers — New Questions
extracting overlapping portions of 2 similar tracks
hi and thanks in advance
I have cyclone tracks extracted from 2 different sources labeled as trackBom and trackRe (stored in sampleTracks.mat). I am trying to bias-correct some variables along these tracks. To do that, I need to extract the overlapping portions of the tracks. The issue is that these tracks do not exactly align in space or time. I have attached a figure showing the original tracks and the overlapping portions that I want to extract. What i want is to extract the overlapping (or almost overlapping) portions of the tracks as shown in the picture and store them as trackBomLap and trackReLap to impliment my bias correction metods.
your help is much appreciated.hi and thanks in advance
I have cyclone tracks extracted from 2 different sources labeled as trackBom and trackRe (stored in sampleTracks.mat). I am trying to bias-correct some variables along these tracks. To do that, I need to extract the overlapping portions of the tracks. The issue is that these tracks do not exactly align in space or time. I have attached a figure showing the original tracks and the overlapping portions that I want to extract. What i want is to extract the overlapping (or almost overlapping) portions of the tracks as shown in the picture and store them as trackBomLap and trackReLap to impliment my bias correction metods.
your help is much appreciated. hi and thanks in advance
I have cyclone tracks extracted from 2 different sources labeled as trackBom and trackRe (stored in sampleTracks.mat). I am trying to bias-correct some variables along these tracks. To do that, I need to extract the overlapping portions of the tracks. The issue is that these tracks do not exactly align in space or time. I have attached a figure showing the original tracks and the overlapping portions that I want to extract. What i want is to extract the overlapping (or almost overlapping) portions of the tracks as shown in the picture and store them as trackBomLap and trackReLap to impliment my bias correction metods.
your help is much appreciated. track matching MATLAB Answers — New Questions
Data is not storage when running loop
hello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met’
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, ‘.’);
but if I run my script with Data1&2 the output is different and I get less data points
I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf(‘select folder containing data filesn’);
currentpath=pwd; %%
datapath=uigetdir(”,’Select Data Folder’); %%
if (datapath == 0)
fprintf(‘Data directory was not selected…script will be terminatednn’);
return
end
prompt = ‘Do you want to export data as .xlsx?’;
save_data_excel = questdlg(prompt,’Save’,’Yes’,’No’,’Yes’);
cd(datapath); %%
files=dir(‘@*.mat’); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf(‘Progress: %d/%dnn’,i, num_files)
load(files(i,1).name)
idx = [false; diff(xzsen__ls_0_rs_) < 0];
idx1 = [false; diff(xzsen__ls_1_rs_) < 0];
idx2 = [false; diff(xzsen__ls_2_rs_) < 0];
idx3 = [false; diff(xzsen__ls_0_rs_) < 0];
idx4 = [false; diff(xzsen__ls_1_rs_) < 0];
idx5 = [false; diff(xzsen__ls_2_rs_) < 0];
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
Epm_nEngallc1_3(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j);
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
endhello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met’
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, ‘.’);
but if I run my script with Data1&2 the output is different and I get less data points
I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf(‘select folder containing data filesn’);
currentpath=pwd; %%
datapath=uigetdir(”,’Select Data Folder’); %%
if (datapath == 0)
fprintf(‘Data directory was not selected…script will be terminatednn’);
return
end
prompt = ‘Do you want to export data as .xlsx?’;
save_data_excel = questdlg(prompt,’Save’,’Yes’,’No’,’Yes’);
cd(datapath); %%
files=dir(‘@*.mat’); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf(‘Progress: %d/%dnn’,i, num_files)
load(files(i,1).name)
idx = [false; diff(xzsen__ls_0_rs_) < 0];
idx1 = [false; diff(xzsen__ls_1_rs_) < 0];
idx2 = [false; diff(xzsen__ls_2_rs_) < 0];
idx3 = [false; diff(xzsen__ls_0_rs_) < 0];
idx4 = [false; diff(xzsen__ls_1_rs_) < 0];
idx5 = [false; diff(xzsen__ls_2_rs_) < 0];
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
Epm_nEngallc1_3(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j);
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
end hello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met’
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, ‘.’);
but if I run my script with Data1&2 the output is different and I get less data points
I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf(‘select folder containing data filesn’);
currentpath=pwd; %%
datapath=uigetdir(”,’Select Data Folder’); %%
if (datapath == 0)
fprintf(‘Data directory was not selected…script will be terminatednn’);
return
end
prompt = ‘Do you want to export data as .xlsx?’;
save_data_excel = questdlg(prompt,’Save’,’Yes’,’No’,’Yes’);
cd(datapath); %%
files=dir(‘@*.mat’); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf(‘Progress: %d/%dnn’,i, num_files)
load(files(i,1).name)
idx = [false; diff(xzsen__ls_0_rs_) < 0];
idx1 = [false; diff(xzsen__ls_1_rs_) < 0];
idx2 = [false; diff(xzsen__ls_2_rs_) < 0];
idx3 = [false; diff(xzsen__ls_0_rs_) < 0];
idx4 = [false; diff(xzsen__ls_1_rs_) < 0];
idx5 = [false; diff(xzsen__ls_2_rs_) < 0];
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
Epm_nEngallc1_3(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j);
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
end loops, matlab MATLAB Answers — New Questions
Calculation of psnr value in RGB image. I have calculated psnr using this code. But the result obtained is a complex number. What should be the error??
if true
function PSNR = psnrgb(I,W)
[m,n,p] = size(I);
[h,w,q] = size(W);
if m ~= h || n ~= w || p~=q
error(‘Two images must have the same size.’)
end
for k=1:p
for i=1:m
for j=1:n
delta=sum(I(i,j,k)-W(i,j,k).^2);
end
end
end
delta = 1/(m*n*p) * delta ;
PSNR = 10 * log10( 255^2/delta );
end
endif true
function PSNR = psnrgb(I,W)
[m,n,p] = size(I);
[h,w,q] = size(W);
if m ~= h || n ~= w || p~=q
error(‘Two images must have the same size.’)
end
for k=1:p
for i=1:m
for j=1:n
delta=sum(I(i,j,k)-W(i,j,k).^2);
end
end
end
delta = 1/(m*n*p) * delta ;
PSNR = 10 * log10( 255^2/delta );
end
end if true
function PSNR = psnrgb(I,W)
[m,n,p] = size(I);
[h,w,q] = size(W);
if m ~= h || n ~= w || p~=q
error(‘Two images must have the same size.’)
end
for k=1:p
for i=1:m
for j=1:n
delta=sum(I(i,j,k)-W(i,j,k).^2);
end
end
end
delta = 1/(m*n*p) * delta ;
PSNR = 10 * log10( 255^2/delta );
end
end image processing, steganography MATLAB Answers — New Questions
Trouble Plotting Basic Function
I’m having difficulty getting a function to plot correctly in Matlab. The function is:
f(x) = x^3 – sin(x) – e^x
I’ve tried using the below but the graph is not how it should appear:
X = -4:0.01:10;
Y = X.^3 – (sin(X)) – (exp(X));
plot(X,Y)I’m having difficulty getting a function to plot correctly in Matlab. The function is:
f(x) = x^3 – sin(x) – e^x
I’ve tried using the below but the graph is not how it should appear:
X = -4:0.01:10;
Y = X.^3 – (sin(X)) – (exp(X));
plot(X,Y) I’m having difficulty getting a function to plot correctly in Matlab. The function is:
f(x) = x^3 – sin(x) – e^x
I’ve tried using the below but the graph is not how it should appear:
X = -4:0.01:10;
Y = X.^3 – (sin(X)) – (exp(X));
plot(X,Y) plot, function MATLAB Answers — New Questions
Chasing what is wrong with ‘dual-simplex-highs’ in linprog
I try to see why ‘dual-simplex-highs’ algorithm fails and ‘dual-simplex-legacy’ works OK on this specific LP problem of size 467.
The linear programming involves only linear equality constraints, and lower bounds x >= 0 on some components of x (but not all of them).
The Aeq size is 211 x 467 and the condion number is not high at all IMO (about 10). So I consider it is not a difficult problem numerically (?).
‘dual-simplex-legacy’ able to find the solution, however not the default algorithm ‘dual-simplex-highs’, the output does not help much what is wrong.
Can someone tell me where I could investigate further to the cause?
load(‘linprog_test.mat’)
size(Aeq)
cond(full(Aeq))
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-legacy’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-highs’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)I try to see why ‘dual-simplex-highs’ algorithm fails and ‘dual-simplex-legacy’ works OK on this specific LP problem of size 467.
The linear programming involves only linear equality constraints, and lower bounds x >= 0 on some components of x (but not all of them).
The Aeq size is 211 x 467 and the condion number is not high at all IMO (about 10). So I consider it is not a difficult problem numerically (?).
‘dual-simplex-legacy’ able to find the solution, however not the default algorithm ‘dual-simplex-highs’, the output does not help much what is wrong.
Can someone tell me where I could investigate further to the cause?
load(‘linprog_test.mat’)
size(Aeq)
cond(full(Aeq))
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-legacy’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-highs’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt) I try to see why ‘dual-simplex-highs’ algorithm fails and ‘dual-simplex-legacy’ works OK on this specific LP problem of size 467.
The linear programming involves only linear equality constraints, and lower bounds x >= 0 on some components of x (but not all of them).
The Aeq size is 211 x 467 and the condion number is not high at all IMO (about 10). So I consider it is not a difficult problem numerically (?).
‘dual-simplex-legacy’ able to find the solution, however not the default algorithm ‘dual-simplex-highs’, the output does not help much what is wrong.
Can someone tell me where I could investigate further to the cause?
load(‘linprog_test.mat’)
size(Aeq)
cond(full(Aeq))
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-legacy’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-highs’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt) linprog, dual-simplex-highs, failure MATLAB Answers — New Questions
Vectorizing a Simple(?) Operation
Hi all,
This might be a bit of a fruitless question but I just want to confirm there is no other method. I want to know if there is any way of vectorizing the following code:
array = [1,0,1,1,0,0,1];
for i = 2:length(array)-1
if array(i-1) ~= array(i+1)
% Generate a random bit (0 or 1)
random_bit = randi([0, 1]);
% Update the array in place
array(i) = mod(array(i) + random_bit, 2);
end
end
The array can be of any length as long as it is only fillled with 0s and 1s. The key part of the code is that I want to update the array by doing nearest neighbor checks and in such a way that the number of walls (array(i) ~= array(i+1) for i from 1 to size(array)) is constant. And it is this constrained logic of my code that leads me to believe I cannot do away with using for-loops.
The reason I wish to vectorize the code is because I will be doing monte-carlo sampling where I have a large number of these arrays and wish to update them all at the same time using the above update rule, so in the ideal scenario I wouldn’t have to use a nested for-loop to cycle through each sample.Hi all,
This might be a bit of a fruitless question but I just want to confirm there is no other method. I want to know if there is any way of vectorizing the following code:
array = [1,0,1,1,0,0,1];
for i = 2:length(array)-1
if array(i-1) ~= array(i+1)
% Generate a random bit (0 or 1)
random_bit = randi([0, 1]);
% Update the array in place
array(i) = mod(array(i) + random_bit, 2);
end
end
The array can be of any length as long as it is only fillled with 0s and 1s. The key part of the code is that I want to update the array by doing nearest neighbor checks and in such a way that the number of walls (array(i) ~= array(i+1) for i from 1 to size(array)) is constant. And it is this constrained logic of my code that leads me to believe I cannot do away with using for-loops.
The reason I wish to vectorize the code is because I will be doing monte-carlo sampling where I have a large number of these arrays and wish to update them all at the same time using the above update rule, so in the ideal scenario I wouldn’t have to use a nested for-loop to cycle through each sample. Hi all,
This might be a bit of a fruitless question but I just want to confirm there is no other method. I want to know if there is any way of vectorizing the following code:
array = [1,0,1,1,0,0,1];
for i = 2:length(array)-1
if array(i-1) ~= array(i+1)
% Generate a random bit (0 or 1)
random_bit = randi([0, 1]);
% Update the array in place
array(i) = mod(array(i) + random_bit, 2);
end
end
The array can be of any length as long as it is only fillled with 0s and 1s. The key part of the code is that I want to update the array by doing nearest neighbor checks and in such a way that the number of walls (array(i) ~= array(i+1) for i from 1 to size(array)) is constant. And it is this constrained logic of my code that leads me to believe I cannot do away with using for-loops.
The reason I wish to vectorize the code is because I will be doing monte-carlo sampling where I have a large number of these arrays and wish to update them all at the same time using the above update rule, so in the ideal scenario I wouldn’t have to use a nested for-loop to cycle through each sample. vectorization MATLAB Answers — New Questions
Why is 0.3 – 0.2 – 0.1 not equal to zero?
Why does
0.3 – 0.2 – 0.1 == 0
or
v = 0:0.1:1;
any(v == 0.3)
(or similar numbers) reply false?Why does
0.3 – 0.2 – 0.1 == 0
or
v = 0:0.1:1;
any(v == 0.3)
(or similar numbers) reply false? Why does
0.3 – 0.2 – 0.1 == 0
or
v = 0:0.1:1;
any(v == 0.3)
(or similar numbers) reply false? faqlist, floating point, limited precision, faq_fp MATLAB Answers — New Questions