Category: Matlab
Category Archives: Matlab
MATLAB third package Simulink for Arduino take too long time ?
MATLAB third package Simulink for Arduino take too long time ? what can i do ?MATLAB third package Simulink for Arduino take too long time ? what can i do ? MATLAB third package Simulink for Arduino take too long time ? what can i do ? matlab support, simulink arduino MATLAB Answers — New Questions
I want to classify linear, parabolic and exponential functions using machine learning.
I need to use machine learning for this project. 10 x and y values of the functions will be given and using these values, it will be understood whether the other functions to be written are linear parabolic or exponential functions. I need help with where to start and where to go after. Not sure what to do.I need to use machine learning for this project. 10 x and y values of the functions will be given and using these values, it will be understood whether the other functions to be written are linear parabolic or exponential functions. I need help with where to start and where to go after. Not sure what to do. I need to use machine learning for this project. 10 x and y values of the functions will be given and using these values, it will be understood whether the other functions to be written are linear parabolic or exponential functions. I need help with where to start and where to go after. Not sure what to do. machine learning MATLAB Answers — New Questions
How to calculate Bootstrap confidence interval
Hi all. I wonder how to calculate bootstrapped confidence interval for following data sent. The conventiona confidence interval is quite large and I wonder if it may make more sense with bootstrapped CIs.
x = [6 10 14 20 26 34 38];
y = [122 107 119 120 105 95 92];
I am using a*exp(-x/b) for fitting which gives a = 127, b = 130. I want to calculated the CIs for bootstrapped sample.Hi all. I wonder how to calculate bootstrapped confidence interval for following data sent. The conventiona confidence interval is quite large and I wonder if it may make more sense with bootstrapped CIs.
x = [6 10 14 20 26 34 38];
y = [122 107 119 120 105 95 92];
I am using a*exp(-x/b) for fitting which gives a = 127, b = 130. I want to calculated the CIs for bootstrapped sample. Hi all. I wonder how to calculate bootstrapped confidence interval for following data sent. The conventiona confidence interval is quite large and I wonder if it may make more sense with bootstrapped CIs.
x = [6 10 14 20 26 34 38];
y = [122 107 119 120 105 95 92];
I am using a*exp(-x/b) for fitting which gives a = 127, b = 130. I want to calculated the CIs for bootstrapped sample. confidence interval, boostrapped MATLAB Answers — New Questions
Temperature profile in a pipe flow with Matlab pdepe solver
I’m currently trying to solve the heat equation for the Ohmic heating of a pipe flow using the MATLAB pdepe solver. The problem is described in the following paper: https://doi.org/10.4236/ojmsi.2021.91002. This paper also contains the solution for the axial bulk temperature profile. Unfortunately, I don’t find the same solution, and I wonder if anyone could help me find the error.
The simplified heat equation for this case becomes:
𝜌𝐶𝑝𝑣𝑧∂𝑇∂𝑧=𝑘𝑟∂∂𝑟(𝑟∂𝑇∂𝑟)+𝑄̂.𝑄̂=𝜎𝐸2 is the heat source due to the Ohmic heating (this is also defined in the paper). 𝑣𝑧=2𝑉𝑎𝑣𝑔(1−(𝑥𝐷/2)2) is the classical solution for the axial velocity of the fluid in the pipe.
Please find the values of the constants in the code below.
The boundary conditions are:
𝑇(𝑧=0,𝑟)=40°𝐶,∂𝑇∂𝑟|𝑧,𝑟=0=0,−𝑘∂𝑇∂𝑟|𝑧,𝑟=𝐷/2=ℎ(𝑇(𝑧,𝑟=𝐷/2)−𝑇∞).
Please find my Matlab code below. Note that in order to be able to use the Matlab pdepe solver, the time argument in the solver corresponds with the axial coordinate 𝑧. Another important remark is that I want to solve it with the option 𝑚=0.
Any help/comments/remarks will be greatly appreciated. Thanks in advance!
%% Main code
m=0;
r=linspace(0,0.025,1000); % m r corresponds with x
z=linspace(0,2.5,1000); % m z corresponds with t
sol=pdepe(m,@pdex1pde,@ic1pde,@bc1pde,r,z);
u=sol(:,:,1); % u=T
% Figure I’m trying to recreate
figure
plot(z,u(:,1))
title(‘Axial bulk temperature distribution’)
xlabel(‘z’)
ylabel(‘T(z,r=0)’)
%% Functions
% Definition of the PDE
function [c,f,s]=pdex1pde(x,t,u,DuDx)
% Parameters
T_0=40; %°C
k=0.6178; % W/m*°C
rho=992.2; % kg/m^3
C_p=4182; % J/kg*°C
m=82.5/3600; % kg/s
R=25*10^(-3); % m
D=50*10^(-3); % m
A=pi*R^2; % m^2
V_gem=m/(rho*A); % kg m
k_0=0.015; % 1/°C^3 /s
elec_cond=0.998*(1+k_0*(u-T_0)); % S/m
v_z=2*V_gem*(1-(x^2/(D/2)^2)); % kg m^3 /s
Volt=2304; % V
L=2.5; % m
Q=elec_cond*(Volt/L)^2*x/k;
c=(rho*C_p*v_z*x/k);
f=x*DuDx;
s=Q;
end
% "Initial" condition
function u0=ic1pde(x)
u0=40;
end
% Boundary conditions
function [pl,ql,pr,qr]= bc1pde(xl,ul,xr,ur,t)
% Parameters
T_amb=20; % °C
T_0=40; % °C
h=10; % W/m^2*°C
k=0.6178; % W/m*°C
pl=0; % left is ul=0
ql=1; % p+qf=0
pr=h*(ur-T_amb);
qr=k/xr;
endI’m currently trying to solve the heat equation for the Ohmic heating of a pipe flow using the MATLAB pdepe solver. The problem is described in the following paper: https://doi.org/10.4236/ojmsi.2021.91002. This paper also contains the solution for the axial bulk temperature profile. Unfortunately, I don’t find the same solution, and I wonder if anyone could help me find the error.
The simplified heat equation for this case becomes:
𝜌𝐶𝑝𝑣𝑧∂𝑇∂𝑧=𝑘𝑟∂∂𝑟(𝑟∂𝑇∂𝑟)+𝑄̂.𝑄̂=𝜎𝐸2 is the heat source due to the Ohmic heating (this is also defined in the paper). 𝑣𝑧=2𝑉𝑎𝑣𝑔(1−(𝑥𝐷/2)2) is the classical solution for the axial velocity of the fluid in the pipe.
Please find the values of the constants in the code below.
The boundary conditions are:
𝑇(𝑧=0,𝑟)=40°𝐶,∂𝑇∂𝑟|𝑧,𝑟=0=0,−𝑘∂𝑇∂𝑟|𝑧,𝑟=𝐷/2=ℎ(𝑇(𝑧,𝑟=𝐷/2)−𝑇∞).
Please find my Matlab code below. Note that in order to be able to use the Matlab pdepe solver, the time argument in the solver corresponds with the axial coordinate 𝑧. Another important remark is that I want to solve it with the option 𝑚=0.
Any help/comments/remarks will be greatly appreciated. Thanks in advance!
%% Main code
m=0;
r=linspace(0,0.025,1000); % m r corresponds with x
z=linspace(0,2.5,1000); % m z corresponds with t
sol=pdepe(m,@pdex1pde,@ic1pde,@bc1pde,r,z);
u=sol(:,:,1); % u=T
% Figure I’m trying to recreate
figure
plot(z,u(:,1))
title(‘Axial bulk temperature distribution’)
xlabel(‘z’)
ylabel(‘T(z,r=0)’)
%% Functions
% Definition of the PDE
function [c,f,s]=pdex1pde(x,t,u,DuDx)
% Parameters
T_0=40; %°C
k=0.6178; % W/m*°C
rho=992.2; % kg/m^3
C_p=4182; % J/kg*°C
m=82.5/3600; % kg/s
R=25*10^(-3); % m
D=50*10^(-3); % m
A=pi*R^2; % m^2
V_gem=m/(rho*A); % kg m
k_0=0.015; % 1/°C^3 /s
elec_cond=0.998*(1+k_0*(u-T_0)); % S/m
v_z=2*V_gem*(1-(x^2/(D/2)^2)); % kg m^3 /s
Volt=2304; % V
L=2.5; % m
Q=elec_cond*(Volt/L)^2*x/k;
c=(rho*C_p*v_z*x/k);
f=x*DuDx;
s=Q;
end
% "Initial" condition
function u0=ic1pde(x)
u0=40;
end
% Boundary conditions
function [pl,ql,pr,qr]= bc1pde(xl,ul,xr,ur,t)
% Parameters
T_amb=20; % °C
T_0=40; % °C
h=10; % W/m^2*°C
k=0.6178; % W/m*°C
pl=0; % left is ul=0
ql=1; % p+qf=0
pr=h*(ur-T_amb);
qr=k/xr;
end I’m currently trying to solve the heat equation for the Ohmic heating of a pipe flow using the MATLAB pdepe solver. The problem is described in the following paper: https://doi.org/10.4236/ojmsi.2021.91002. This paper also contains the solution for the axial bulk temperature profile. Unfortunately, I don’t find the same solution, and I wonder if anyone could help me find the error.
The simplified heat equation for this case becomes:
𝜌𝐶𝑝𝑣𝑧∂𝑇∂𝑧=𝑘𝑟∂∂𝑟(𝑟∂𝑇∂𝑟)+𝑄̂.𝑄̂=𝜎𝐸2 is the heat source due to the Ohmic heating (this is also defined in the paper). 𝑣𝑧=2𝑉𝑎𝑣𝑔(1−(𝑥𝐷/2)2) is the classical solution for the axial velocity of the fluid in the pipe.
Please find the values of the constants in the code below.
The boundary conditions are:
𝑇(𝑧=0,𝑟)=40°𝐶,∂𝑇∂𝑟|𝑧,𝑟=0=0,−𝑘∂𝑇∂𝑟|𝑧,𝑟=𝐷/2=ℎ(𝑇(𝑧,𝑟=𝐷/2)−𝑇∞).
Please find my Matlab code below. Note that in order to be able to use the Matlab pdepe solver, the time argument in the solver corresponds with the axial coordinate 𝑧. Another important remark is that I want to solve it with the option 𝑚=0.
Any help/comments/remarks will be greatly appreciated. Thanks in advance!
%% Main code
m=0;
r=linspace(0,0.025,1000); % m r corresponds with x
z=linspace(0,2.5,1000); % m z corresponds with t
sol=pdepe(m,@pdex1pde,@ic1pde,@bc1pde,r,z);
u=sol(:,:,1); % u=T
% Figure I’m trying to recreate
figure
plot(z,u(:,1))
title(‘Axial bulk temperature distribution’)
xlabel(‘z’)
ylabel(‘T(z,r=0)’)
%% Functions
% Definition of the PDE
function [c,f,s]=pdex1pde(x,t,u,DuDx)
% Parameters
T_0=40; %°C
k=0.6178; % W/m*°C
rho=992.2; % kg/m^3
C_p=4182; % J/kg*°C
m=82.5/3600; % kg/s
R=25*10^(-3); % m
D=50*10^(-3); % m
A=pi*R^2; % m^2
V_gem=m/(rho*A); % kg m
k_0=0.015; % 1/°C^3 /s
elec_cond=0.998*(1+k_0*(u-T_0)); % S/m
v_z=2*V_gem*(1-(x^2/(D/2)^2)); % kg m^3 /s
Volt=2304; % V
L=2.5; % m
Q=elec_cond*(Volt/L)^2*x/k;
c=(rho*C_p*v_z*x/k);
f=x*DuDx;
s=Q;
end
% "Initial" condition
function u0=ic1pde(x)
u0=40;
end
% Boundary conditions
function [pl,ql,pr,qr]= bc1pde(xl,ul,xr,ur,t)
% Parameters
T_amb=20; % °C
T_0=40; % °C
h=10; % W/m^2*°C
k=0.6178; % W/m*°C
pl=0; % left is ul=0
ql=1; % p+qf=0
pr=h*(ur-T_amb);
qr=k/xr;
end fluid meganics, ohmic heating proces, heat transfer, pdepe solver MATLAB Answers — New Questions
How to create a surface plot having 3 vectors?
I have 3 vectors X, Y, Z and each vector is 1×200.
I need to show the relationship between them on a plot. I used "plot3" which works, but it doesn’t show the relationship that well.
So, I was wondering if there is a way to create a surface plot. I tried to do:
surf(X,Y,Z) but it does not work and Matlab wants Z to be a matrix where Z depends on X and Y which is not the case in my calculations.
So, is there a way to get a surface plot with X, Y, and Z?
P.S.: I looked at other questions like this, but I am still confused how their answers can be applied to my case.I have 3 vectors X, Y, Z and each vector is 1×200.
I need to show the relationship between them on a plot. I used "plot3" which works, but it doesn’t show the relationship that well.
So, I was wondering if there is a way to create a surface plot. I tried to do:
surf(X,Y,Z) but it does not work and Matlab wants Z to be a matrix where Z depends on X and Y which is not the case in my calculations.
So, is there a way to get a surface plot with X, Y, and Z?
P.S.: I looked at other questions like this, but I am still confused how their answers can be applied to my case. I have 3 vectors X, Y, Z and each vector is 1×200.
I need to show the relationship between them on a plot. I used "plot3" which works, but it doesn’t show the relationship that well.
So, I was wondering if there is a way to create a surface plot. I tried to do:
surf(X,Y,Z) but it does not work and Matlab wants Z to be a matrix where Z depends on X and Y which is not the case in my calculations.
So, is there a way to get a surface plot with X, Y, and Z?
P.S.: I looked at other questions like this, but I am still confused how their answers can be applied to my case. surface, plotting, 3d plots MATLAB Answers — New Questions
Converting MATLAB code to AutoCAD
I am new to MATLAB. I have been trying to convert the code to excel, so I can convert that into autocad, but nothing seems to be working. It is possible to do because I need it for school and past students have done it. This is my code:
t = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, ‘c’); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
% Creating a triangulation object
tri = delaunay(x(:), y(:)); % Triangulate the surface
% Save as an STL file
vertices = [x(:), y(:), z(:)]; % Create vertices matrix
stlwrite(tri,’flower.stl’); % Save as an STL file using triangulation objectt = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, ‘c’); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
i have since then produced the following code, but when I try to open it with excel, an error comes up.
t = linspace(0, 2*pi, 201); % 201 evenly spaced points between 0 and 2pi
r = sqrt(abs(7*sin(5*t))); % Polar coordinates
[x, y] = pol2cart(t, r); % Convert polar to Cartesian coordinates
z = 3 * (x.^2 + y.^2); % Calculate z coordinates
data = [x(:), y(:), z(:)]; % Create a matrix where each row is [x, y, z]
filename = ‘flower_data.xlsx’; % Define the filename
writematrix(data, filename); % Write data to Excel
the error is:
excel cannot open the file ‘flower_data.xlsx’ because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension matches the format of the file
can anyone please help?I am new to MATLAB. I have been trying to convert the code to excel, so I can convert that into autocad, but nothing seems to be working. It is possible to do because I need it for school and past students have done it. This is my code:
t = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, ‘c’); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
% Creating a triangulation object
tri = delaunay(x(:), y(:)); % Triangulate the surface
% Save as an STL file
vertices = [x(:), y(:), z(:)]; % Create vertices matrix
stlwrite(tri,’flower.stl’); % Save as an STL file using triangulation objectt = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, ‘c’); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
i have since then produced the following code, but when I try to open it with excel, an error comes up.
t = linspace(0, 2*pi, 201); % 201 evenly spaced points between 0 and 2pi
r = sqrt(abs(7*sin(5*t))); % Polar coordinates
[x, y] = pol2cart(t, r); % Convert polar to Cartesian coordinates
z = 3 * (x.^2 + y.^2); % Calculate z coordinates
data = [x(:), y(:), z(:)]; % Create a matrix where each row is [x, y, z]
filename = ‘flower_data.xlsx’; % Define the filename
writematrix(data, filename); % Write data to Excel
the error is:
excel cannot open the file ‘flower_data.xlsx’ because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension matches the format of the file
can anyone please help? I am new to MATLAB. I have been trying to convert the code to excel, so I can convert that into autocad, but nothing seems to be working. It is possible to do because I need it for school and past students have done it. This is my code:
t = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, ‘c’); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
% Creating a triangulation object
tri = delaunay(x(:), y(:)); % Triangulate the surface
% Save as an STL file
vertices = [x(:), y(:), z(:)]; % Create vertices matrix
stlwrite(tri,’flower.stl’); % Save as an STL file using triangulation objectt = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, ‘c’); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
i have since then produced the following code, but when I try to open it with excel, an error comes up.
t = linspace(0, 2*pi, 201); % 201 evenly spaced points between 0 and 2pi
r = sqrt(abs(7*sin(5*t))); % Polar coordinates
[x, y] = pol2cart(t, r); % Convert polar to Cartesian coordinates
z = 3 * (x.^2 + y.^2); % Calculate z coordinates
data = [x(:), y(:), z(:)]; % Create a matrix where each row is [x, y, z]
filename = ‘flower_data.xlsx’; % Define the filename
writematrix(data, filename); % Write data to Excel
the error is:
excel cannot open the file ‘flower_data.xlsx’ because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension matches the format of the file
can anyone please help? matlab, autocad, excel, convert, .xlsx MATLAB Answers — New Questions
Understanding implicit surface plot behavior
Here is some code that plots an implicit infinite, tilted cylinder.
Q=diag([0,1,1]./3^2);
axis([-5 5 -5 5 -5 5])
h1=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,’EdgeColor’,’none’,’FaceAlpha’,0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform(‘axisrotate’,[0 1 0],pi/4);
h1.Parent=hgtransform(‘Matrix’,T);
My first question is, why doesn’t the cylinder, which is infinite, extend to the axis limits?
My second question is, below is the same code again, except at the very end, we double the extent of the axes. Why does the cylinder become invisible when this is done?
figure;
axis([-5 5 -5 5 -5 5])
h2=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,’EdgeColor’,’none’,’FaceAlpha’,0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform(‘axisrotate’,[0 1 0],pi/4);
h2.Parent=hgtransform(‘Matrix’,T);
axis([-5 5 -5 5 -5 5]*2) %<—-makes the cylinder disappear!
function d=quadform(x,y,z, Q)
xyz=[x(:).’; y(:).’; z(:).’];
d=reshape( (sum((Q*xyz).*xyz)-1), size(x));
endHere is some code that plots an implicit infinite, tilted cylinder.
Q=diag([0,1,1]./3^2);
axis([-5 5 -5 5 -5 5])
h1=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,’EdgeColor’,’none’,’FaceAlpha’,0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform(‘axisrotate’,[0 1 0],pi/4);
h1.Parent=hgtransform(‘Matrix’,T);
My first question is, why doesn’t the cylinder, which is infinite, extend to the axis limits?
My second question is, below is the same code again, except at the very end, we double the extent of the axes. Why does the cylinder become invisible when this is done?
figure;
axis([-5 5 -5 5 -5 5])
h2=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,’EdgeColor’,’none’,’FaceAlpha’,0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform(‘axisrotate’,[0 1 0],pi/4);
h2.Parent=hgtransform(‘Matrix’,T);
axis([-5 5 -5 5 -5 5]*2) %<—-makes the cylinder disappear!
function d=quadform(x,y,z, Q)
xyz=[x(:).’; y(:).’; z(:).’];
d=reshape( (sum((Q*xyz).*xyz)-1), size(x));
end Here is some code that plots an implicit infinite, tilted cylinder.
Q=diag([0,1,1]./3^2);
axis([-5 5 -5 5 -5 5])
h1=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,’EdgeColor’,’none’,’FaceAlpha’,0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform(‘axisrotate’,[0 1 0],pi/4);
h1.Parent=hgtransform(‘Matrix’,T);
My first question is, why doesn’t the cylinder, which is infinite, extend to the axis limits?
My second question is, below is the same code again, except at the very end, we double the extent of the axes. Why does the cylinder become invisible when this is done?
figure;
axis([-5 5 -5 5 -5 5])
h2=fimplicit3(@(x,y,z) quadform(x,y,z,Q) ,’EdgeColor’,’none’,’FaceAlpha’,0.3);
view([-2,11])
xlabel X, ylabel Y, zlabel Z
T=makehgtform(‘axisrotate’,[0 1 0],pi/4);
h2.Parent=hgtransform(‘Matrix’,T);
axis([-5 5 -5 5 -5 5]*2) %<—-makes the cylinder disappear!
function d=quadform(x,y,z, Q)
xyz=[x(:).’; y(:).’; z(:).’];
d=reshape( (sum((Q*xyz).*xyz)-1), size(x));
end graphics, implicit surface, implicitfunctionsurface, bug? MATLAB Answers — New Questions
Display in the command window
my code looks as follows but i don’t understand why the values of x and z won’t display on the command window. The values are supposed to plot a semicircle.
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 150;
maxConstraintX = 50;
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue – radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) – startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp([‘x: ‘, num2str(x), ‘, z: ‘, num2str(z)]);
end
end
endmy code looks as follows but i don’t understand why the values of x and z won’t display on the command window. The values are supposed to plot a semicircle.
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 150;
maxConstraintX = 50;
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue – radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) – startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp([‘x: ‘, num2str(x), ‘, z: ‘, num2str(z)]);
end
end
end my code looks as follows but i don’t understand why the values of x and z won’t display on the command window. The values are supposed to plot a semicircle.
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 150;
maxConstraintX = 50;
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue – radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) – startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp([‘x: ‘, num2str(x), ‘, z: ‘, num2str(z)]);
end
end
end display MATLAB Answers — New Questions
Solving Differential Equation by Laplace Transform
Post Content Post Content laplace transform MATLAB Answers — New Questions
Roadrunner opendrive 1.4 import
When I try to load a .xodr file in Roadrunner nothing happens. I dragged my opendrive 1.4 file (generated with sumo netconvert) into the Library Browser Assets, set the projection mode to Full Projection, and set a Custom Projection (Use Tranverse Mercator), just as was shown in the tutorial video. However, when I then try to drag the file to load it nothing happens, no network spawns. How do I resolve this?When I try to load a .xodr file in Roadrunner nothing happens. I dragged my opendrive 1.4 file (generated with sumo netconvert) into the Library Browser Assets, set the projection mode to Full Projection, and set a Custom Projection (Use Tranverse Mercator), just as was shown in the tutorial video. However, when I then try to drag the file to load it nothing happens, no network spawns. How do I resolve this? When I try to load a .xodr file in Roadrunner nothing happens. I dragged my opendrive 1.4 file (generated with sumo netconvert) into the Library Browser Assets, set the projection mode to Full Projection, and set a Custom Projection (Use Tranverse Mercator), just as was shown in the tutorial video. However, when I then try to drag the file to load it nothing happens, no network spawns. How do I resolve this? roadrunner, opendrive MATLAB Answers — New Questions
Save a 3D image to TIFF
Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB’s outcome back to tiff.
I’d appreciate your help.Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB’s outcome back to tiff.
I’d appreciate your help. Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB’s outcome back to tiff.
I’d appreciate your help. image export, save to tiff, image analysis, tiff MATLAB Answers — New Questions
“Empty sym” when solving a system of linear equations with different conditions
I have a system of linear equations with several conditions describing a kinematic analysis of an automatic gearbox. The system is the following:
where all values are positive.
Then the following conditions are applied
These conditions are permanently valid. Thereafter other conditions are going to be applied according to the engaged gear. For example in fifth gear, the further conditions are:
The aim is to obtain a symblic equation expression consisting of parameters , which defines the gear ratio between the output and input. The gear ratio in 5th gear is for instance
Mathematically the system has 12 unknonws and 11 equations, so it gives exactly the expression for the ratio between the output and input as a function of parameters .
The transmission has a total of 10 gears, so it would be pretty difficult to make all manually.
My idea was creating a code as follows:
syms Z1A Z2A Z3A Z4A Z1B Z2B Z3B Z4B positive
syms w1A w2A w3A w4A …
w1B w2B w3B w4B …
w1C w2C w3C w4C i
% System of equations
eqn1 = w1A*Z1A + w1B*Z1B == w1C*(Z1A+Z1B);
eqn2 = w2A*Z2A + w2B*Z2B == w2C*(Z2A+Z2B);
eqn3 = w3A*Z3A + w3B*Z3B == w3C*(Z3A+Z3B);
eqn4 = w4A*Z4A + w4B*Z4B == w4C*(Z4A+Z4B);
% Permanently valid conditions
cond1 = w2A == w1A;
cond2 = w2B == w3A;
cond3 = w1C == w4B;
cond4 = w3B == w4A;
% Fifth gear analysis example
w1B = 0;
cond_gear5_1 = w4C == w3C;
cond_gear5_2 = w2B == w4A;
ratio = i == w4C/w4A;
Sol = solve([eqn1 eqn2 eqn3 eqn4 …
cond1 cond2 cond3 cond4 …
cond_gear5_1 cond_gear5_2 ratio], i)
I was probably too optimistic about getting the desired expression from Matlab. The problem is that I don’t know how to make it work.
Each advice is appreciated.I have a system of linear equations with several conditions describing a kinematic analysis of an automatic gearbox. The system is the following:
where all values are positive.
Then the following conditions are applied
These conditions are permanently valid. Thereafter other conditions are going to be applied according to the engaged gear. For example in fifth gear, the further conditions are:
The aim is to obtain a symblic equation expression consisting of parameters , which defines the gear ratio between the output and input. The gear ratio in 5th gear is for instance
Mathematically the system has 12 unknonws and 11 equations, so it gives exactly the expression for the ratio between the output and input as a function of parameters .
The transmission has a total of 10 gears, so it would be pretty difficult to make all manually.
My idea was creating a code as follows:
syms Z1A Z2A Z3A Z4A Z1B Z2B Z3B Z4B positive
syms w1A w2A w3A w4A …
w1B w2B w3B w4B …
w1C w2C w3C w4C i
% System of equations
eqn1 = w1A*Z1A + w1B*Z1B == w1C*(Z1A+Z1B);
eqn2 = w2A*Z2A + w2B*Z2B == w2C*(Z2A+Z2B);
eqn3 = w3A*Z3A + w3B*Z3B == w3C*(Z3A+Z3B);
eqn4 = w4A*Z4A + w4B*Z4B == w4C*(Z4A+Z4B);
% Permanently valid conditions
cond1 = w2A == w1A;
cond2 = w2B == w3A;
cond3 = w1C == w4B;
cond4 = w3B == w4A;
% Fifth gear analysis example
w1B = 0;
cond_gear5_1 = w4C == w3C;
cond_gear5_2 = w2B == w4A;
ratio = i == w4C/w4A;
Sol = solve([eqn1 eqn2 eqn3 eqn4 …
cond1 cond2 cond3 cond4 …
cond_gear5_1 cond_gear5_2 ratio], i)
I was probably too optimistic about getting the desired expression from Matlab. The problem is that I don’t know how to make it work.
Each advice is appreciated. I have a system of linear equations with several conditions describing a kinematic analysis of an automatic gearbox. The system is the following:
where all values are positive.
Then the following conditions are applied
These conditions are permanently valid. Thereafter other conditions are going to be applied according to the engaged gear. For example in fifth gear, the further conditions are:
The aim is to obtain a symblic equation expression consisting of parameters , which defines the gear ratio between the output and input. The gear ratio in 5th gear is for instance
Mathematically the system has 12 unknonws and 11 equations, so it gives exactly the expression for the ratio between the output and input as a function of parameters .
The transmission has a total of 10 gears, so it would be pretty difficult to make all manually.
My idea was creating a code as follows:
syms Z1A Z2A Z3A Z4A Z1B Z2B Z3B Z4B positive
syms w1A w2A w3A w4A …
w1B w2B w3B w4B …
w1C w2C w3C w4C i
% System of equations
eqn1 = w1A*Z1A + w1B*Z1B == w1C*(Z1A+Z1B);
eqn2 = w2A*Z2A + w2B*Z2B == w2C*(Z2A+Z2B);
eqn3 = w3A*Z3A + w3B*Z3B == w3C*(Z3A+Z3B);
eqn4 = w4A*Z4A + w4B*Z4B == w4C*(Z4A+Z4B);
% Permanently valid conditions
cond1 = w2A == w1A;
cond2 = w2B == w3A;
cond3 = w1C == w4B;
cond4 = w3B == w4A;
% Fifth gear analysis example
w1B = 0;
cond_gear5_1 = w4C == w3C;
cond_gear5_2 = w2B == w4A;
ratio = i == w4C/w4A;
Sol = solve([eqn1 eqn2 eqn3 eqn4 …
cond1 cond2 cond3 cond4 …
cond_gear5_1 cond_gear5_2 ratio], i)
I was probably too optimistic about getting the desired expression from Matlab. The problem is that I don’t know how to make it work.
Each advice is appreciated. symbolic, solve, system of equations MATLAB Answers — New Questions
Passing additional minibatchable quantities to a trainnet() loss function
I am calling trainnet() with the syntax,
netTrained = trainnet(cds,net,lossFcn,options)
where lossFcn=f(Y,T) is a handle to a custom loss function. Here the variable Y is the network prediction based on input X and T is the training target. Both Y and T are S1xS2xC images. During training, the usual operation of trainnet() is to fetch minibatched pairs (X,T) pointed to by the CombinedDataStore cds and to give the pairs (Y(X),T) to the lossFcn.
I would now like to modify the training to have a loss function of the form lossFcn=f(Y,T,W) where W is an additional minibatchable data set of the same dimensions as Y and T containing constant weights. My question is if there is a way to combine 3 datastores instead of 2 datastores to make this happen. In other words, instead of cds reading in minibatched pairs (X,T), is it possible to have it read in minibatched triplets (X,T,W)? Moreover, will trainnet() know the role of each of member of the triplet, i.e., that X are the network inputs and that (T,W) are ‘other stuff’? Or how am I meant to communicate this?I am calling trainnet() with the syntax,
netTrained = trainnet(cds,net,lossFcn,options)
where lossFcn=f(Y,T) is a handle to a custom loss function. Here the variable Y is the network prediction based on input X and T is the training target. Both Y and T are S1xS2xC images. During training, the usual operation of trainnet() is to fetch minibatched pairs (X,T) pointed to by the CombinedDataStore cds and to give the pairs (Y(X),T) to the lossFcn.
I would now like to modify the training to have a loss function of the form lossFcn=f(Y,T,W) where W is an additional minibatchable data set of the same dimensions as Y and T containing constant weights. My question is if there is a way to combine 3 datastores instead of 2 datastores to make this happen. In other words, instead of cds reading in minibatched pairs (X,T), is it possible to have it read in minibatched triplets (X,T,W)? Moreover, will trainnet() know the role of each of member of the triplet, i.e., that X are the network inputs and that (T,W) are ‘other stuff’? Or how am I meant to communicate this? I am calling trainnet() with the syntax,
netTrained = trainnet(cds,net,lossFcn,options)
where lossFcn=f(Y,T) is a handle to a custom loss function. Here the variable Y is the network prediction based on input X and T is the training target. Both Y and T are S1xS2xC images. During training, the usual operation of trainnet() is to fetch minibatched pairs (X,T) pointed to by the CombinedDataStore cds and to give the pairs (Y(X),T) to the lossFcn.
I would now like to modify the training to have a loss function of the form lossFcn=f(Y,T,W) where W is an additional minibatchable data set of the same dimensions as Y and T containing constant weights. My question is if there is a way to combine 3 datastores instead of 2 datastores to make this happen. In other words, instead of cds reading in minibatched pairs (X,T), is it possible to have it read in minibatched triplets (X,T,W)? Moreover, will trainnet() know the role of each of member of the triplet, i.e., that X are the network inputs and that (T,W) are ‘other stuff’? Or how am I meant to communicate this? trainnet, datastore, minibatch, deep learning, ai MATLAB Answers — New Questions
Convert 0×1 empty double column vector to zero
I am running a code and some of the parameters are 0×1 empty double column vector. Is there any way to convert these to zero?
I mean isntead of daying empty double, assign zero.I am running a code and some of the parameters are 0×1 empty double column vector. Is there any way to convert these to zero?
I mean isntead of daying empty double, assign zero. I am running a code and some of the parameters are 0×1 empty double column vector. Is there any way to convert these to zero?
I mean isntead of daying empty double, assign zero. double, vector MATLAB Answers — New Questions
Using ’tiledlayout’, is it possible to incorporate a zoomed-in section of the main plot within the main plot itself for each tile?
Hi, I created 3 main plots (black square) using ’tiledlayout’, and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like.Hi, I created 3 main plots (black square) using ’tiledlayout’, and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like. Hi, I created 3 main plots (black square) using ’tiledlayout’, and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like. matlab, tiledlayout MATLAB Answers — New Questions
Can I update my Matlab behavior
Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = ‘thisisapath’; % This is a random string
examplepath = [‘thisisa…’ …
‘path’]; % this is the same string if I write three dots "…" somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = [‘thisisa’, …
‘path’];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don’t have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks!Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = ‘thisisapath’; % This is a random string
examplepath = [‘thisisa…’ …
‘path’]; % this is the same string if I write three dots "…" somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = [‘thisisa’, …
‘path’];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don’t have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks! Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = ‘thisisapath’; % This is a random string
examplepath = [‘thisisa…’ …
‘path’]; % this is the same string if I write three dots "…" somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = [‘thisisa’, …
‘path’];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don’t have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks! behavior MATLAB Answers — New Questions
Replace certain columns in a structure array
Hi. I have a structure array, Data, of size (1 x120). The 5th column of the field Data.Temp contains zeroes. I want to replace these zeroes with a number 20 from Data(30).Temp to Data(60).Temp. Also, I want to replace these zeroes from Data(61).Temp to Data(80).Temp with a number 24. I am unable to perform this operation. I kindly request some help from the community.Hi. I have a structure array, Data, of size (1 x120). The 5th column of the field Data.Temp contains zeroes. I want to replace these zeroes with a number 20 from Data(30).Temp to Data(60).Temp. Also, I want to replace these zeroes from Data(61).Temp to Data(80).Temp with a number 24. I am unable to perform this operation. I kindly request some help from the community. Hi. I have a structure array, Data, of size (1 x120). The 5th column of the field Data.Temp contains zeroes. I want to replace these zeroes with a number 20 from Data(30).Temp to Data(60).Temp. Also, I want to replace these zeroes from Data(61).Temp to Data(80).Temp with a number 24. I am unable to perform this operation. I kindly request some help from the community. structure array, array, cell MATLAB Answers — New Questions
Get coordinates of points from an image
Hello,
I would like to know how to obtain the coordinates of p number of random points from an image:
how to call an image ( do i have to specify the path of the folder and how?)
How to obtain the data of x axix and y axis corresponding to it
Shall i use the function getimage?
Thank youHello,
I would like to know how to obtain the coordinates of p number of random points from an image:
how to call an image ( do i have to specify the path of the folder and how?)
How to obtain the data of x axix and y axis corresponding to it
Shall i use the function getimage?
Thank you Hello,
I would like to know how to obtain the coordinates of p number of random points from an image:
how to call an image ( do i have to specify the path of the folder and how?)
How to obtain the data of x axix and y axis corresponding to it
Shall i use the function getimage?
Thank you getimage, coordinates, image, data MATLAB Answers — New Questions
how to remove areas of an image containing a single color?
I have a video that I saved each frame from. The entire video has static text in big white font and it doesnt move so each frame looks very similar. Each frame also has a black background like I want to remove. Is there a way for me to remove any pixle that is (0,0,0) or (1, 1, 1) RGB? Thanks!
heres an example image that I want to crop. I want to crop all of the black and all of the white.I have a video that I saved each frame from. The entire video has static text in big white font and it doesnt move so each frame looks very similar. Each frame also has a black background like I want to remove. Is there a way for me to remove any pixle that is (0,0,0) or (1, 1, 1) RGB? Thanks!
heres an example image that I want to crop. I want to crop all of the black and all of the white. I have a video that I saved each frame from. The entire video has static text in big white font and it doesnt move so each frame looks very similar. Each frame also has a black background like I want to remove. Is there a way for me to remove any pixle that is (0,0,0) or (1, 1, 1) RGB? Thanks!
heres an example image that I want to crop. I want to crop all of the black and all of the white. image processing MATLAB Answers — New Questions
Programmatically Disable a Toolbox
I have an external toolbox (created by me) and I want to disable it (not uninstall it), do some stuff, and then re-enable it.
I have looked through the available methods in matlab.addons.toolbox, but I only see options for installing and uninstalling.
Looking at other ideas, removing the paths would be a way to disable the toolbox, but how do I know (programatically) what paths to remove? Looking in the Add-Ons explorer I can see the paths associated with the toolbox and I have an option to diasble it, but I can’t get either of those through the matlab.addons.toolbox API.
I think I either need a way to get the paths for the toolbox, or I need a method that allows me to disable it.
Am I missing something that exists today to do this?I have an external toolbox (created by me) and I want to disable it (not uninstall it), do some stuff, and then re-enable it.
I have looked through the available methods in matlab.addons.toolbox, but I only see options for installing and uninstalling.
Looking at other ideas, removing the paths would be a way to disable the toolbox, but how do I know (programatically) what paths to remove? Looking in the Add-Ons explorer I can see the paths associated with the toolbox and I have an option to diasble it, but I can’t get either of those through the matlab.addons.toolbox API.
I think I either need a way to get the paths for the toolbox, or I need a method that allows me to disable it.
Am I missing something that exists today to do this? I have an external toolbox (created by me) and I want to disable it (not uninstall it), do some stuff, and then re-enable it.
I have looked through the available methods in matlab.addons.toolbox, but I only see options for installing and uninstalling.
Looking at other ideas, removing the paths would be a way to disable the toolbox, but how do I know (programatically) what paths to remove? Looking in the Add-Ons explorer I can see the paths associated with the toolbox and I have an option to diasble it, but I can’t get either of those through the matlab.addons.toolbox API.
I think I either need a way to get the paths for the toolbox, or I need a method that allows me to disable it.
Am I missing something that exists today to do this? toolbox, disable, toolbox paths MATLAB Answers — New Questions