Category: Matlab
Category Archives: Matlab
Constraints to a Second Order Curve Fit
Given this set of data, is it possible to perform a 2nd order curve fit with the set constraint that the leading coefficient must be positive? Using an unconstrained curve fit (both "polyfit" and "fit" were used), the data produces a curve with a rather small negative leading coefficient. For reference, the data is as follows:
x = 150, 190, 400, 330, 115, 494
y = 1537, 1784, 3438, 2943, 1175, 4203
The given outputs using both methods largely agreed, as shown below:
fit_eq =
-0.0007 8.3119 255.8074
eq =
Linear model Poly2:
eq(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = -0.0007088 (-0.003588, 0.00217)
p2 = 8.312 (6.51, 10.11)
p3 = 255.8 (25.01, 486.6)Given this set of data, is it possible to perform a 2nd order curve fit with the set constraint that the leading coefficient must be positive? Using an unconstrained curve fit (both "polyfit" and "fit" were used), the data produces a curve with a rather small negative leading coefficient. For reference, the data is as follows:
x = 150, 190, 400, 330, 115, 494
y = 1537, 1784, 3438, 2943, 1175, 4203
The given outputs using both methods largely agreed, as shown below:
fit_eq =
-0.0007 8.3119 255.8074
eq =
Linear model Poly2:
eq(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = -0.0007088 (-0.003588, 0.00217)
p2 = 8.312 (6.51, 10.11)
p3 = 255.8 (25.01, 486.6) Given this set of data, is it possible to perform a 2nd order curve fit with the set constraint that the leading coefficient must be positive? Using an unconstrained curve fit (both "polyfit" and "fit" were used), the data produces a curve with a rather small negative leading coefficient. For reference, the data is as follows:
x = 150, 190, 400, 330, 115, 494
y = 1537, 1784, 3438, 2943, 1175, 4203
The given outputs using both methods largely agreed, as shown below:
fit_eq =
-0.0007 8.3119 255.8074
eq =
Linear model Poly2:
eq(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = -0.0007088 (-0.003588, 0.00217)
p2 = 8.312 (6.51, 10.11)
p3 = 255.8 (25.01, 486.6) curve fitting, matlab, polyfit MATLAB Answers — New Questions
S curve ramp function
I need help creating a function for an s curve ramp. The code below will create the inserted picture below. However, this code only works for a constant ramp block (connected to x). This code from the piecewise function on the Matlab smf() help file page.
I need two additional inputs (acceleration rate and jerk rate). The output should ramp the input velocity (x) signal based on the acceleration rate (a), and jerk rate (j). I need the block or code to be dynamic. I do not want to put a time value inside of my code. I will be exporting the code to structure text and input the code into a Siemens PLC.
I don’t want to include a fixed dt in my code because I will be running the code in a PLC. Maybe it would be better to design this function in simulink and set a fixed time solver and use integrator blocks?
x = 0:0.01:10; % domain
a = 1; % unsaturated interval’s left endpoint
b = 8; % unsaturated interval’s right endpoint
y = smf(x, a, b);
plot(x, y), grid on
xline(a, ‘–‘)
xline(b, ‘–‘)
title("S-curve piecewise function")
xlabel("x")
ylabel("Amplitude")
ylim([-0.05 1.05])
%% S-curve piecewise function
function y = smf(x, a, b)
m = (a + b)/2;
y = (x > a & x <= m) .* ( 2*((x-a)/(b-a)).^2) + …
(x > m & x <= b) .* (1-2*((x-b)/(b-a)).^2) + …
(x > b);
endI need help creating a function for an s curve ramp. The code below will create the inserted picture below. However, this code only works for a constant ramp block (connected to x). This code from the piecewise function on the Matlab smf() help file page.
I need two additional inputs (acceleration rate and jerk rate). The output should ramp the input velocity (x) signal based on the acceleration rate (a), and jerk rate (j). I need the block or code to be dynamic. I do not want to put a time value inside of my code. I will be exporting the code to structure text and input the code into a Siemens PLC.
I don’t want to include a fixed dt in my code because I will be running the code in a PLC. Maybe it would be better to design this function in simulink and set a fixed time solver and use integrator blocks?
x = 0:0.01:10; % domain
a = 1; % unsaturated interval’s left endpoint
b = 8; % unsaturated interval’s right endpoint
y = smf(x, a, b);
plot(x, y), grid on
xline(a, ‘–‘)
xline(b, ‘–‘)
title("S-curve piecewise function")
xlabel("x")
ylabel("Amplitude")
ylim([-0.05 1.05])
%% S-curve piecewise function
function y = smf(x, a, b)
m = (a + b)/2;
y = (x > a & x <= m) .* ( 2*((x-a)/(b-a)).^2) + …
(x > m & x <= b) .* (1-2*((x-b)/(b-a)).^2) + …
(x > b);
end I need help creating a function for an s curve ramp. The code below will create the inserted picture below. However, this code only works for a constant ramp block (connected to x). This code from the piecewise function on the Matlab smf() help file page.
I need two additional inputs (acceleration rate and jerk rate). The output should ramp the input velocity (x) signal based on the acceleration rate (a), and jerk rate (j). I need the block or code to be dynamic. I do not want to put a time value inside of my code. I will be exporting the code to structure text and input the code into a Siemens PLC.
I don’t want to include a fixed dt in my code because I will be running the code in a PLC. Maybe it would be better to design this function in simulink and set a fixed time solver and use integrator blocks?
x = 0:0.01:10; % domain
a = 1; % unsaturated interval’s left endpoint
b = 8; % unsaturated interval’s right endpoint
y = smf(x, a, b);
plot(x, y), grid on
xline(a, ‘–‘)
xline(b, ‘–‘)
title("S-curve piecewise function")
xlabel("x")
ylabel("Amplitude")
ylim([-0.05 1.05])
%% S-curve piecewise function
function y = smf(x, a, b)
m = (a + b)/2;
y = (x > a & x <= m) .* ( 2*((x-a)/(b-a)).^2) + …
(x > m & x <= b) .* (1-2*((x-b)/(b-a)).^2) + …
(x > b);
end s curve MATLAB Answers — New Questions
How to create excel sheet for developed model using MATLAB
I have subsystem which is having few input/output. I want to do testing using excel sheet.
How to create excel using script which generate input and output inside excel.
or any other way to test the model.
Please let me know the solutionI have subsystem which is having few input/output. I want to do testing using excel sheet.
How to create excel using script which generate input and output inside excel.
or any other way to test the model.
Please let me know the solution I have subsystem which is having few input/output. I want to do testing using excel sheet.
How to create excel using script which generate input and output inside excel.
or any other way to test the model.
Please let me know the solution importing excel data, testing, mil, matlab MATLAB Answers — New Questions
How to express constants of integral
Hi everyone,
I am a matlab beginner. How can I find the constants of integral C1 and C2 ?
For example i know that, how can i find constants of integral C1 and C2 in this script? Thanks 🙂
syms x
y1 = exp(-2*x+sqrt(6)*x);
y2 = exp(-2*x-sqrt(6)*x);
g = 2*x^2-3*x+6;
A = [y1 y2;diff(y1,x) diff(y2,x)]
b = [0; g]
Ab
u = simplify(Ab)
u = int(u,x)
simplify(u)Hi everyone,
I am a matlab beginner. How can I find the constants of integral C1 and C2 ?
For example i know that, how can i find constants of integral C1 and C2 in this script? Thanks 🙂
syms x
y1 = exp(-2*x+sqrt(6)*x);
y2 = exp(-2*x-sqrt(6)*x);
g = 2*x^2-3*x+6;
A = [y1 y2;diff(y1,x) diff(y2,x)]
b = [0; g]
Ab
u = simplify(Ab)
u = int(u,x)
simplify(u) Hi everyone,
I am a matlab beginner. How can I find the constants of integral C1 and C2 ?
For example i know that, how can i find constants of integral C1 and C2 in this script? Thanks 🙂
syms x
y1 = exp(-2*x+sqrt(6)*x);
y2 = exp(-2*x-sqrt(6)*x);
g = 2*x^2-3*x+6;
A = [y1 y2;diff(y1,x) diff(y2,x)]
b = [0; g]
Ab
u = simplify(Ab)
u = int(u,x)
simplify(u) integral, constants of integral MATLAB Answers — New Questions
2019b download installer
I need to download 2019 version of Matlab for my macbook pro 10.13.6. How can I download it. ThanksI need to download 2019 version of Matlab for my macbook pro 10.13.6. How can I download it. Thanks I need to download 2019 version of Matlab for my macbook pro 10.13.6. How can I download it. Thanks matlab MATLAB Answers — New Questions
I want to build a double pendulum system in Simulink but am getting errors relating to the tolerance and step size
How do I solve this coupled second order differential equation.
Errors:
Right now it uses ode45 to solve it but I have tried every model, added the memory block, changed the initial conditions to be smaller, changed the max step size and relative errors but nothing works.How do I solve this coupled second order differential equation.
Errors:
Right now it uses ode45 to solve it but I have tried every model, added the memory block, changed the initial conditions to be smaller, changed the max step size and relative errors but nothing works. How do I solve this coupled second order differential equation.
Errors:
Right now it uses ode45 to solve it but I have tried every model, added the memory block, changed the initial conditions to be smaller, changed the max step size and relative errors but nothing works. stepsize, ode45, ode, differential equations, simulink, matlab MATLAB Answers — New Questions
How to model a simple brake in Simscape (mechanical rotational domain)?
Hello, I am currently trying to model a simple brake in Simscape in the mechanical rotational domain.
The input to the block should be pressure.
The braking torque should increase linearly between the following points:0 bar = 0 Nm1 bar = 10 Nm
Is such a block available in the foundation library?
Would it be possible to implement such a component as a custom Simscape component?Hello, I am currently trying to model a simple brake in Simscape in the mechanical rotational domain.
The input to the block should be pressure.
The braking torque should increase linearly between the following points:0 bar = 0 Nm1 bar = 10 Nm
Is such a block available in the foundation library?
Would it be possible to implement such a component as a custom Simscape component? Hello, I am currently trying to model a simple brake in Simscape in the mechanical rotational domain.
The input to the block should be pressure.
The braking torque should increase linearly between the following points:0 bar = 0 Nm1 bar = 10 Nm
Is such a block available in the foundation library?
Would it be possible to implement such a component as a custom Simscape component? MATLAB Answers — New Questions
How to debug C# .NET assembly called from MATLAB?
I’m trying to use some .NET assemblies from MATLAB but I am encountering a MATLAB System Error.
I was wondering if there is some additional debug logs I can turn on to see the details of the system error to determine what in my .NET assembly might be causing the crash.I’m trying to use some .NET assemblies from MATLAB but I am encountering a MATLAB System Error.
I was wondering if there is some additional debug logs I can turn on to see the details of the system error to determine what in my .NET assembly might be causing the crash. I’m trying to use some .NET assemblies from MATLAB but I am encountering a MATLAB System Error.
I was wondering if there is some additional debug logs I can turn on to see the details of the system error to determine what in my .NET assembly might be causing the crash. MATLAB Answers — New Questions
How do I set the size of a tile from tiledlayout?
I am producing a number of figures with a different number of tiles from tiledlayout. I’d like to make sure all tiles are the same size across the figures. I have only found options to set the figure size. This is problematic since I have to change the figure size every time the number of tiles changes.I am producing a number of figures with a different number of tiles from tiledlayout. I’d like to make sure all tiles are the same size across the figures. I have only found options to set the figure size. This is problematic since I have to change the figure size every time the number of tiles changes. I am producing a number of figures with a different number of tiles from tiledlayout. I’d like to make sure all tiles are the same size across the figures. I have only found options to set the figure size. This is problematic since I have to change the figure size every time the number of tiles changes. tiledlayout, plotting MATLAB Answers — New Questions
Communicate with worker through client
Hello!
I have an app (app designer/GUIDE) which calls a function that looks something like this
function func()
spmd
switch labindex
case 1
while (true)
% some code…
end
case 2
while (true)
% some code…
end
end
end
end
and I would like to be able to break out of the while loop for each workers of the spmd with a click of a button in the app, which means I have to send data from the client to the workers.
I know I can easily send data from the workers to the client, but I’m not sure about the reverse direction.
Please help, thanks!Hello!
I have an app (app designer/GUIDE) which calls a function that looks something like this
function func()
spmd
switch labindex
case 1
while (true)
% some code…
end
case 2
while (true)
% some code…
end
end
end
end
and I would like to be able to break out of the while loop for each workers of the spmd with a click of a button in the app, which means I have to send data from the client to the workers.
I know I can easily send data from the workers to the client, but I’m not sure about the reverse direction.
Please help, thanks! Hello!
I have an app (app designer/GUIDE) which calls a function that looks something like this
function func()
spmd
switch labindex
case 1
while (true)
% some code…
end
case 2
while (true)
% some code…
end
end
end
end
and I would like to be able to break out of the while loop for each workers of the spmd with a click of a button in the app, which means I have to send data from the client to the workers.
I know I can easily send data from the workers to the client, but I’m not sure about the reverse direction.
Please help, thanks! spmd, worker, parallel computing, app designer, guide, dataqueue MATLAB Answers — New Questions
Find Gaps and Overlaps in Rectangular Prisms
I have rectangular prisms at fixed locations defined below, and I’m trying to see if they fit in a box without any gaps or overlaps. The perfect no-gaps, no-overlaps solution looks like the picture of the attached Jenga tower.
% Fit the following rectangular prisms in a box:
prisms.p1.x = [75 200]; % Min/max of x range for prism p1
prisms.p1.y = [4 100]; % Min/max of y range for prism p1
prisms.p1.z = [1e3 1e4]; % Min/max of z range for prism p1
prisms.p2.x = [20 80];
prisms.p2.y = [0.1 2.2];
prisms.p2.z = [0 1e3];
prisms.p3.x = [80 115];
prisms.p3.y = [0.1 4];
prisms.p3.z = [0 1e3];
prisms.p4.x = [20 180];
prisms.p4.y = [2.2 8];
prisms.p4.z = [0 1e3];
prisms.p5.x = [200 1000];
prisms.p5.y = [0 1];
prisms.p5.z = [0 1e4];
% The box that the prisms must fit in, given the values above, is:
box.x = [20 1000]; % Min/max of x range for the box of prisms
box.y = [0 100]; % Min/max of x range for the box of prisms
box.z = [0 1e4]; % Min/max of x range for the box of prisms
Above is a struct called prisms. It has 5 fields; each field describes one prism (p1,p2,p3,p4,p5) using x,y,z coordinates. I want to identify if the rectangular prisms have any overlaps or gaps between them, and if so, report where those gaps and/or overlaps occur. The ranges are all aligned with the axes, and are always >=0.
The size of the box that the prisms must fit in is defined to be the min and max values over all prisms for a particular axis. If two prisms touch at only one point in their range, I don’t count that as an "overlap". I don’t want to move the prisms, but instead want to report where two prisms overlap, or where there are gaps in the box.
I’ve found all the overlapping regions by testing pairs of rectangular prisms for overlap, and it seems to work:
%% Get all combinations of classes (combinations since order does not matter)
nFields = length(fieldnames(prisms));
combos = nchoosek(1:nFields,2);
nCombos = nchoosek(nFields,2);
% Index the struct by index instead of field name
fns = fieldnames(prisms);
%% Check for overlap between each pair of classes
for ic = 1:nCombos
x11 = prisms.(fns{combos(ic,1)}).x(1);
x12 = prisms.(fns{combos(ic,1)}).x(2);
y11 = prisms.(fns{combos(ic,1)}).y(1);
y12 = prisms.(fns{combos(ic,1)}).y(2);
z11 = prisms.(fns{combos(ic,1)}).z(1);
z12 = prisms.(fns{combos(ic,1)}).z(2);
x21 = prisms.(fns{combos(ic,2)}).x(1);
x22 = prisms.(fns{combos(ic,2)}).x(2);
y21 = prisms.(fns{combos(ic,2)}).y(1);
y22 = prisms.(fns{combos(ic,2)}).y(2);
z21 = prisms.(fns{combos(ic,2)}).z(1);
z22 = prisms.(fns{combos(ic,2)}).z(2);
if( (x12>x21 && y12>y21 && z12>z21) || (x21>x12 && y21>y12 && z21>z12) )
% There is either overlap, or the edge of classes align
% Check for overlap in x
if( ((x12>=x21) && (x11<=x22)) || ((x11<=x22) && (x21<=x21)) )
if((x21==x12) || (x11==x22))
continue;
else
fprintf(‘Overlap in x between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s x: [%g %g]n’, fns{combos(ic,1)}, x11, x12);
fprintf(‘ Limits for %s x: [%g %g]n’, fns{combos(ic,2)}, x21, x22);
end
end
% Check for overlap in y
if( ((y12>=y21) && (y11<=y22)) || ((y11<=y22) && (y21<=y21)) )
if((y21==y12) || (y11==y22))
continue;
else
fprintf(‘Overlap in y between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s y: [%g %g]n’, fns{combos(ic,1)}, y11, y12);
fprintf(‘ Limits for %s y: [%g %g]n’, fns{combos(ic,2)}, y21, y22);
end
end
% Check for overlap in z
if( ((z12>=z21) && (z11<=z22)) || ((z11<=z22) && (z21<=z21)) )
if((z21==z12) || (z11==z22))
continue;
else
fprintf(‘Overlap in z between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s z: [%g %g]n’, fns{combos(ic,1)}, z11, z12);
fprintf(‘ Limits for %s z: [%g %g]n’, fns{combos(ic,2)}, z21, z22);
end
end
end
end
I just can’t get the last part which will identify where the gaps happen. I think I can modify the above code to push this function across the finish line, but I need some help.I have rectangular prisms at fixed locations defined below, and I’m trying to see if they fit in a box without any gaps or overlaps. The perfect no-gaps, no-overlaps solution looks like the picture of the attached Jenga tower.
% Fit the following rectangular prisms in a box:
prisms.p1.x = [75 200]; % Min/max of x range for prism p1
prisms.p1.y = [4 100]; % Min/max of y range for prism p1
prisms.p1.z = [1e3 1e4]; % Min/max of z range for prism p1
prisms.p2.x = [20 80];
prisms.p2.y = [0.1 2.2];
prisms.p2.z = [0 1e3];
prisms.p3.x = [80 115];
prisms.p3.y = [0.1 4];
prisms.p3.z = [0 1e3];
prisms.p4.x = [20 180];
prisms.p4.y = [2.2 8];
prisms.p4.z = [0 1e3];
prisms.p5.x = [200 1000];
prisms.p5.y = [0 1];
prisms.p5.z = [0 1e4];
% The box that the prisms must fit in, given the values above, is:
box.x = [20 1000]; % Min/max of x range for the box of prisms
box.y = [0 100]; % Min/max of x range for the box of prisms
box.z = [0 1e4]; % Min/max of x range for the box of prisms
Above is a struct called prisms. It has 5 fields; each field describes one prism (p1,p2,p3,p4,p5) using x,y,z coordinates. I want to identify if the rectangular prisms have any overlaps or gaps between them, and if so, report where those gaps and/or overlaps occur. The ranges are all aligned with the axes, and are always >=0.
The size of the box that the prisms must fit in is defined to be the min and max values over all prisms for a particular axis. If two prisms touch at only one point in their range, I don’t count that as an "overlap". I don’t want to move the prisms, but instead want to report where two prisms overlap, or where there are gaps in the box.
I’ve found all the overlapping regions by testing pairs of rectangular prisms for overlap, and it seems to work:
%% Get all combinations of classes (combinations since order does not matter)
nFields = length(fieldnames(prisms));
combos = nchoosek(1:nFields,2);
nCombos = nchoosek(nFields,2);
% Index the struct by index instead of field name
fns = fieldnames(prisms);
%% Check for overlap between each pair of classes
for ic = 1:nCombos
x11 = prisms.(fns{combos(ic,1)}).x(1);
x12 = prisms.(fns{combos(ic,1)}).x(2);
y11 = prisms.(fns{combos(ic,1)}).y(1);
y12 = prisms.(fns{combos(ic,1)}).y(2);
z11 = prisms.(fns{combos(ic,1)}).z(1);
z12 = prisms.(fns{combos(ic,1)}).z(2);
x21 = prisms.(fns{combos(ic,2)}).x(1);
x22 = prisms.(fns{combos(ic,2)}).x(2);
y21 = prisms.(fns{combos(ic,2)}).y(1);
y22 = prisms.(fns{combos(ic,2)}).y(2);
z21 = prisms.(fns{combos(ic,2)}).z(1);
z22 = prisms.(fns{combos(ic,2)}).z(2);
if( (x12>x21 && y12>y21 && z12>z21) || (x21>x12 && y21>y12 && z21>z12) )
% There is either overlap, or the edge of classes align
% Check for overlap in x
if( ((x12>=x21) && (x11<=x22)) || ((x11<=x22) && (x21<=x21)) )
if((x21==x12) || (x11==x22))
continue;
else
fprintf(‘Overlap in x between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s x: [%g %g]n’, fns{combos(ic,1)}, x11, x12);
fprintf(‘ Limits for %s x: [%g %g]n’, fns{combos(ic,2)}, x21, x22);
end
end
% Check for overlap in y
if( ((y12>=y21) && (y11<=y22)) || ((y11<=y22) && (y21<=y21)) )
if((y21==y12) || (y11==y22))
continue;
else
fprintf(‘Overlap in y between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s y: [%g %g]n’, fns{combos(ic,1)}, y11, y12);
fprintf(‘ Limits for %s y: [%g %g]n’, fns{combos(ic,2)}, y21, y22);
end
end
% Check for overlap in z
if( ((z12>=z21) && (z11<=z22)) || ((z11<=z22) && (z21<=z21)) )
if((z21==z12) || (z11==z22))
continue;
else
fprintf(‘Overlap in z between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s z: [%g %g]n’, fns{combos(ic,1)}, z11, z12);
fprintf(‘ Limits for %s z: [%g %g]n’, fns{combos(ic,2)}, z21, z22);
end
end
end
end
I just can’t get the last part which will identify where the gaps happen. I think I can modify the above code to push this function across the finish line, but I need some help. I have rectangular prisms at fixed locations defined below, and I’m trying to see if they fit in a box without any gaps or overlaps. The perfect no-gaps, no-overlaps solution looks like the picture of the attached Jenga tower.
% Fit the following rectangular prisms in a box:
prisms.p1.x = [75 200]; % Min/max of x range for prism p1
prisms.p1.y = [4 100]; % Min/max of y range for prism p1
prisms.p1.z = [1e3 1e4]; % Min/max of z range for prism p1
prisms.p2.x = [20 80];
prisms.p2.y = [0.1 2.2];
prisms.p2.z = [0 1e3];
prisms.p3.x = [80 115];
prisms.p3.y = [0.1 4];
prisms.p3.z = [0 1e3];
prisms.p4.x = [20 180];
prisms.p4.y = [2.2 8];
prisms.p4.z = [0 1e3];
prisms.p5.x = [200 1000];
prisms.p5.y = [0 1];
prisms.p5.z = [0 1e4];
% The box that the prisms must fit in, given the values above, is:
box.x = [20 1000]; % Min/max of x range for the box of prisms
box.y = [0 100]; % Min/max of x range for the box of prisms
box.z = [0 1e4]; % Min/max of x range for the box of prisms
Above is a struct called prisms. It has 5 fields; each field describes one prism (p1,p2,p3,p4,p5) using x,y,z coordinates. I want to identify if the rectangular prisms have any overlaps or gaps between them, and if so, report where those gaps and/or overlaps occur. The ranges are all aligned with the axes, and are always >=0.
The size of the box that the prisms must fit in is defined to be the min and max values over all prisms for a particular axis. If two prisms touch at only one point in their range, I don’t count that as an "overlap". I don’t want to move the prisms, but instead want to report where two prisms overlap, or where there are gaps in the box.
I’ve found all the overlapping regions by testing pairs of rectangular prisms for overlap, and it seems to work:
%% Get all combinations of classes (combinations since order does not matter)
nFields = length(fieldnames(prisms));
combos = nchoosek(1:nFields,2);
nCombos = nchoosek(nFields,2);
% Index the struct by index instead of field name
fns = fieldnames(prisms);
%% Check for overlap between each pair of classes
for ic = 1:nCombos
x11 = prisms.(fns{combos(ic,1)}).x(1);
x12 = prisms.(fns{combos(ic,1)}).x(2);
y11 = prisms.(fns{combos(ic,1)}).y(1);
y12 = prisms.(fns{combos(ic,1)}).y(2);
z11 = prisms.(fns{combos(ic,1)}).z(1);
z12 = prisms.(fns{combos(ic,1)}).z(2);
x21 = prisms.(fns{combos(ic,2)}).x(1);
x22 = prisms.(fns{combos(ic,2)}).x(2);
y21 = prisms.(fns{combos(ic,2)}).y(1);
y22 = prisms.(fns{combos(ic,2)}).y(2);
z21 = prisms.(fns{combos(ic,2)}).z(1);
z22 = prisms.(fns{combos(ic,2)}).z(2);
if( (x12>x21 && y12>y21 && z12>z21) || (x21>x12 && y21>y12 && z21>z12) )
% There is either overlap, or the edge of classes align
% Check for overlap in x
if( ((x12>=x21) && (x11<=x22)) || ((x11<=x22) && (x21<=x21)) )
if((x21==x12) || (x11==x22))
continue;
else
fprintf(‘Overlap in x between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s x: [%g %g]n’, fns{combos(ic,1)}, x11, x12);
fprintf(‘ Limits for %s x: [%g %g]n’, fns{combos(ic,2)}, x21, x22);
end
end
% Check for overlap in y
if( ((y12>=y21) && (y11<=y22)) || ((y11<=y22) && (y21<=y21)) )
if((y21==y12) || (y11==y22))
continue;
else
fprintf(‘Overlap in y between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s y: [%g %g]n’, fns{combos(ic,1)}, y11, y12);
fprintf(‘ Limits for %s y: [%g %g]n’, fns{combos(ic,2)}, y21, y22);
end
end
% Check for overlap in z
if( ((z12>=z21) && (z11<=z22)) || ((z11<=z22) && (z21<=z21)) )
if((z21==z12) || (z11==z22))
continue;
else
fprintf(‘Overlap in z between %s and %sn’, fns{combos(ic,1)}, fns{combos(ic,2)});
fprintf(‘ Limits for %s z: [%g %g]n’, fns{combos(ic,1)}, z11, z12);
fprintf(‘ Limits for %s z: [%g %g]n’, fns{combos(ic,2)}, z21, z22);
end
end
end
end
I just can’t get the last part which will identify where the gaps happen. I think I can modify the above code to push this function across the finish line, but I need some help. matlab, function, 3d, mathematics MATLAB Answers — New Questions
Position finding by triangulation
How can I triangulate a position using two DMEs in matlab?How can I triangulate a position using two DMEs in matlab? How can I triangulate a position using two DMEs in matlab? navigation MATLAB Answers — New Questions









