Tag Archives: matlab
Halo i want to combine 2d slices oct skin images into 3d, after that i want to make an automatic detection volume of epidermis and stratum corneum
i already combine like this
% Initialize variables
rows = []; columns = [];
% Loop through each slice
for k = 1:100
fileName = sprintf(‘_%d.txt’, k);
% Read the text file
sliceImage = dlmread(fileName);
% Check the size of the first slice to initialize the 3D array
if isempty(rows) || isempty(columns)
[rows, columns] = size(sliceImage);
image3d = zeros(rows, columns, 8, ‘uint8’); % Initialize 3D array
end
% Convert to uint8
sliceImage = uint8(sliceImage);
% Put this slice into plane k of the 3D image
image3d(:, :, k) = sliceImage;
endi already combine like this
% Initialize variables
rows = []; columns = [];
% Loop through each slice
for k = 1:100
fileName = sprintf(‘_%d.txt’, k);
% Read the text file
sliceImage = dlmread(fileName);
% Check the size of the first slice to initialize the 3D array
if isempty(rows) || isempty(columns)
[rows, columns] = size(sliceImage);
image3d = zeros(rows, columns, 8, ‘uint8’); % Initialize 3D array
end
% Convert to uint8
sliceImage = uint8(sliceImage);
% Put this slice into plane k of the 3D image
image3d(:, :, k) = sliceImage;
end i already combine like this
% Initialize variables
rows = []; columns = [];
% Loop through each slice
for k = 1:100
fileName = sprintf(‘_%d.txt’, k);
% Read the text file
sliceImage = dlmread(fileName);
% Check the size of the first slice to initialize the 3D array
if isempty(rows) || isempty(columns)
[rows, columns] = size(sliceImage);
image3d = zeros(rows, columns, 8, ‘uint8’); % Initialize 3D array
end
% Convert to uint8
sliceImage = uint8(sliceImage);
% Put this slice into plane k of the 3D image
image3d(:, :, k) = sliceImage;
end 3d plots, image segmentation MATLAB Answers — New Questions
how to export model coordinates?
Hello,
I am running the example spiralInductor.
Is there a way to export the geometry for fabrication?
Thank youHello,
I am running the example spiralInductor.
Is there a way to export the geometry for fabrication?
Thank you Hello,
I am running the example spiralInductor.
Is there a way to export the geometry for fabrication?
Thank you coil, matlab coder, microwave, performance MATLAB Answers — New Questions
Remogenerate optimized code by removing code for out-of-range floating point to integer conversions did not improve execution speed,is there a problem?
I want to improve the running speed of the code converted from Simulink to C coder, so I tried setting the maximum running speed mode in it, but the result was similar to balancing RAM and speed mode. So I tried to modify more detailed settings, I tried to modify the settings to regenerate optimized code by removing out of range floating-point to integer conversion code, but still had no effect. Why is this? Is there any other setting in the model that can improve the running speed of the code? Or should I directly modify the structure of the code to improve speed?I want to improve the running speed of the code converted from Simulink to C coder, so I tried setting the maximum running speed mode in it, but the result was similar to balancing RAM and speed mode. So I tried to modify more detailed settings, I tried to modify the settings to regenerate optimized code by removing out of range floating-point to integer conversion code, but still had no effect. Why is this? Is there any other setting in the model that can improve the running speed of the code? Or should I directly modify the structure of the code to improve speed? I want to improve the running speed of the code converted from Simulink to C coder, so I tried setting the maximum running speed mode in it, but the result was similar to balancing RAM and speed mode. So I tried to modify more detailed settings, I tried to modify the settings to regenerate optimized code by removing out of range floating-point to integer conversion code, but still had no effect. Why is this? Is there any other setting in the model that can improve the running speed of the code? Or should I directly modify the structure of the code to improve speed? simulink, embedded coder MATLAB Answers — New Questions
How to average across tables in a cell
I have a Cell containing a n number of tables (in this case 3 tables (2500×44)) and I’m trying output just one table being the average of each cell within each table across all 3 tables. This is likely a silly question but can’t seem to figure it out.I have a Cell containing a n number of tables (in this case 3 tables (2500×44)) and I’m trying output just one table being the average of each cell within each table across all 3 tables. This is likely a silly question but can’t seem to figure it out. I have a Cell containing a n number of tables (in this case 3 tables (2500×44)) and I’m trying output just one table being the average of each cell within each table across all 3 tables. This is likely a silly question but can’t seem to figure it out. cell array, table, mean MATLAB Answers — New Questions
Why there is a time delay of one time step while co-simulating a FMU in Simulink?
I exported an FMU from a Simulink model with Simulink Compiler and imported it into Simulink with FMU Import block.
In the results, when comparing the Simulink output and the FMU output, I see that they do not match with a one-time step difference/one-time step delay.
What is causing this behavior?I exported an FMU from a Simulink model with Simulink Compiler and imported it into Simulink with FMU Import block.
In the results, when comparing the Simulink output and the FMU output, I see that they do not match with a one-time step difference/one-time step delay.
What is causing this behavior? I exported an FMU from a Simulink model with Simulink Compiler and imported it into Simulink with FMU Import block.
In the results, when comparing the Simulink output and the FMU output, I see that they do not match with a one-time step difference/one-time step delay.
What is causing this behavior? fmu, delay, time, step, different, results, simulink, fmi MATLAB Answers — New Questions
Interpolating between columns for an index
I am trying to use a seperate array as an index and a variable.
E.g.
Row 1 I want to use as index, or lookup.
Row 2 are data
550 750 950
1 2 8
Column 1 would be reference from row 1
Column 2 would be multiplied against row 2 depending on how Column 1 relates to row 1
550 22
580 21
650 20
623 28
850 14
So my goal is using the second set of data.
at 550, 22 would be multiplied by 1,
at 650, 20 would be multiplied by 1.5
at 850, 14 would be multiplied by 5
I tried search for awhile on the community and through the "basics"
I might be wording this wrong by calling it indexing.I am trying to use a seperate array as an index and a variable.
E.g.
Row 1 I want to use as index, or lookup.
Row 2 are data
550 750 950
1 2 8
Column 1 would be reference from row 1
Column 2 would be multiplied against row 2 depending on how Column 1 relates to row 1
550 22
580 21
650 20
623 28
850 14
So my goal is using the second set of data.
at 550, 22 would be multiplied by 1,
at 650, 20 would be multiplied by 1.5
at 850, 14 would be multiplied by 5
I tried search for awhile on the community and through the "basics"
I might be wording this wrong by calling it indexing. I am trying to use a seperate array as an index and a variable.
E.g.
Row 1 I want to use as index, or lookup.
Row 2 are data
550 750 950
1 2 8
Column 1 would be reference from row 1
Column 2 would be multiplied against row 2 depending on how Column 1 relates to row 1
550 22
580 21
650 20
623 28
850 14
So my goal is using the second set of data.
at 550, 22 would be multiplied by 1,
at 650, 20 would be multiplied by 1.5
at 850, 14 would be multiplied by 5
I tried search for awhile on the community and through the "basics"
I might be wording this wrong by calling it indexing. basics, interpolation, indexing MATLAB Answers — New Questions
Trying to sign out of MATLAB desktop
I am trying to sign out of my MATLAB account on the desktop app, yet it is not letting me.
I keep getting this message, although I have nothing open aside from MATLAB and no scripts are running: Before signing out you must:
Close all MATLAB sessions, including the current one.Note: Restarting MATLAB requires internet access.I am trying to sign out of my MATLAB account on the desktop app, yet it is not letting me.
I keep getting this message, although I have nothing open aside from MATLAB and no scripts are running: Before signing out you must:
Close all MATLAB sessions, including the current one.Note: Restarting MATLAB requires internet access. I am trying to sign out of my MATLAB account on the desktop app, yet it is not letting me.
I keep getting this message, although I have nothing open aside from MATLAB and no scripts are running: Before signing out you must:
Close all MATLAB sessions, including the current one.Note: Restarting MATLAB requires internet access. matlab MATLAB Answers — New Questions
Detecting circles in an image to measure inner and outer diameter
Any reason why this code won’t detect the inner and outer diamter of the tube seen in the image below?
a = imread(‘E1-E2.jpg’);
imshow(a);
% Center and radius
[centers,radii] = imfindcircles(a,[20 1000],’ObjectPolarity’,’bright’, ‘Sensitivity’,0.95);
diameter = radii*2;
viscircles(centers, radii,’Color’,’b’);Any reason why this code won’t detect the inner and outer diamter of the tube seen in the image below?
a = imread(‘E1-E2.jpg’);
imshow(a);
% Center and radius
[centers,radii] = imfindcircles(a,[20 1000],’ObjectPolarity’,’bright’, ‘Sensitivity’,0.95);
diameter = radii*2;
viscircles(centers, radii,’Color’,’b’); Any reason why this code won’t detect the inner and outer diamter of the tube seen in the image below?
a = imread(‘E1-E2.jpg’);
imshow(a);
% Center and radius
[centers,radii] = imfindcircles(a,[20 1000],’ObjectPolarity’,’bright’, ‘Sensitivity’,0.95);
diameter = radii*2;
viscircles(centers, radii,’Color’,’b’); image, circle, wrong lens, image analysis MATLAB Answers — New Questions
Reading data from Microsoft Excel
What is the syntax for reading data from Microsoft Excel sheets? I tried the following and it returned error messages.
A = xlsread(‘amat.xlsx’,’sheet1′,’a1:a10′)
I even changed the case of S in sheet to capital and the error persisted. Anyone with an idea?What is the syntax for reading data from Microsoft Excel sheets? I tried the following and it returned error messages.
A = xlsread(‘amat.xlsx’,’sheet1′,’a1:a10′)
I even changed the case of S in sheet to capital and the error persisted. Anyone with an idea? What is the syntax for reading data from Microsoft Excel sheets? I tried the following and it returned error messages.
A = xlsread(‘amat.xlsx’,’sheet1′,’a1:a10′)
I even changed the case of S in sheet to capital and the error persisted. Anyone with an idea? transferred MATLAB Answers — New Questions
How to deal with corrupted matlabprefs?
I run a matlab-script that use batch processing to collect sample from different sensors at same time.
Some sensors are connect using UDP protocol, modbus, and serial port.
As a rule, they work fine. However, sometimes I have an error related to matlabprefs.mat.
As a consequence, one of the sensors can stop to collect data, i.e., I can not read correctly form a specific serial port, and in the next time I run the same matlab script, it will fail producing some complaining about "matlabprefs.mat" (see example below).
I have this problem frequently.
I am affraid becasue If I can not deal properlly with this problem,I can not trust on matlab to control my data sample system.
Please, could you help me to figure out a deffinitive solution for this issue?
Warning: Initializing MATLAB Graphics failed.
This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was:
MATLAB:load:unableToReadMatFile
Unable to read MAT-file C:UsersuserAppDataRoamingMathWorksMATLABR2023amatlabprefs.mat. File might be corrupt.
> In hgrc (line 151)
In matlab.graphics.internal.initialize (line 15)I run a matlab-script that use batch processing to collect sample from different sensors at same time.
Some sensors are connect using UDP protocol, modbus, and serial port.
As a rule, they work fine. However, sometimes I have an error related to matlabprefs.mat.
As a consequence, one of the sensors can stop to collect data, i.e., I can not read correctly form a specific serial port, and in the next time I run the same matlab script, it will fail producing some complaining about "matlabprefs.mat" (see example below).
I have this problem frequently.
I am affraid becasue If I can not deal properlly with this problem,I can not trust on matlab to control my data sample system.
Please, could you help me to figure out a deffinitive solution for this issue?
Warning: Initializing MATLAB Graphics failed.
This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was:
MATLAB:load:unableToReadMatFile
Unable to read MAT-file C:UsersuserAppDataRoamingMathWorksMATLABR2023amatlabprefs.mat. File might be corrupt.
> In hgrc (line 151)
In matlab.graphics.internal.initialize (line 15) I run a matlab-script that use batch processing to collect sample from different sensors at same time.
Some sensors are connect using UDP protocol, modbus, and serial port.
As a rule, they work fine. However, sometimes I have an error related to matlabprefs.mat.
As a consequence, one of the sensors can stop to collect data, i.e., I can not read correctly form a specific serial port, and in the next time I run the same matlab script, it will fail producing some complaining about "matlabprefs.mat" (see example below).
I have this problem frequently.
I am affraid becasue If I can not deal properlly with this problem,I can not trust on matlab to control my data sample system.
Please, could you help me to figure out a deffinitive solution for this issue?
Warning: Initializing MATLAB Graphics failed.
This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was:
MATLAB:load:unableToReadMatFile
Unable to read MAT-file C:UsersuserAppDataRoamingMathWorksMATLABR2023amatlabprefs.mat. File might be corrupt.
> In hgrc (line 151)
In matlab.graphics.internal.initialize (line 15) matlabprefs.mat MATLAB Answers — New Questions
function chaining when one function has multiple outputs
Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y)Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y) Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y) chained_function, function_chaining, function_composition MATLAB Answers — New Questions
MATLAB Web Apps are not supported on this device (Phone)
Good night everybody,
I am currently trying to develop a MATLAB Web App on MATLAB Web Server R2020b. This application works fine on Desktop, however if I try to access it on any phone an error "MATLAB Web Apps are not supported on this device" appears. I have accessed the link (https://es.mathworks.com/help/compiler/webapps/supported-browsers-and-platform-incompatibilities.html#:~:text=Web%20apps%20are%20compatible%20with,Chrome%E2%84%A2%20browser%20on%20Chromebooks.) of the error and there is nothing about incompatibility with phones. Are phones and maybe some other devices unhandled by Web Apps or this is some unrelated error which I can’t manage to find? As an example, if I try to access with Chrome or Firefox on a Pixel 2 the error of the image appears, however if I turn on "View in desktop mode" it works correctly and I can see my app.
Thank you all,
MarcosGood night everybody,
I am currently trying to develop a MATLAB Web App on MATLAB Web Server R2020b. This application works fine on Desktop, however if I try to access it on any phone an error "MATLAB Web Apps are not supported on this device" appears. I have accessed the link (https://es.mathworks.com/help/compiler/webapps/supported-browsers-and-platform-incompatibilities.html#:~:text=Web%20apps%20are%20compatible%20with,Chrome%E2%84%A2%20browser%20on%20Chromebooks.) of the error and there is nothing about incompatibility with phones. Are phones and maybe some other devices unhandled by Web Apps or this is some unrelated error which I can’t manage to find? As an example, if I try to access with Chrome or Firefox on a Pixel 2 the error of the image appears, however if I turn on "View in desktop mode" it works correctly and I can see my app.
Thank you all,
Marcos Good night everybody,
I am currently trying to develop a MATLAB Web App on MATLAB Web Server R2020b. This application works fine on Desktop, however if I try to access it on any phone an error "MATLAB Web Apps are not supported on this device" appears. I have accessed the link (https://es.mathworks.com/help/compiler/webapps/supported-browsers-and-platform-incompatibilities.html#:~:text=Web%20apps%20are%20compatible%20with,Chrome%E2%84%A2%20browser%20on%20Chromebooks.) of the error and there is nothing about incompatibility with phones. Are phones and maybe some other devices unhandled by Web Apps or this is some unrelated error which I can’t manage to find? As an example, if I try to access with Chrome or Firefox on a Pixel 2 the error of the image appears, however if I turn on "View in desktop mode" it works correctly and I can see my app.
Thank you all,
Marcos matlab, web app MATLAB Answers — New Questions
Would like to determine when a UDP packet is physically received
Hello,
Is there anyway to determine when a machine physically receives a UDP packet from the network?
Thanks!Hello,
Is there anyway to determine when a machine physically receives a UDP packet from the network?
Thanks! Hello,
Is there anyway to determine when a machine physically receives a UDP packet from the network?
Thanks! udp MATLAB Answers — New Questions
How to apply orientation constraints between two rigid bodies
I am trying to do an inverse kinematics analysis on a rigid body tree that has 3 rigid bodies, all with revolute joints, operating in a 2D plane. One of the contraints of the system that this is based off is that the first and third body must be parallel. How would I apply a constraint to ensure that this happens? I am attempting to mimic the physical motion of the model below, where the base frame is the hole near the top of the 3D model.I am trying to do an inverse kinematics analysis on a rigid body tree that has 3 rigid bodies, all with revolute joints, operating in a 2D plane. One of the contraints of the system that this is based off is that the first and third body must be parallel. How would I apply a constraint to ensure that this happens? I am attempting to mimic the physical motion of the model below, where the base frame is the hole near the top of the 3D model. I am trying to do an inverse kinematics analysis on a rigid body tree that has 3 rigid bodies, all with revolute joints, operating in a 2D plane. One of the contraints of the system that this is based off is that the first and third body must be parallel. How would I apply a constraint to ensure that this happens? I am attempting to mimic the physical motion of the model below, where the base frame is the hole near the top of the 3D model. robotics, inverse kinematics MATLAB Answers — New Questions
Arduino Fails to Program with “avrdude: ser_open(): can’t set com-state” Error
I have an Arduino Uno device and have attempted to attach it to one of my computer’s COM Ports via a USB cable. I have downloaded the MATLAB Support Package for Arduino Hardware, and ensured that it is correctly accessed by my MATLAB installation via the following commands:
>> restoredefaultpath
>> rehash toolboxcache
Following this, I enter the "arduinosetup" command into my MATLAB Command Window, and follow the instructions described in the following MATLAB Documentation:
https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html
I have ensured that I am selecting both the correct board as well as the correct COM port. However, when I press "Program", I receive the following error message:
Failed to program the arduino board. Click the following link to see the error log. Contact Technical support if you need more help.
Clicking the link in that message provides me a TXT file with a fairly large stack trace. The most important lines, however, seem to be at the end. These read the following:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:ProgramDataMATLABSupportPackagesR2023aaIDEhardwaretoolsavr/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can’t set com-state for "\.COM5"
avrdude done. Thank you.
An error occurred while uploading the sketch
Upon receiving this error, I tried a few initial troubleshooting steps:Uninstalling and then reinstalling the MATLAB Support Package for Arduino Hardware.Connecting to a different COM port.Restarting both my system and my Arduino board.
Unfortunately, none of the above steps changed the resulting error message. How do I fix this and ensure that I am able to interact with my Arduino board via MATLAB?I have an Arduino Uno device and have attempted to attach it to one of my computer’s COM Ports via a USB cable. I have downloaded the MATLAB Support Package for Arduino Hardware, and ensured that it is correctly accessed by my MATLAB installation via the following commands:
>> restoredefaultpath
>> rehash toolboxcache
Following this, I enter the "arduinosetup" command into my MATLAB Command Window, and follow the instructions described in the following MATLAB Documentation:
https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html
I have ensured that I am selecting both the correct board as well as the correct COM port. However, when I press "Program", I receive the following error message:
Failed to program the arduino board. Click the following link to see the error log. Contact Technical support if you need more help.
Clicking the link in that message provides me a TXT file with a fairly large stack trace. The most important lines, however, seem to be at the end. These read the following:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:ProgramDataMATLABSupportPackagesR2023aaIDEhardwaretoolsavr/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can’t set com-state for "\.COM5"
avrdude done. Thank you.
An error occurred while uploading the sketch
Upon receiving this error, I tried a few initial troubleshooting steps:Uninstalling and then reinstalling the MATLAB Support Package for Arduino Hardware.Connecting to a different COM port.Restarting both my system and my Arduino board.
Unfortunately, none of the above steps changed the resulting error message. How do I fix this and ensure that I am able to interact with my Arduino board via MATLAB? I have an Arduino Uno device and have attempted to attach it to one of my computer’s COM Ports via a USB cable. I have downloaded the MATLAB Support Package for Arduino Hardware, and ensured that it is correctly accessed by my MATLAB installation via the following commands:
>> restoredefaultpath
>> rehash toolboxcache
Following this, I enter the "arduinosetup" command into my MATLAB Command Window, and follow the instructions described in the following MATLAB Documentation:
https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html
I have ensured that I am selecting both the correct board as well as the correct COM port. However, when I press "Program", I receive the following error message:
Failed to program the arduino board. Click the following link to see the error log. Contact Technical support if you need more help.
Clicking the link in that message provides me a TXT file with a fairly large stack trace. The most important lines, however, seem to be at the end. These read the following:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:ProgramDataMATLABSupportPackagesR2023aaIDEhardwaretoolsavr/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can’t set com-state for "\.COM5"
avrdude done. Thank you.
An error occurred while uploading the sketch
Upon receiving this error, I tried a few initial troubleshooting steps:Uninstalling and then reinstalling the MATLAB Support Package for Arduino Hardware.Connecting to a different COM port.Restarting both my system and my Arduino board.
Unfortunately, none of the above steps changed the resulting error message. How do I fix this and ensure that I am able to interact with my Arduino board via MATLAB? arduino, program, driver, drivers, avrdude, com, port MATLAB Answers — New Questions
thingspeak server closing connection immediately
mqtt3.thingspeak.com closing the connection immediately when trying to connect using A6 gsm module. Has been working flawlessly up to a week ago.Not able to publish any data to private channel. No encryption used (http).mqtt3.thingspeak.com closing the connection immediately when trying to connect using A6 gsm module. Has been working flawlessly up to a week ago.Not able to publish any data to private channel. No encryption used (http). mqtt3.thingspeak.com closing the connection immediately when trying to connect using A6 gsm module. Has been working flawlessly up to a week ago.Not able to publish any data to private channel. No encryption used (http). mqtt broker, tihngspeak MATLAB Answers — New Questions
Theoretical details regarding symbolic integration in Matlab
Dear all,
I am using symbolic integration in Matlab (in particular the "int"-function). I would like to use it as a reference in my research. Therefore, it would be nice to obtain some details which methods Matlab is actually using. Does anybody know? Is there a source to get more details?
Best,
MichaelDear all,
I am using symbolic integration in Matlab (in particular the "int"-function). I would like to use it as a reference in my research. Therefore, it would be nice to obtain some details which methods Matlab is actually using. Does anybody know? Is there a source to get more details?
Best,
Michael Dear all,
I am using symbolic integration in Matlab (in particular the "int"-function). I would like to use it as a reference in my research. Therefore, it would be nice to obtain some details which methods Matlab is actually using. Does anybody know? Is there a source to get more details?
Best,
Michael integration, symbolic, theory MATLAB Answers — New Questions
Why do I get different results on different machines when using “fmincon” from the Optimization Toolbox?
When I try to optimize my objective function with "fmincon", the optimization exits with a flag 0. However on a different machine, it exits with a flag 5. Why do these results differ?When I try to optimize my objective function with "fmincon", the optimization exits with a flag 0. However on a different machine, it exits with a flag 5. Why do these results differ? When I try to optimize my objective function with "fmincon", the optimization exits with a flag 0. However on a different machine, it exits with a flag 5. Why do these results differ? fmincon, condition, firstorderopt, optimization, numericalreproducibility MATLAB Answers — New Questions
app designer error: Attempt to add “theta” to a static workspace.
Hello, i wrote a code and it works while running the script. but when i use it in an app this error shows up Attempt to add "theta" to a static workspace. can somebody help me out. thanks
The code:
%% Constants and parameters
J1 = 1; % Polarization of outer magnet
J2 = 1; % Polarization of inner magnet
u0 = pi*4e-7; % Magnetic constant
%% Position vectors, define appropriately
r = [0.25, 0.3, 0.20 , 0.24]; % radius of magnets (outer to inner)
z = [0.05, 0.15, 0.08, 0.18]; % z cordinate of magnets (outer to inner)
%% main function g
g = @(a, b, c) computeG(a, b, c);
% Initialize F_Z
F_Z = 0;
% Compute F_Z based on the given formula
for i = 1:2
for k = 1:2
for j = 3:4
for l = 3:4
deltaZ = z(k) – z(l);
ri2 = r(i)^2;
rj2 = r(j)^2;
Fijkl = r(i) * r(j) * g(deltaZ, ri2+rj2+deltaZ^2, -2 * r(i) * r(j));
power = 1 + i + j + k + l;
F_Z = F_Z + ((-1)^power) * Fijkl;
end
end
end
end
F_Z = ((J1 * J2) / (2 * u0)) * F_Z;
%% Define the function computeG
function result = computeG(a, b, c)
A = (a^2 – b) / c * pi + sqrt(c^2 – (a^2 – b)^2) / c *(log((-16 * c^2) / ((c^2 – (a^2 – b)^2)^1.5)) + log(c^2 / ((c^2 – (a^2 – b)^2)^1.5)));
S = computeS(a, b, c);
result = A + S;
end
%% Define the function computeS
function S = computeS(a, b, c)
% Define constants
epsilon = c / (c – b);
beta = (b + c) / (b – c);
mu = c / (b + c);
% Calculate terms for S
term1 = (2 * 1i * a) / (c * sqrt(b + c)) * …
((b + c) * ellipticE(asin(sqrt(beta)), beta^(-1)) – c * ellipticF(asin(sqrt(beta)), beta^(-1)));
term2 = (2 * a) / (c * sqrt(b – c) * sqrt(epsilon)) * …
(c / sqrt(mu) * ellipticE1(1 / beta) – c * sqrt(mu) * ellipticK(1 / beta));
term3 = sqrt(epsilon * (1 / beta)) * …
((b – a^2) * ellipticK(2 * mu) + (a^2 – b + c) * ellipticPi(2 * c / (c + b – a^2), 2 * mu));
% Sum all terms
S = term1 + term2 + term3;
end
% Elliptic integral functions using symbolic math toolbox
function val = ellipticK(m)
syms theta;
val = double(int(1 / sqrt(1 – m * sin(theta)^2), theta, 0, pi/2));
end
function val = ellipticF(phi, m)
syms theta;
val = double(int(1 / sqrt(1 – m * sin(theta)^2), theta, 0, phi));
end
function val = ellipticE(phi, m)
syms theta;
val = double(int(sqrt(1 – m * sin(theta)^2), theta, 0, phi));
end
function val = ellipticE1(m)
syms theta;
val = double(int(sqrt(1 – m * sin(theta)^2), theta, 0, pi/2));
end
function val = ellipticPi(n, m)
syms theta;
val = double(int(1 / (sqrt(1 – n * sin(theta)^2) * sqrt(1 – m * sin(theta)^2)), theta, 0, pi/2));
endHello, i wrote a code and it works while running the script. but when i use it in an app this error shows up Attempt to add "theta" to a static workspace. can somebody help me out. thanks
The code:
%% Constants and parameters
J1 = 1; % Polarization of outer magnet
J2 = 1; % Polarization of inner magnet
u0 = pi*4e-7; % Magnetic constant
%% Position vectors, define appropriately
r = [0.25, 0.3, 0.20 , 0.24]; % radius of magnets (outer to inner)
z = [0.05, 0.15, 0.08, 0.18]; % z cordinate of magnets (outer to inner)
%% main function g
g = @(a, b, c) computeG(a, b, c);
% Initialize F_Z
F_Z = 0;
% Compute F_Z based on the given formula
for i = 1:2
for k = 1:2
for j = 3:4
for l = 3:4
deltaZ = z(k) – z(l);
ri2 = r(i)^2;
rj2 = r(j)^2;
Fijkl = r(i) * r(j) * g(deltaZ, ri2+rj2+deltaZ^2, -2 * r(i) * r(j));
power = 1 + i + j + k + l;
F_Z = F_Z + ((-1)^power) * Fijkl;
end
end
end
end
F_Z = ((J1 * J2) / (2 * u0)) * F_Z;
%% Define the function computeG
function result = computeG(a, b, c)
A = (a^2 – b) / c * pi + sqrt(c^2 – (a^2 – b)^2) / c *(log((-16 * c^2) / ((c^2 – (a^2 – b)^2)^1.5)) + log(c^2 / ((c^2 – (a^2 – b)^2)^1.5)));
S = computeS(a, b, c);
result = A + S;
end
%% Define the function computeS
function S = computeS(a, b, c)
% Define constants
epsilon = c / (c – b);
beta = (b + c) / (b – c);
mu = c / (b + c);
% Calculate terms for S
term1 = (2 * 1i * a) / (c * sqrt(b + c)) * …
((b + c) * ellipticE(asin(sqrt(beta)), beta^(-1)) – c * ellipticF(asin(sqrt(beta)), beta^(-1)));
term2 = (2 * a) / (c * sqrt(b – c) * sqrt(epsilon)) * …
(c / sqrt(mu) * ellipticE1(1 / beta) – c * sqrt(mu) * ellipticK(1 / beta));
term3 = sqrt(epsilon * (1 / beta)) * …
((b – a^2) * ellipticK(2 * mu) + (a^2 – b + c) * ellipticPi(2 * c / (c + b – a^2), 2 * mu));
% Sum all terms
S = term1 + term2 + term3;
end
% Elliptic integral functions using symbolic math toolbox
function val = ellipticK(m)
syms theta;
val = double(int(1 / sqrt(1 – m * sin(theta)^2), theta, 0, pi/2));
end
function val = ellipticF(phi, m)
syms theta;
val = double(int(1 / sqrt(1 – m * sin(theta)^2), theta, 0, phi));
end
function val = ellipticE(phi, m)
syms theta;
val = double(int(sqrt(1 – m * sin(theta)^2), theta, 0, phi));
end
function val = ellipticE1(m)
syms theta;
val = double(int(sqrt(1 – m * sin(theta)^2), theta, 0, pi/2));
end
function val = ellipticPi(n, m)
syms theta;
val = double(int(1 / (sqrt(1 – n * sin(theta)^2) * sqrt(1 – m * sin(theta)^2)), theta, 0, pi/2));
end Hello, i wrote a code and it works while running the script. but when i use it in an app this error shows up Attempt to add "theta" to a static workspace. can somebody help me out. thanks
The code:
%% Constants and parameters
J1 = 1; % Polarization of outer magnet
J2 = 1; % Polarization of inner magnet
u0 = pi*4e-7; % Magnetic constant
%% Position vectors, define appropriately
r = [0.25, 0.3, 0.20 , 0.24]; % radius of magnets (outer to inner)
z = [0.05, 0.15, 0.08, 0.18]; % z cordinate of magnets (outer to inner)
%% main function g
g = @(a, b, c) computeG(a, b, c);
% Initialize F_Z
F_Z = 0;
% Compute F_Z based on the given formula
for i = 1:2
for k = 1:2
for j = 3:4
for l = 3:4
deltaZ = z(k) – z(l);
ri2 = r(i)^2;
rj2 = r(j)^2;
Fijkl = r(i) * r(j) * g(deltaZ, ri2+rj2+deltaZ^2, -2 * r(i) * r(j));
power = 1 + i + j + k + l;
F_Z = F_Z + ((-1)^power) * Fijkl;
end
end
end
end
F_Z = ((J1 * J2) / (2 * u0)) * F_Z;
%% Define the function computeG
function result = computeG(a, b, c)
A = (a^2 – b) / c * pi + sqrt(c^2 – (a^2 – b)^2) / c *(log((-16 * c^2) / ((c^2 – (a^2 – b)^2)^1.5)) + log(c^2 / ((c^2 – (a^2 – b)^2)^1.5)));
S = computeS(a, b, c);
result = A + S;
end
%% Define the function computeS
function S = computeS(a, b, c)
% Define constants
epsilon = c / (c – b);
beta = (b + c) / (b – c);
mu = c / (b + c);
% Calculate terms for S
term1 = (2 * 1i * a) / (c * sqrt(b + c)) * …
((b + c) * ellipticE(asin(sqrt(beta)), beta^(-1)) – c * ellipticF(asin(sqrt(beta)), beta^(-1)));
term2 = (2 * a) / (c * sqrt(b – c) * sqrt(epsilon)) * …
(c / sqrt(mu) * ellipticE1(1 / beta) – c * sqrt(mu) * ellipticK(1 / beta));
term3 = sqrt(epsilon * (1 / beta)) * …
((b – a^2) * ellipticK(2 * mu) + (a^2 – b + c) * ellipticPi(2 * c / (c + b – a^2), 2 * mu));
% Sum all terms
S = term1 + term2 + term3;
end
% Elliptic integral functions using symbolic math toolbox
function val = ellipticK(m)
syms theta;
val = double(int(1 / sqrt(1 – m * sin(theta)^2), theta, 0, pi/2));
end
function val = ellipticF(phi, m)
syms theta;
val = double(int(1 / sqrt(1 – m * sin(theta)^2), theta, 0, phi));
end
function val = ellipticE(phi, m)
syms theta;
val = double(int(sqrt(1 – m * sin(theta)^2), theta, 0, phi));
end
function val = ellipticE1(m)
syms theta;
val = double(int(sqrt(1 – m * sin(theta)^2), theta, 0, pi/2));
end
function val = ellipticPi(n, m)
syms theta;
val = double(int(1 / (sqrt(1 – n * sin(theta)^2) * sqrt(1 – m * sin(theta)^2)), theta, 0, pi/2));
end appdesigner, app designer MATLAB Answers — New Questions
Speed of vpaintegral vs. int+vpa
Dear all,
I am currently testing the possibilities of integrating symbolic functions in Matlab. In the documentation of "int" (https://de.mathworks.com/help/symbolic/sym.int.html), I found the following statement which is not in agreement with my personal observations:
"To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances."
I run the following example and observe that a combination of "int" and "vpa" needs 0.35 secs vs. 47.69 secs in case of "vpaintegral" both having the same precision of 32 valid digits.
syms x y
% define integration boundary
f1 = 0;
eqn = 0.980580675690920 * (0.4-x) – 0.196116135138184 * (1-y) == 0;
f2 = solve(eqn,y);
f3 = 1;
y_max = 0.5;
f = piecewise(x<0.2, min(f1,y_max), 0.2<=x<0.4, min(f2,y_max), …
x>=0.4, min(f3,y_max)); %#ok<CHAIN>
% define integrand
mon = x*y;
% integration over x-y-domain limited by the boundary, y=0, x=0 and x=0.5
tic
F = int(int(mon,y,0,f),x,0,0.5);
vpa(F)
toc
tic
vpaintegral(vpaintegral(mon,y,0,f),x,0,0.5,’RelTol’, 1e-32, ‘AbsTol’, 0)
toc
I am curious whether I miss something here.Dear all,
I am currently testing the possibilities of integrating symbolic functions in Matlab. In the documentation of "int" (https://de.mathworks.com/help/symbolic/sym.int.html), I found the following statement which is not in agreement with my personal observations:
"To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances."
I run the following example and observe that a combination of "int" and "vpa" needs 0.35 secs vs. 47.69 secs in case of "vpaintegral" both having the same precision of 32 valid digits.
syms x y
% define integration boundary
f1 = 0;
eqn = 0.980580675690920 * (0.4-x) – 0.196116135138184 * (1-y) == 0;
f2 = solve(eqn,y);
f3 = 1;
y_max = 0.5;
f = piecewise(x<0.2, min(f1,y_max), 0.2<=x<0.4, min(f2,y_max), …
x>=0.4, min(f3,y_max)); %#ok<CHAIN>
% define integrand
mon = x*y;
% integration over x-y-domain limited by the boundary, y=0, x=0 and x=0.5
tic
F = int(int(mon,y,0,f),x,0,0.5);
vpa(F)
toc
tic
vpaintegral(vpaintegral(mon,y,0,f),x,0,0.5,’RelTol’, 1e-32, ‘AbsTol’, 0)
toc
I am curious whether I miss something here. Dear all,
I am currently testing the possibilities of integrating symbolic functions in Matlab. In the documentation of "int" (https://de.mathworks.com/help/symbolic/sym.int.html), I found the following statement which is not in agreement with my personal observations:
"To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and provides control over integration tolerances."
I run the following example and observe that a combination of "int" and "vpa" needs 0.35 secs vs. 47.69 secs in case of "vpaintegral" both having the same precision of 32 valid digits.
syms x y
% define integration boundary
f1 = 0;
eqn = 0.980580675690920 * (0.4-x) – 0.196116135138184 * (1-y) == 0;
f2 = solve(eqn,y);
f3 = 1;
y_max = 0.5;
f = piecewise(x<0.2, min(f1,y_max), 0.2<=x<0.4, min(f2,y_max), …
x>=0.4, min(f3,y_max)); %#ok<CHAIN>
% define integrand
mon = x*y;
% integration over x-y-domain limited by the boundary, y=0, x=0 and x=0.5
tic
F = int(int(mon,y,0,f),x,0,0.5);
vpa(F)
toc
tic
vpaintegral(vpaintegral(mon,y,0,f),x,0,0.5,’RelTol’, 1e-32, ‘AbsTol’, 0)
toc
I am curious whether I miss something here. integral, speed MATLAB Answers — New Questions