Category: Matlab
Category Archives: Matlab
Syntax for specifying boundary condition using dsolve.
I am working on a beam bending/deflection problem. The boundary conditions I need to satisfy are…
Displacement at x = 0 is 0
Slope at x = 0 is 0
Displacement at x = L is 0
Moment at x = L is 0
The code I have is below. The issue I am having is specifying the moment to be zero at x=L (syntax).
syms I E L f x u0(x)
% initial equation
eq1 = diff(E*I*diff(u0,x,2),x,2) + f == 0
% gen. sol.
eq2 = dsolve(eq1)
% part. sol.
Du0 = diff(u0,x,1); DDu0 = diff(u0,x,2);
bc1 = u0(0) == 0 % Displacement at x = 0 is 0
bc2 = Du0(0) == 0 % Slope at x = 0 is 0
bc3 = u0(L) == 0 % Displacement at x = L is 0
bc4 = DDu0(x==L) == 0 % Moment at x = L is 0
eq3 = dsolve( eq1 , [ bc1, bc2 , bc3 , bc4 ] )I am working on a beam bending/deflection problem. The boundary conditions I need to satisfy are…
Displacement at x = 0 is 0
Slope at x = 0 is 0
Displacement at x = L is 0
Moment at x = L is 0
The code I have is below. The issue I am having is specifying the moment to be zero at x=L (syntax).
syms I E L f x u0(x)
% initial equation
eq1 = diff(E*I*diff(u0,x,2),x,2) + f == 0
% gen. sol.
eq2 = dsolve(eq1)
% part. sol.
Du0 = diff(u0,x,1); DDu0 = diff(u0,x,2);
bc1 = u0(0) == 0 % Displacement at x = 0 is 0
bc2 = Du0(0) == 0 % Slope at x = 0 is 0
bc3 = u0(L) == 0 % Displacement at x = L is 0
bc4 = DDu0(x==L) == 0 % Moment at x = L is 0
eq3 = dsolve( eq1 , [ bc1, bc2 , bc3 , bc4 ] ) I am working on a beam bending/deflection problem. The boundary conditions I need to satisfy are…
Displacement at x = 0 is 0
Slope at x = 0 is 0
Displacement at x = L is 0
Moment at x = L is 0
The code I have is below. The issue I am having is specifying the moment to be zero at x=L (syntax).
syms I E L f x u0(x)
% initial equation
eq1 = diff(E*I*diff(u0,x,2),x,2) + f == 0
% gen. sol.
eq2 = dsolve(eq1)
% part. sol.
Du0 = diff(u0,x,1); DDu0 = diff(u0,x,2);
bc1 = u0(0) == 0 % Displacement at x = 0 is 0
bc2 = Du0(0) == 0 % Slope at x = 0 is 0
bc3 = u0(L) == 0 % Displacement at x = L is 0
bc4 = DDu0(x==L) == 0 % Moment at x = L is 0
eq3 = dsolve( eq1 , [ bc1, bc2 , bc3 , bc4 ] ) dsolve, syntax, beam deflection MATLAB Answers — New Questions
How can I get script’s location when running one section of a script?
I frequently run scripts one section at a time. I can be using different computers, remote desktops, etc., so the path changes. The load and save commands are relative to the present working directory rather than the directory of the script, which causes problems if the present working directory isn’t where the script is. When running a whole script, I can use either mfilename(‘fullpath’) or dbstack(‘-completenames’) to get the directory the script is in, but this doesn’t work when running a section. How can I achieve this? None of the following work:
% Returns ‘C:UsersMyNameAppDataLocalTempEditor_mddonLiveEditorEvaluationHelperE847216552.m’
stk = dbstack(‘-completenames’);
filepath = stk(1).file
% Returns ‘C:UsersMyNameAppDataLocalTempEditor_mddonLiveEditorEvaluationHelperE847216552.m’
mfilename(‘fullpath’)
% Returns wrong filename, because I’ve moved to another script by the time
% it gets to this line.
filePath = matlab.desktop.editor.getActiveFilename
If it’s impossible with MATLAB code, perhaps there is a Java-based workaround?I frequently run scripts one section at a time. I can be using different computers, remote desktops, etc., so the path changes. The load and save commands are relative to the present working directory rather than the directory of the script, which causes problems if the present working directory isn’t where the script is. When running a whole script, I can use either mfilename(‘fullpath’) or dbstack(‘-completenames’) to get the directory the script is in, but this doesn’t work when running a section. How can I achieve this? None of the following work:
% Returns ‘C:UsersMyNameAppDataLocalTempEditor_mddonLiveEditorEvaluationHelperE847216552.m’
stk = dbstack(‘-completenames’);
filepath = stk(1).file
% Returns ‘C:UsersMyNameAppDataLocalTempEditor_mddonLiveEditorEvaluationHelperE847216552.m’
mfilename(‘fullpath’)
% Returns wrong filename, because I’ve moved to another script by the time
% it gets to this line.
filePath = matlab.desktop.editor.getActiveFilename
If it’s impossible with MATLAB code, perhaps there is a Java-based workaround? I frequently run scripts one section at a time. I can be using different computers, remote desktops, etc., so the path changes. The load and save commands are relative to the present working directory rather than the directory of the script, which causes problems if the present working directory isn’t where the script is. When running a whole script, I can use either mfilename(‘fullpath’) or dbstack(‘-completenames’) to get the directory the script is in, but this doesn’t work when running a section. How can I achieve this? None of the following work:
% Returns ‘C:UsersMyNameAppDataLocalTempEditor_mddonLiveEditorEvaluationHelperE847216552.m’
stk = dbstack(‘-completenames’);
filepath = stk(1).file
% Returns ‘C:UsersMyNameAppDataLocalTempEditor_mddonLiveEditorEvaluationHelperE847216552.m’
mfilename(‘fullpath’)
% Returns wrong filename, because I’ve moved to another script by the time
% it gets to this line.
filePath = matlab.desktop.editor.getActiveFilename
If it’s impossible with MATLAB code, perhaps there is a Java-based workaround? pwd, directory, section, current directory MATLAB Answers — New Questions
Reduce width of git portion of Current Folder pane
Can I give more space to file names, and less space to the small git status icon? See attached screenshot. I don’t see any way to change the relative space allocation. I’m using MacOS if that makes a difference.Can I give more space to file names, and less space to the small git status icon? See attached screenshot. I don’t see any way to change the relative space allocation. I’m using MacOS if that makes a difference. Can I give more space to file names, and less space to the small git status icon? See attached screenshot. I don’t see any way to change the relative space allocation. I’m using MacOS if that makes a difference. current folder, git MATLAB Answers — New Questions
How to take input values from users symbolically while running a code?
o2 = [0, 0, 0]; % Origin for ain
ain = [26, 0, 0]; % Initial vector for ain
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
theta1 = deg2rad(10); % Angle of rotation for ain in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + …
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + …
(1 – cos(theta)) * (axis’ * axis);
% Compute the rotated vector for ain
a_rotated = rot_matrix(input_axis, theta1) * (ain’ – o2′) + o2′;
a_final = a_rotated’;
disp(norm(a_final));
cin=[122.95, -20, 0];
c_rotated= rot_matrix(input_axis, theta1) * (cin’ – o2′) + o2′;
naxis=[sin(theta1),0,cos(theta1)];
syms phi;
c_final_rotated=rot_matrix(naxis,phi)*(c_rotated-a_rotated)+a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0]; % Origin for bin
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
theta2 = deg2rad(10); % Angle of rotation for bin in radians
% Compute the rotated vector for bin
b1_rotated = rot_matrix(output_axis, theta2) * (bin’ – o4′) + o4′;
b1_final = b1_rotated’;
disp(norm(b1_final-o4));
coupler = c_final_rotated’-b1_final;
coupler = subs(coupler, conj(phi), phi);
%%in this code,i want to take theta1 and theta2 values from the user before from doing parametric substitution(t) given below and want to show eq in terms of theta1 and theta2 and phi
eq=norm(coupler)-106;
disp(eq);
%%after doing this ,put values of theta 1 and theta2 in
coupler = subs(coupler, conj(phi), phi);
%%and continue further as below
syms t;
cos_phi = (1 – t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp(‘Parametric form of coupler:’);
disp(coupler_parametric);
syms targetvalue % it might be 3.5 …
normsq = expand(sum(coupler_parametric.^2) – targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,’maxdegree’,4,’returnconditions’,true);
h=vpa(subs(tsolve.t,targetvalue, 106));
%disp(h);
real_solutions = h(imag(h) == 0);
disp(‘Real roots:’);
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp(‘Angles in degrees before adjustment:’);
disp(angles_deg);
phi=double(angles_rad(1));
c1_position = double(rot_matrix(naxis,phi) * (c_rotated – a_rotated) + a_rotated);
p=(c1_position’-a_final)’;
%q=(c1_position’-b1_final)’;
angle=acosd(p(2)/norm(p));
disp(angle);
%%at last i want to display value of angle for both theta1 and theta2 equal to 10 degrees
%%please help someone ,i am getting no real solution if i am taking theta1 and theta2 from user as 10 degrees but no error if i am explicitly defining like in this codeo2 = [0, 0, 0]; % Origin for ain
ain = [26, 0, 0]; % Initial vector for ain
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
theta1 = deg2rad(10); % Angle of rotation for ain in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + …
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + …
(1 – cos(theta)) * (axis’ * axis);
% Compute the rotated vector for ain
a_rotated = rot_matrix(input_axis, theta1) * (ain’ – o2′) + o2′;
a_final = a_rotated’;
disp(norm(a_final));
cin=[122.95, -20, 0];
c_rotated= rot_matrix(input_axis, theta1) * (cin’ – o2′) + o2′;
naxis=[sin(theta1),0,cos(theta1)];
syms phi;
c_final_rotated=rot_matrix(naxis,phi)*(c_rotated-a_rotated)+a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0]; % Origin for bin
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
theta2 = deg2rad(10); % Angle of rotation for bin in radians
% Compute the rotated vector for bin
b1_rotated = rot_matrix(output_axis, theta2) * (bin’ – o4′) + o4′;
b1_final = b1_rotated’;
disp(norm(b1_final-o4));
coupler = c_final_rotated’-b1_final;
coupler = subs(coupler, conj(phi), phi);
%%in this code,i want to take theta1 and theta2 values from the user before from doing parametric substitution(t) given below and want to show eq in terms of theta1 and theta2 and phi
eq=norm(coupler)-106;
disp(eq);
%%after doing this ,put values of theta 1 and theta2 in
coupler = subs(coupler, conj(phi), phi);
%%and continue further as below
syms t;
cos_phi = (1 – t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp(‘Parametric form of coupler:’);
disp(coupler_parametric);
syms targetvalue % it might be 3.5 …
normsq = expand(sum(coupler_parametric.^2) – targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,’maxdegree’,4,’returnconditions’,true);
h=vpa(subs(tsolve.t,targetvalue, 106));
%disp(h);
real_solutions = h(imag(h) == 0);
disp(‘Real roots:’);
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp(‘Angles in degrees before adjustment:’);
disp(angles_deg);
phi=double(angles_rad(1));
c1_position = double(rot_matrix(naxis,phi) * (c_rotated – a_rotated) + a_rotated);
p=(c1_position’-a_final)’;
%q=(c1_position’-b1_final)’;
angle=acosd(p(2)/norm(p));
disp(angle);
%%at last i want to display value of angle for both theta1 and theta2 equal to 10 degrees
%%please help someone ,i am getting no real solution if i am taking theta1 and theta2 from user as 10 degrees but no error if i am explicitly defining like in this code o2 = [0, 0, 0]; % Origin for ain
ain = [26, 0, 0]; % Initial vector for ain
input_axis = [0, 1, 0]; % Axis of rotation for ain (y-axis)
theta1 = deg2rad(10); % Angle of rotation for ain in radians
% Rotation matrix function
rot_matrix = @(axis, theta) cos(theta) * eye(3) + …
sin(theta) * [0, -axis(3), axis(2); axis(3), 0, -axis(1); -axis(2), axis(1), 0] + …
(1 – cos(theta)) * (axis’ * axis);
% Compute the rotated vector for ain
a_rotated = rot_matrix(input_axis, theta1) * (ain’ – o2′) + o2′;
a_final = a_rotated’;
disp(norm(a_final));
cin=[122.95, -20, 0];
c_rotated= rot_matrix(input_axis, theta1) * (cin’ – o2′) + o2′;
naxis=[sin(theta1),0,cos(theta1)];
syms phi;
c_final_rotated=rot_matrix(naxis,phi)*(c_rotated-a_rotated)+a_rotated;
bin = [29.5, 30, 0];
o4 = [13.5, 30, 0]; % Origin for bin
output_axis = [0, 1, 0]; % Axis of rotation for bin (y-axis)
theta2 = deg2rad(10); % Angle of rotation for bin in radians
% Compute the rotated vector for bin
b1_rotated = rot_matrix(output_axis, theta2) * (bin’ – o4′) + o4′;
b1_final = b1_rotated’;
disp(norm(b1_final-o4));
coupler = c_final_rotated’-b1_final;
coupler = subs(coupler, conj(phi), phi);
%%in this code,i want to take theta1 and theta2 values from the user before from doing parametric substitution(t) given below and want to show eq in terms of theta1 and theta2 and phi
eq=norm(coupler)-106;
disp(eq);
%%after doing this ,put values of theta 1 and theta2 in
coupler = subs(coupler, conj(phi), phi);
%%and continue further as below
syms t;
cos_phi = (1 – t^2) / (1 + t^2);
sin_phi = 2 * t / (1 + t^2);
% Substitute parametric forms into coupler components
coupler_parametric = subs(coupler, [cos(phi), sin(phi)], [cos_phi, sin_phi]);
% Display the parametric coupler
disp(‘Parametric form of coupler:’);
disp(coupler_parametric);
syms targetvalue % it might be 3.5 …
normsq = expand(sum(coupler_parametric.^2) – targetvalue^2);
normpoly = simplify(normsq*(t^2+1)^2);
vpa(expand(normpoly),4);
tsolve = solve(normpoly,t,’maxdegree’,4,’returnconditions’,true);
h=vpa(subs(tsolve.t,targetvalue, 106));
%disp(h);
real_solutions = h(imag(h) == 0);
disp(‘Real roots:’);
disp(real_solutions);
angles_rad = 2 * atan(real_solutions);
angles_deg = rad2deg(angles_rad);
% Display angles in degrees
disp(‘Angles in degrees before adjustment:’);
disp(angles_deg);
phi=double(angles_rad(1));
c1_position = double(rot_matrix(naxis,phi) * (c_rotated – a_rotated) + a_rotated);
p=(c1_position’-a_final)’;
%q=(c1_position’-b1_final)’;
angle=acosd(p(2)/norm(p));
disp(angle);
%%at last i want to display value of angle for both theta1 and theta2 equal to 10 degrees
%%please help someone ,i am getting no real solution if i am taking theta1 and theta2 from user as 10 degrees but no error if i am explicitly defining like in this code #symbolic, #equation MATLAB Answers — New Questions
How to extract latitude and longitudes from a table given the timestamp range?
Hello, I’m currently using a time table and want to have the user give a start time and end time then store them in variables. Once given, I want to use the timetiable to access a list of latitude and longitude values given in between those times and plot it. I’m still new to MATLAB and unsure how to approach this is ui.app designer.Hello, I’m currently using a time table and want to have the user give a start time and end time then store them in variables. Once given, I want to use the timetiable to access a list of latitude and longitude values given in between those times and plot it. I’m still new to MATLAB and unsure how to approach this is ui.app designer. Hello, I’m currently using a time table and want to have the user give a start time and end time then store them in variables. Once given, I want to use the timetiable to access a list of latitude and longitude values given in between those times and plot it. I’m still new to MATLAB and unsure how to approach this is ui.app designer. datetime, timetable, table, appdesigner, plot MATLAB Answers — New Questions
problem to install IQC toolbox
Hi everyone
I tried to install IQCtoolbox with several methods provided by available sources, but none worked well.
I got errors that are not clear.
I followed all the provided steps by
https://iqctoolbox.github.io/iqcToolbox/getting_started.html
I tried using web save, add-on, direct download,
while I type:
installIqcToolbox
it asked me to install YALMIP, I pressed y then asked to install LPSOLVE 5.5 I pressed y, then asked to install SDPT3 I pressed y but returned the error:
>> installIqcToolbox
yalmip is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
y
Installing from the fork YALMIP, Copyright (c) 2012-2021 by Johan Löfberg
y
lpsolve is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
Installing LPSOLVE 5.5, Copyright (c) 2004 – 2021 by M. Berkelaar, K. Eikland, and P. Notebaert
MEX configured to use ‘Xcode with Clang’ for C language compilation.
SDPT3 is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
y
Installing SDPT3, Copyright (c) 1997 by Kim-Chuan Toh, Michael J. Todd, and Reha H. Tutuncu
Warning: Directory already exists.
> In installIqcToolbox (line 246)
Error using assert
iqcToolbox has not been correctly installed, run installIqcToolbox first
Error in initializeIqcToolbox (line 27)
assert(install_complete,…
Error in installIqcToolbox (line 254)
initializeIqcToolbox
any help is highly appreciated,Hi everyone
I tried to install IQCtoolbox with several methods provided by available sources, but none worked well.
I got errors that are not clear.
I followed all the provided steps by
https://iqctoolbox.github.io/iqcToolbox/getting_started.html
I tried using web save, add-on, direct download,
while I type:
installIqcToolbox
it asked me to install YALMIP, I pressed y then asked to install LPSOLVE 5.5 I pressed y, then asked to install SDPT3 I pressed y but returned the error:
>> installIqcToolbox
yalmip is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
y
Installing from the fork YALMIP, Copyright (c) 2012-2021 by Johan Löfberg
y
lpsolve is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
Installing LPSOLVE 5.5, Copyright (c) 2004 – 2021 by M. Berkelaar, K. Eikland, and P. Notebaert
MEX configured to use ‘Xcode with Clang’ for C language compilation.
SDPT3 is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
y
Installing SDPT3, Copyright (c) 1997 by Kim-Chuan Toh, Michael J. Todd, and Reha H. Tutuncu
Warning: Directory already exists.
> In installIqcToolbox (line 246)
Error using assert
iqcToolbox has not been correctly installed, run installIqcToolbox first
Error in initializeIqcToolbox (line 27)
assert(install_complete,…
Error in installIqcToolbox (line 254)
initializeIqcToolbox
any help is highly appreciated, Hi everyone
I tried to install IQCtoolbox with several methods provided by available sources, but none worked well.
I got errors that are not clear.
I followed all the provided steps by
https://iqctoolbox.github.io/iqcToolbox/getting_started.html
I tried using web save, add-on, direct download,
while I type:
installIqcToolbox
it asked me to install YALMIP, I pressed y then asked to install LPSOLVE 5.5 I pressed y, then asked to install SDPT3 I pressed y but returned the error:
>> installIqcToolbox
yalmip is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
y
Installing from the fork YALMIP, Copyright (c) 2012-2021 by Johan Löfberg
y
lpsolve is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
Installing LPSOLVE 5.5, Copyright (c) 2004 – 2021 by M. Berkelaar, K. Eikland, and P. Notebaert
MEX configured to use ‘Xcode with Clang’ for C language compilation.
SDPT3 is not detected on your system and must be installed. Do you wish to install? [‘y’/’n’]
y
Installing SDPT3, Copyright (c) 1997 by Kim-Chuan Toh, Michael J. Todd, and Reha H. Tutuncu
Warning: Directory already exists.
> In installIqcToolbox (line 246)
Error using assert
iqcToolbox has not been correctly installed, run installIqcToolbox first
Error in initializeIqcToolbox (line 27)
assert(install_complete,…
Error in installIqcToolbox (line 254)
initializeIqcToolbox
any help is highly appreciated, iqc, iqctoolbox MATLAB Answers — New Questions
Why do I get a “libXt.so.6: cannot open shared object file” error when trying to open any “.ctf” apps on my MATLAB R2024a Web App Server Running on CentOS?
I have a web app server running on CentOS 9 which seems to start and run normally. I can upload ".ctf" file to my server and they successfully show up on my web app server with their status listed as "ok". However, when I click on one of the apps to open it, it does not open, and eventually I receive the error:
Something went wrong. Click "OK" or refresh to page to restart the app
After enabling verbose logging on my server and looking at the "webapps_launcher_<timestamp>.log" log I see multiple occurrences of this error:
Error loading /usr/local/MATLAB/MATLAB_Runtime/R2023b/bin/glnxa64/matlab_startup_plugins/matlab_graphics_ui/mwuixloader.so. libXt.so.6: cannot open shared object file: No such file or directory
What is this error and why can’t I open applications on my web app server?I have a web app server running on CentOS 9 which seems to start and run normally. I can upload ".ctf" file to my server and they successfully show up on my web app server with their status listed as "ok". However, when I click on one of the apps to open it, it does not open, and eventually I receive the error:
Something went wrong. Click "OK" or refresh to page to restart the app
After enabling verbose logging on my server and looking at the "webapps_launcher_<timestamp>.log" log I see multiple occurrences of this error:
Error loading /usr/local/MATLAB/MATLAB_Runtime/R2023b/bin/glnxa64/matlab_startup_plugins/matlab_graphics_ui/mwuixloader.so. libXt.so.6: cannot open shared object file: No such file or directory
What is this error and why can’t I open applications on my web app server? I have a web app server running on CentOS 9 which seems to start and run normally. I can upload ".ctf" file to my server and they successfully show up on my web app server with their status listed as "ok". However, when I click on one of the apps to open it, it does not open, and eventually I receive the error:
Something went wrong. Click "OK" or refresh to page to restart the app
After enabling verbose logging on my server and looking at the "webapps_launcher_<timestamp>.log" log I see multiple occurrences of this error:
Error loading /usr/local/MATLAB/MATLAB_Runtime/R2023b/bin/glnxa64/matlab_startup_plugins/matlab_graphics_ui/mwuixloader.so. libXt.so.6: cannot open shared object file: No such file or directory
What is this error and why can’t I open applications on my web app server? webappserver, centos, linux, libxt6 MATLAB Answers — New Questions
Python function call from Matlab – error occurred “Conversion to int64 from py.NoneType is not possible.”
I want to call a python function from Matlab.
I have two Python files. one file can call the other file. The content of the file named, calculation.py is as follows
def addNumbers(a, b):
print("Sum is ", a + b)
def subtractNumbers(a, b):
print("Difference is ", a – b)
def multiplyNumbers(a, b):
print("Product is ", a * b)
def divideNumbers(a, b):
print("Division is ", a / b)
def modulusNumbers(a, b):
print("Remainder is ", a % b)
The content of the another python file named call_file.py is as follows
from calculation import addNumbers, multiplyNumbers
I wrote a matlab code to call call_flie.py. The matlab code is as follows
pyenv
path_add = fileparts(which("call_file.py"))
if count(py.sys.path,path_add)==0
insert(py.sys.path,int64(0),path_add)
end
pyOut = py.call_file.addNumbers(5, 2);
sum = int64(pyOut);
disp(sum)
I received the error "Error using int64
Conversion to int64 from py.NoneType is not possible.
Error in Test1 (line 8)
sum = int64(pyOut);
"
How can I solve the error?
Thank you.I want to call a python function from Matlab.
I have two Python files. one file can call the other file. The content of the file named, calculation.py is as follows
def addNumbers(a, b):
print("Sum is ", a + b)
def subtractNumbers(a, b):
print("Difference is ", a – b)
def multiplyNumbers(a, b):
print("Product is ", a * b)
def divideNumbers(a, b):
print("Division is ", a / b)
def modulusNumbers(a, b):
print("Remainder is ", a % b)
The content of the another python file named call_file.py is as follows
from calculation import addNumbers, multiplyNumbers
I wrote a matlab code to call call_flie.py. The matlab code is as follows
pyenv
path_add = fileparts(which("call_file.py"))
if count(py.sys.path,path_add)==0
insert(py.sys.path,int64(0),path_add)
end
pyOut = py.call_file.addNumbers(5, 2);
sum = int64(pyOut);
disp(sum)
I received the error "Error using int64
Conversion to int64 from py.NoneType is not possible.
Error in Test1 (line 8)
sum = int64(pyOut);
"
How can I solve the error?
Thank you. I want to call a python function from Matlab.
I have two Python files. one file can call the other file. The content of the file named, calculation.py is as follows
def addNumbers(a, b):
print("Sum is ", a + b)
def subtractNumbers(a, b):
print("Difference is ", a – b)
def multiplyNumbers(a, b):
print("Product is ", a * b)
def divideNumbers(a, b):
print("Division is ", a / b)
def modulusNumbers(a, b):
print("Remainder is ", a % b)
The content of the another python file named call_file.py is as follows
from calculation import addNumbers, multiplyNumbers
I wrote a matlab code to call call_flie.py. The matlab code is as follows
pyenv
path_add = fileparts(which("call_file.py"))
if count(py.sys.path,path_add)==0
insert(py.sys.path,int64(0),path_add)
end
pyOut = py.call_file.addNumbers(5, 2);
sum = int64(pyOut);
disp(sum)
I received the error "Error using int64
Conversion to int64 from py.NoneType is not possible.
Error in Test1 (line 8)
sum = int64(pyOut);
"
How can I solve the error?
Thank you. python, matlab MATLAB Answers — New Questions
Solving all math and teaching it as you go
Hello MATLAB community,
I have another mission for my project and I am trying to get it started.
So the objective is to make a code that can solve math problems but also show you how to solve the input math problem. I know there is certain ways to solve some math problem (adding, subtracting ,etc) however when it get to the gritty of things I would like to make it so go step by step solving problems. Like derivative or finding varibles etc.
I was hopping to have a options on how to input the problem in the code and code solves it but shows how to solve it.
DOes anyone have any idea or suggest or example to get me started and moving?
Thank youHello MATLAB community,
I have another mission for my project and I am trying to get it started.
So the objective is to make a code that can solve math problems but also show you how to solve the input math problem. I know there is certain ways to solve some math problem (adding, subtracting ,etc) however when it get to the gritty of things I would like to make it so go step by step solving problems. Like derivative or finding varibles etc.
I was hopping to have a options on how to input the problem in the code and code solves it but shows how to solve it.
DOes anyone have any idea or suggest or example to get me started and moving?
Thank you Hello MATLAB community,
I have another mission for my project and I am trying to get it started.
So the objective is to make a code that can solve math problems but also show you how to solve the input math problem. I know there is certain ways to solve some math problem (adding, subtracting ,etc) however when it get to the gritty of things I would like to make it so go step by step solving problems. Like derivative or finding varibles etc.
I was hopping to have a options on how to input the problem in the code and code solves it but shows how to solve it.
DOes anyone have any idea or suggest or example to get me started and moving?
Thank you solve, mathematics, numerical integration, calculus MATLAB Answers — New Questions
StartPoint on Curve Fitting Toolbox
I am trying to fit a linear resonance curve of a 2nd order mechanical system to get the Q-factor.
The instrument that I am using to obtain the frequency response function has an in-built curve fitting software that uses the following equation to fit the curve.
denominator = sqrt(f^2 + (Q / f0)^2 * (f^2 – f0^2)^2);
X=A * f / denominator;
(C=0) *image q2.png
A is the amplitude, 𝑄 is the quality factor and 𝑓0 is the center frequency.
My goal is to use MATLAB’s Curve Fitting tool to obtain the Q-factor value; first I want to match the Q-factor value obtained from the instrument (as a validation step, so I can fit more data without requiring the instrument’s curve fitting tool).
Below is the FRF obtained from the instrument–the Q factor value I obtain is 8705.9559
*image q1.png
Center Frequency (f0) = 1496.26
A = 2.4216e-3 (amplitude)
I saved this sweep and plotted and tried to recreate the this fit using the CurveFitting tool box–using the same cut-off range as above (1453 kHz to 1548 kHz)
However, I am having an issue with converging to the value for the Q-factor from the instrument–it varies as I change my StartPoint and Lower and Upper values. I understand this is the case, sensitive to inital conditions–however, I was under the assumption that it may converge to the value as I refine my StartPoint and Lower and Upper bounds—this is not the case.
For example:
With StartPoint= 0; Lower= 10; Upper= 10e3 Q=8052 (7994, 8110) with R-square of 0.9961
moving the StartPoint closer to 8000 (which is around the actual value), it drops
With StartPoint = 7000; Lower=10; Upper= 10e3 Q=8278 (8228, 8329) with R-square of 0.9973
With StartPoint= 8000; Lower= 10; Upper= 10e3 Q=8000 (7940, 8060) with R-square of 0.9961
(varying the Upper and Lower bounds also causes the Q factor value to change–and not converge–to different values that is around value obtained from the instrument)
–I was hoping to get closer and improve the goodness of fit, but the fit is very sensitive to the StartPoint—any pointers on how to get an accurate value?
Is this method, fitting this curve using the CurveFitting Toolbox the best method to get the value for Q?
I have shared my data, code and image snippets. Any pointers appreciated.
clc;clear;close all
data = load(‘data.mat’);
f=data.d(:,1);
A=data.d(:,2);
[fitresult, gof] = createFit(f, A)
function [fitresult, gof] = createFit(f, A)
%CREATEFIT(F,A)
% Create a fit.
%
% Data for ‘untitled fit 1’ fit:
% X Input: f
% Y Output: A
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 12-Jun-2024 17:27:38
%% Fit: ‘untitled fit 1’.
[xData, yData] = prepareCurveData( f, A );
% Set up fittype and options.
ft = fittype( ‘2.4216e-3*f./(sqrt(f^2+(Q/1496.26)^2*(f^2-1496.26^2)^2))’, ‘independent’, ‘f’, ‘dependent’, ‘A’ );
excludedPoints = (xData < 1426.9) | (xData > 1570.4);
opts = fitoptions( ‘Method’, ‘NonlinearLeastSquares’ );
opts.Display = ‘Off’;
opts.Lower = 10;
opts.MaxFunEvals = 1000;
opts.MaxIter = 1000;
opts.StartPoint = 7000;
opts.TolFun = 1e-07;
opts.Upper = 10000;
opts.Exclude = excludedPoints;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( ‘Name’, ‘untitled fit 1’ );
h = plot( fitresult, xData, yData, excludedPoints );
legend( h, ‘A vs. f’, ‘Excluded A vs. f’, ‘untitled fit 1’, ‘Location’, ‘NorthEast’, ‘Interpreter’, ‘none’ );
% Label axes
xlabel( ‘f’, ‘Interpreter’, ‘none’ );
ylabel( ‘A’, ‘Interpreter’, ‘none’ );
grid on
end
TL;DR–I am trying to understand why the value of Q, obtained from my fit, does not converge to a value (and improve the fit) as I use a guess that is around the accurate value, and reduce the size of the bounds (Lower and Upper)I am trying to fit a linear resonance curve of a 2nd order mechanical system to get the Q-factor.
The instrument that I am using to obtain the frequency response function has an in-built curve fitting software that uses the following equation to fit the curve.
denominator = sqrt(f^2 + (Q / f0)^2 * (f^2 – f0^2)^2);
X=A * f / denominator;
(C=0) *image q2.png
A is the amplitude, 𝑄 is the quality factor and 𝑓0 is the center frequency.
My goal is to use MATLAB’s Curve Fitting tool to obtain the Q-factor value; first I want to match the Q-factor value obtained from the instrument (as a validation step, so I can fit more data without requiring the instrument’s curve fitting tool).
Below is the FRF obtained from the instrument–the Q factor value I obtain is 8705.9559
*image q1.png
Center Frequency (f0) = 1496.26
A = 2.4216e-3 (amplitude)
I saved this sweep and plotted and tried to recreate the this fit using the CurveFitting tool box–using the same cut-off range as above (1453 kHz to 1548 kHz)
However, I am having an issue with converging to the value for the Q-factor from the instrument–it varies as I change my StartPoint and Lower and Upper values. I understand this is the case, sensitive to inital conditions–however, I was under the assumption that it may converge to the value as I refine my StartPoint and Lower and Upper bounds—this is not the case.
For example:
With StartPoint= 0; Lower= 10; Upper= 10e3 Q=8052 (7994, 8110) with R-square of 0.9961
moving the StartPoint closer to 8000 (which is around the actual value), it drops
With StartPoint = 7000; Lower=10; Upper= 10e3 Q=8278 (8228, 8329) with R-square of 0.9973
With StartPoint= 8000; Lower= 10; Upper= 10e3 Q=8000 (7940, 8060) with R-square of 0.9961
(varying the Upper and Lower bounds also causes the Q factor value to change–and not converge–to different values that is around value obtained from the instrument)
–I was hoping to get closer and improve the goodness of fit, but the fit is very sensitive to the StartPoint—any pointers on how to get an accurate value?
Is this method, fitting this curve using the CurveFitting Toolbox the best method to get the value for Q?
I have shared my data, code and image snippets. Any pointers appreciated.
clc;clear;close all
data = load(‘data.mat’);
f=data.d(:,1);
A=data.d(:,2);
[fitresult, gof] = createFit(f, A)
function [fitresult, gof] = createFit(f, A)
%CREATEFIT(F,A)
% Create a fit.
%
% Data for ‘untitled fit 1’ fit:
% X Input: f
% Y Output: A
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 12-Jun-2024 17:27:38
%% Fit: ‘untitled fit 1’.
[xData, yData] = prepareCurveData( f, A );
% Set up fittype and options.
ft = fittype( ‘2.4216e-3*f./(sqrt(f^2+(Q/1496.26)^2*(f^2-1496.26^2)^2))’, ‘independent’, ‘f’, ‘dependent’, ‘A’ );
excludedPoints = (xData < 1426.9) | (xData > 1570.4);
opts = fitoptions( ‘Method’, ‘NonlinearLeastSquares’ );
opts.Display = ‘Off’;
opts.Lower = 10;
opts.MaxFunEvals = 1000;
opts.MaxIter = 1000;
opts.StartPoint = 7000;
opts.TolFun = 1e-07;
opts.Upper = 10000;
opts.Exclude = excludedPoints;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( ‘Name’, ‘untitled fit 1’ );
h = plot( fitresult, xData, yData, excludedPoints );
legend( h, ‘A vs. f’, ‘Excluded A vs. f’, ‘untitled fit 1’, ‘Location’, ‘NorthEast’, ‘Interpreter’, ‘none’ );
% Label axes
xlabel( ‘f’, ‘Interpreter’, ‘none’ );
ylabel( ‘A’, ‘Interpreter’, ‘none’ );
grid on
end
TL;DR–I am trying to understand why the value of Q, obtained from my fit, does not converge to a value (and improve the fit) as I use a guess that is around the accurate value, and reduce the size of the bounds (Lower and Upper) I am trying to fit a linear resonance curve of a 2nd order mechanical system to get the Q-factor.
The instrument that I am using to obtain the frequency response function has an in-built curve fitting software that uses the following equation to fit the curve.
denominator = sqrt(f^2 + (Q / f0)^2 * (f^2 – f0^2)^2);
X=A * f / denominator;
(C=0) *image q2.png
A is the amplitude, 𝑄 is the quality factor and 𝑓0 is the center frequency.
My goal is to use MATLAB’s Curve Fitting tool to obtain the Q-factor value; first I want to match the Q-factor value obtained from the instrument (as a validation step, so I can fit more data without requiring the instrument’s curve fitting tool).
Below is the FRF obtained from the instrument–the Q factor value I obtain is 8705.9559
*image q1.png
Center Frequency (f0) = 1496.26
A = 2.4216e-3 (amplitude)
I saved this sweep and plotted and tried to recreate the this fit using the CurveFitting tool box–using the same cut-off range as above (1453 kHz to 1548 kHz)
However, I am having an issue with converging to the value for the Q-factor from the instrument–it varies as I change my StartPoint and Lower and Upper values. I understand this is the case, sensitive to inital conditions–however, I was under the assumption that it may converge to the value as I refine my StartPoint and Lower and Upper bounds—this is not the case.
For example:
With StartPoint= 0; Lower= 10; Upper= 10e3 Q=8052 (7994, 8110) with R-square of 0.9961
moving the StartPoint closer to 8000 (which is around the actual value), it drops
With StartPoint = 7000; Lower=10; Upper= 10e3 Q=8278 (8228, 8329) with R-square of 0.9973
With StartPoint= 8000; Lower= 10; Upper= 10e3 Q=8000 (7940, 8060) with R-square of 0.9961
(varying the Upper and Lower bounds also causes the Q factor value to change–and not converge–to different values that is around value obtained from the instrument)
–I was hoping to get closer and improve the goodness of fit, but the fit is very sensitive to the StartPoint—any pointers on how to get an accurate value?
Is this method, fitting this curve using the CurveFitting Toolbox the best method to get the value for Q?
I have shared my data, code and image snippets. Any pointers appreciated.
clc;clear;close all
data = load(‘data.mat’);
f=data.d(:,1);
A=data.d(:,2);
[fitresult, gof] = createFit(f, A)
function [fitresult, gof] = createFit(f, A)
%CREATEFIT(F,A)
% Create a fit.
%
% Data for ‘untitled fit 1’ fit:
% X Input: f
% Y Output: A
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 12-Jun-2024 17:27:38
%% Fit: ‘untitled fit 1’.
[xData, yData] = prepareCurveData( f, A );
% Set up fittype and options.
ft = fittype( ‘2.4216e-3*f./(sqrt(f^2+(Q/1496.26)^2*(f^2-1496.26^2)^2))’, ‘independent’, ‘f’, ‘dependent’, ‘A’ );
excludedPoints = (xData < 1426.9) | (xData > 1570.4);
opts = fitoptions( ‘Method’, ‘NonlinearLeastSquares’ );
opts.Display = ‘Off’;
opts.Lower = 10;
opts.MaxFunEvals = 1000;
opts.MaxIter = 1000;
opts.StartPoint = 7000;
opts.TolFun = 1e-07;
opts.Upper = 10000;
opts.Exclude = excludedPoints;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( ‘Name’, ‘untitled fit 1’ );
h = plot( fitresult, xData, yData, excludedPoints );
legend( h, ‘A vs. f’, ‘Excluded A vs. f’, ‘untitled fit 1’, ‘Location’, ‘NorthEast’, ‘Interpreter’, ‘none’ );
% Label axes
xlabel( ‘f’, ‘Interpreter’, ‘none’ );
ylabel( ‘A’, ‘Interpreter’, ‘none’ );
grid on
end
TL;DR–I am trying to understand why the value of Q, obtained from my fit, does not converge to a value (and improve the fit) as I use a guess that is around the accurate value, and reduce the size of the bounds (Lower and Upper) curve fitting MATLAB Answers — New Questions
The maximum value is not changing even after adding 1
I have an image with values ranging from [0,255]
It’s data is attached below as data.mat below.
I read it and added 1 to its data.
The minimum value of data is changed to 1, but the maximum value of data is still 255.
I don’t understand why.I have an image with values ranging from [0,255]
It’s data is attached below as data.mat below.
I read it and added 1 to its data.
The minimum value of data is changed to 1, but the maximum value of data is still 255.
I don’t understand why. I have an image with values ranging from [0,255]
It’s data is attached below as data.mat below.
I read it and added 1 to its data.
The minimum value of data is changed to 1, but the maximum value of data is still 255.
I don’t understand why. add, max, min, value MATLAB Answers — New Questions
Uistack with GraphPlot (it looks like not working)
I have a GraphPlot array. Some of the GraphPlots have a name. Other GraphPlots, instead, do not have a name. I am trying to reorder the visual stacking of those GraphPlots by using their names, i.e. all the GraphPlots that have a name need to go to the top.
However, If I use
uistack(h(idx),’top’)
nothing changes.
How can I reorder that GraphPlot array, in such a way that GraphPlots without a name go to the bottom of the visual stacking and GraphPlots with a name go to the top?
I reproduced something similar to my case, with 5 Graphplots:
c = {‘b’,’k’,’m’,’y’,’r’};
s = [1 1 1 1 1 1 1 9 9 9 9 9 9 9];
name = {‘apple’,”,”,’banana’,’peach’};
% generate 5 arrays of t = randi([2 8],5,14);
t = [
3 3 4 5 4 6 8 6 2 5 2 8 3 2
6 3 5 5 6 4 5 3 3 2 6 7 6 5
5 7 6 2 2 7 7 8 2 5 5 8 5 8
7 8 6 7 4 4 3 5 6 4 2 8 3 2
7 8 4 8 8 5 6 8 6 5 6 7 4 2];
hold on
for i = 1 : size(t,1)
h(i) = plot(graph(s,t(i,:)),’LineWidth’,3,’EdgeColor’,c{i},’NodeColor’,c{i},’DisplayName’,name{i});
h(i).EdgeAlpha=1;
end
names_plots = {h.DisplayName};
idx = find(~cellfun(@isempty,names_plots));
uistack(h(idx),’top’)
legend(h)I have a GraphPlot array. Some of the GraphPlots have a name. Other GraphPlots, instead, do not have a name. I am trying to reorder the visual stacking of those GraphPlots by using their names, i.e. all the GraphPlots that have a name need to go to the top.
However, If I use
uistack(h(idx),’top’)
nothing changes.
How can I reorder that GraphPlot array, in such a way that GraphPlots without a name go to the bottom of the visual stacking and GraphPlots with a name go to the top?
I reproduced something similar to my case, with 5 Graphplots:
c = {‘b’,’k’,’m’,’y’,’r’};
s = [1 1 1 1 1 1 1 9 9 9 9 9 9 9];
name = {‘apple’,”,”,’banana’,’peach’};
% generate 5 arrays of t = randi([2 8],5,14);
t = [
3 3 4 5 4 6 8 6 2 5 2 8 3 2
6 3 5 5 6 4 5 3 3 2 6 7 6 5
5 7 6 2 2 7 7 8 2 5 5 8 5 8
7 8 6 7 4 4 3 5 6 4 2 8 3 2
7 8 4 8 8 5 6 8 6 5 6 7 4 2];
hold on
for i = 1 : size(t,1)
h(i) = plot(graph(s,t(i,:)),’LineWidth’,3,’EdgeColor’,c{i},’NodeColor’,c{i},’DisplayName’,name{i});
h(i).EdgeAlpha=1;
end
names_plots = {h.DisplayName};
idx = find(~cellfun(@isempty,names_plots));
uistack(h(idx),’top’)
legend(h) I have a GraphPlot array. Some of the GraphPlots have a name. Other GraphPlots, instead, do not have a name. I am trying to reorder the visual stacking of those GraphPlots by using their names, i.e. all the GraphPlots that have a name need to go to the top.
However, If I use
uistack(h(idx),’top’)
nothing changes.
How can I reorder that GraphPlot array, in such a way that GraphPlots without a name go to the bottom of the visual stacking and GraphPlots with a name go to the top?
I reproduced something similar to my case, with 5 Graphplots:
c = {‘b’,’k’,’m’,’y’,’r’};
s = [1 1 1 1 1 1 1 9 9 9 9 9 9 9];
name = {‘apple’,”,”,’banana’,’peach’};
% generate 5 arrays of t = randi([2 8],5,14);
t = [
3 3 4 5 4 6 8 6 2 5 2 8 3 2
6 3 5 5 6 4 5 3 3 2 6 7 6 5
5 7 6 2 2 7 7 8 2 5 5 8 5 8
7 8 6 7 4 4 3 5 6 4 2 8 3 2
7 8 4 8 8 5 6 8 6 5 6 7 4 2];
hold on
for i = 1 : size(t,1)
h(i) = plot(graph(s,t(i,:)),’LineWidth’,3,’EdgeColor’,c{i},’NodeColor’,c{i},’DisplayName’,name{i});
h(i).EdgeAlpha=1;
end
names_plots = {h.DisplayName};
idx = find(~cellfun(@isempty,names_plots));
uistack(h(idx),’top’)
legend(h) uistack, reorder, graphplots, visual stacking, stacking, order, plots MATLAB Answers — New Questions
Apply 2-D logical mask to obtain masked third dimension values in 3-D array
This is difficult to describe in words so I have given an example below. I have a 3-D array. Some of the values are NaNs (although this is not directly relevant to my question). I want to apply a 2-D mask to the first two dimensions and arrange all the third dimensions behind the mask as sequential rows in a 2-D array. I’m looking for a way to do this without ‘for’ loops.
Here’s the example:
% Set up the example 3-D array and mask
BW = logical([0,0,1; 0,1,1; 1,1,0; 1,0,0]); %create a mask
A = 9*ones(4,3,3); % create a 3 dimensional array
A(:,:,2) = 8*ones(4,3); % Make the second ‘slice’ 8s
A(:,:,3) = 7*ones(4,3); % Make the third ‘slice’ 8s
A(1,3,1) = NaN; % add a NaN
A(3,2,3) = NaN; % add another NaN
A(4,1,2) = NaN % add another NaN
% Apply the mask and organise the masked third dimension values into a 2-D array
my2Darray = zeros(1,size(A,3));
for row=1:(size(A,1))
for col=1:(size(A,2))
if (BW(row,col))
mySpectrum = squeeze (A(row, col,:))’;
my2Darray = cat (1, my2Darray, mySpectrum);
end
end
end
my2Darray(1,:) = [] % Get rid of the first row of zeros
The outcome is correct. The total number of rows in my2Darray should be equal to sum(sum(BW)).
But is there an elegant way to reshape this that doesn’t require the ‘for’ loops, please?This is difficult to describe in words so I have given an example below. I have a 3-D array. Some of the values are NaNs (although this is not directly relevant to my question). I want to apply a 2-D mask to the first two dimensions and arrange all the third dimensions behind the mask as sequential rows in a 2-D array. I’m looking for a way to do this without ‘for’ loops.
Here’s the example:
% Set up the example 3-D array and mask
BW = logical([0,0,1; 0,1,1; 1,1,0; 1,0,0]); %create a mask
A = 9*ones(4,3,3); % create a 3 dimensional array
A(:,:,2) = 8*ones(4,3); % Make the second ‘slice’ 8s
A(:,:,3) = 7*ones(4,3); % Make the third ‘slice’ 8s
A(1,3,1) = NaN; % add a NaN
A(3,2,3) = NaN; % add another NaN
A(4,1,2) = NaN % add another NaN
% Apply the mask and organise the masked third dimension values into a 2-D array
my2Darray = zeros(1,size(A,3));
for row=1:(size(A,1))
for col=1:(size(A,2))
if (BW(row,col))
mySpectrum = squeeze (A(row, col,:))’;
my2Darray = cat (1, my2Darray, mySpectrum);
end
end
end
my2Darray(1,:) = [] % Get rid of the first row of zeros
The outcome is correct. The total number of rows in my2Darray should be equal to sum(sum(BW)).
But is there an elegant way to reshape this that doesn’t require the ‘for’ loops, please? This is difficult to describe in words so I have given an example below. I have a 3-D array. Some of the values are NaNs (although this is not directly relevant to my question). I want to apply a 2-D mask to the first two dimensions and arrange all the third dimensions behind the mask as sequential rows in a 2-D array. I’m looking for a way to do this without ‘for’ loops.
Here’s the example:
% Set up the example 3-D array and mask
BW = logical([0,0,1; 0,1,1; 1,1,0; 1,0,0]); %create a mask
A = 9*ones(4,3,3); % create a 3 dimensional array
A(:,:,2) = 8*ones(4,3); % Make the second ‘slice’ 8s
A(:,:,3) = 7*ones(4,3); % Make the third ‘slice’ 8s
A(1,3,1) = NaN; % add a NaN
A(3,2,3) = NaN; % add another NaN
A(4,1,2) = NaN % add another NaN
% Apply the mask and organise the masked third dimension values into a 2-D array
my2Darray = zeros(1,size(A,3));
for row=1:(size(A,1))
for col=1:(size(A,2))
if (BW(row,col))
mySpectrum = squeeze (A(row, col,:))’;
my2Darray = cat (1, my2Darray, mySpectrum);
end
end
end
my2Darray(1,:) = [] % Get rid of the first row of zeros
The outcome is correct. The total number of rows in my2Darray should be equal to sum(sum(BW)).
But is there an elegant way to reshape this that doesn’t require the ‘for’ loops, please? mask, array, reshape MATLAB Answers — New Questions
Problem with converting a value into double
I read 2 matrix from txt files, for example, two 2×3 matrix A=[740 850 550 ; 830 820 200 ] B=[742 851 552 ; 835 818 220 ]
and want to calculate A-B, but in the 2×3 ans, all nubmers are zeros ans= [0 0 0; 0 0 0]
I tried to convert them to double using double(A), double(B), but it doesn’t work
Also I tried several things
A+1 gives me 0.001*(A+1), also, say [0.0741 0.0851 0.0551; 0.0831 0.0821 0.0201]
A+0.1 gives me 0.001*(A), also, say [0.0740 0.0850 0.0550; 0.0830 0.0820 0.0200]
even after A=double(A), then do A+1, it gives me the same values as listed in 1
Can anyone help me to solve this?I read 2 matrix from txt files, for example, two 2×3 matrix A=[740 850 550 ; 830 820 200 ] B=[742 851 552 ; 835 818 220 ]
and want to calculate A-B, but in the 2×3 ans, all nubmers are zeros ans= [0 0 0; 0 0 0]
I tried to convert them to double using double(A), double(B), but it doesn’t work
Also I tried several things
A+1 gives me 0.001*(A+1), also, say [0.0741 0.0851 0.0551; 0.0831 0.0821 0.0201]
A+0.1 gives me 0.001*(A), also, say [0.0740 0.0850 0.0550; 0.0830 0.0820 0.0200]
even after A=double(A), then do A+1, it gives me the same values as listed in 1
Can anyone help me to solve this? I read 2 matrix from txt files, for example, two 2×3 matrix A=[740 850 550 ; 830 820 200 ] B=[742 851 552 ; 835 818 220 ]
and want to calculate A-B, but in the 2×3 ans, all nubmers are zeros ans= [0 0 0; 0 0 0]
I tried to convert them to double using double(A), double(B), but it doesn’t work
Also I tried several things
A+1 gives me 0.001*(A+1), also, say [0.0741 0.0851 0.0551; 0.0831 0.0821 0.0201]
A+0.1 gives me 0.001*(A), also, say [0.0740 0.0850 0.0550; 0.0830 0.0820 0.0200]
even after A=double(A), then do A+1, it gives me the same values as listed in 1
Can anyone help me to solve this? double, matlab, unit MATLAB Answers — New Questions
How can i make 3D graph with multiple 2D graphs?
I made R0-SOC graph at various C values in 2D figure. Now, how can I make 3D figure about R0 for SOC,C values? Which makes me hard to figure it out is that 0.05C, 0.1C, 1/3C has 17 values and 1C and 2C have 13 values.
The output would look like this one.
Thank you for your help.I made R0-SOC graph at various C values in 2D figure. Now, how can I make 3D figure about R0 for SOC,C values? Which makes me hard to figure it out is that 0.05C, 0.1C, 1/3C has 17 values and 1C and 2C have 13 values.
The output would look like this one.
Thank you for your help. I made R0-SOC graph at various C values in 2D figure. Now, how can I make 3D figure about R0 for SOC,C values? Which makes me hard to figure it out is that 0.05C, 0.1C, 1/3C has 17 values and 1C and 2C have 13 values.
The output would look like this one.
Thank you for your help. 3d plots, interpolation MATLAB Answers — New Questions
Parsing Through HTLM Style .txt File
I’m trying to read in a txt file with a series of messages describing what is happening during a sporting event. The general format seems to be based on HTML but the file is given as .txt. I’m able to open the file and save it as a variable using fscanf (not sure if this is the most appropiate way for this application). I’m having trouble wrapping my head around how to search for blocks of code that I want to record for further analysis. For example one of things ill be doing is looking for a block like the one below.
<FLAG>
<ID>e9f40b4b-decd-4b47-ae83-e6f9c972c570</ID>
<DT>01.07.2023 16:30:00.000</DT>
<FL>Green</FL>
<LV>Track</LV>
<FI />
</FLAG>
So in plain English i want to look for every time there is <FLAG> and then record the time of day which is denoted by <DT>. I’m pretty rusty with my MATLAB never any reading from .txt files when i was at my best so I think once I get the hand of reading and searching through the file I’ll be able to figure it all out from there.I’m trying to read in a txt file with a series of messages describing what is happening during a sporting event. The general format seems to be based on HTML but the file is given as .txt. I’m able to open the file and save it as a variable using fscanf (not sure if this is the most appropiate way for this application). I’m having trouble wrapping my head around how to search for blocks of code that I want to record for further analysis. For example one of things ill be doing is looking for a block like the one below.
<FLAG>
<ID>e9f40b4b-decd-4b47-ae83-e6f9c972c570</ID>
<DT>01.07.2023 16:30:00.000</DT>
<FL>Green</FL>
<LV>Track</LV>
<FI />
</FLAG>
So in plain English i want to look for every time there is <FLAG> and then record the time of day which is denoted by <DT>. I’m pretty rusty with my MATLAB never any reading from .txt files when i was at my best so I think once I get the hand of reading and searching through the file I’ll be able to figure it all out from there. I’m trying to read in a txt file with a series of messages describing what is happening during a sporting event. The general format seems to be based on HTML but the file is given as .txt. I’m able to open the file and save it as a variable using fscanf (not sure if this is the most appropiate way for this application). I’m having trouble wrapping my head around how to search for blocks of code that I want to record for further analysis. For example one of things ill be doing is looking for a block like the one below.
<FLAG>
<ID>e9f40b4b-decd-4b47-ae83-e6f9c972c570</ID>
<DT>01.07.2023 16:30:00.000</DT>
<FL>Green</FL>
<LV>Track</LV>
<FI />
</FLAG>
So in plain English i want to look for every time there is <FLAG> and then record the time of day which is denoted by <DT>. I’m pretty rusty with my MATLAB never any reading from .txt files when i was at my best so I think once I get the hand of reading and searching through the file I’ll be able to figure it all out from there. .txt, html, read, parse MATLAB Answers — New Questions
Error in user-supplied fitness function evaluation – Genetic Algorithm
Hello everyone. I am currently using the ga function in order to find the best parameters for a discrete GPC controller. However, more often than not, the execution of this algorithm ends up in error.
First, let me show the fitness function that I am currently using:
function J = simplanta(individuo)
Np = individuo(1);
Nc = individuo(2);
rw = individuo(3);
ts=1/2000; % sampling time
t=0:ts:1; % sim time
f0=50;
r=1+1.5.*sin(2*pi*f0*t); % reference signal
Ldata=length(t); % # of time points
%Discrete Model
Ad =[0.4134 0.4536 0; -0.2404 0.7876 0; -0.4366 0.4224 0.7738];
Bd =[0.1331; 0.4528; 0.1273];
Cd=[0 0 1];
% Specified Gain Calc
n=length(Ad); %order%
Omega = 2*pi*f0*ts;
gamma = ( 2*cos(Omega) ) + 1;
E=[0 1 0; 0 0 1; 1 -gamma gamma];
sigma = [0;0;1];
% prediction matrices
A=[Ad zeros(n,3); sigma*Cd*Ad E];
B=[Bd; sigma*Cd*Bd];
C=[zeros(1,3) sigma’ ];
% MPC
nau = length(A);
Rb = rw*eye(Nc,Nc);
% F e Phi
F=zeros(Np,nau);
for i=1:Np
F(i,:)=C*(A^i);
end
Phi = zeros(Np, Nc);
%1st column:
for linha=1:Np
Phi(linha,1) = C*(A^(linha-1))*B;
end
%other column
for col =2: Nc
Phi(col:Np, col) = Phi(1:Np-(col-1),1);
end
PTP = Phi’*Phi;
if (Nc == 1)
vetor10 = [1];
else
vetor10 = [ 1 zeros(1,Nc-1)];
end
Hessiana=inv(PTP + Rb);
Kbs = -1*vetor10*Hessiana*(Phi’)*F;
% control sim
x = zeros(n,Ldata+1); %
y = zeros(1,Ldata); %
erro =zeros(1,Ldata); %
u =zeros(1,Ldata); %
xk_1=zeros(n,1); %x(k-1)
xk_2=zeros(n,1); %x(k-2)
xk_3=zeros(n,1); %x(k-3)
uk_1=0; %u(k-1)
uk_2=0; %u(k-2)
uk_3=0; %u(k-3)
ek_1=0; %e(k-1)
ek_2=0; %e(k-2)
% closed loop sim
for k=1:Ldata
xk = x(:,k); %
rk = r(k);
yk = Cd*xk; %
ek = rk-yk; %
qk = xk_3+(-gamma*xk_2)+(gamma*xk_1)-xk;
xbarra= [qk;ek_2;ek_1;ek];
vk=Kbs*xbarra;
uk= uk_3 + gamma*(uk_1-uk_2)-vk;
%
x(:,k+1) = (Ad*xk)+(Bd*uk);
%
erro(k) = ek;
u(k) = uk;
y(k) = yk;
%
xk_3 = xk_2;
xk_2 = xk_1;
xk_1 = xk;
uk_3 = uk_2;
uk_2 = uk_1;
uk_1 = uk;
ek_2 = ek_1;
ek_1 = ek;
end
%Fit func
up = max(abs(u))/1000; %peak control law
erro_rmse = rmse(r,y); % RMSE
% settling time
max_e = max(erro); %
valor_acom = 0.02*max_e; %
ind_acom = find(erro >= -valor_acom & erro <= valor_acom, 1); %
t_ae = t(ind_acom); %
J=0.2*up + 0.7*erro_rmse + 0.1*t_ae;
With this fitness function I am calling the ga function with the following parameters:
A_des = [0 0 -1; -1 1 0; 1 0 0; 0 -1 0];
b_des = [0 0 100 -2]’;
intcon = [1 2]; os
lb = [2 2 0];
ub = [100 99 60];
%Declaração das opções de funcionamento do AG
options = optimoptions("ga","CreationFcn","gacreationuniformint",…
"Display","iter","MutationFcn","mutationpower",…
"SelectionFcn","selectionroulette",…
"PlotFcn",["gaplotdistance", "gaplotselection","gaplotstopping",…
"gaplotbestf","gaplotbestindiv"]);
[best_ind, cost] = ga(@simplanta, 3, A_des, b_des, [], [], lb, ub, [],…
intcon, options)
param = infoPlant(best_ind)
However, sometimes (and to be quite frankly more often than not) MATLAB shows me this error during the execution of this code:
Unable to perform assignment because the size of the left side is 1-by-1 and the
size of the right side is 1-by-0.
Error in fcnvectorizer (line 19)
y(i,:) = feval(fun,(pop(i,:)));
Error in gaminlppenaltyfcn
Error in gapenalty
Error in stepGA (line 63)
nextScore = FitnessFcn(pop);
Error in galincon (line 86)
[score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn);
Error in gapenalty
Error in ga (line 412)
[x,fval,exitFlag,output,population,scores] = gapenalty(FitnessFcn,nvars,…
Error in ga_implementation (line 60)
[best_ind, cost] = ga(@simplanta, 3, A_des, b_des, [], [], lb, ub, [],…
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
I am quite frankly at loss as of why that would happen, since it sometimes runs smoothly, so it seems that it isn’t necessarily a code syntax error of my part. Or perhaps it IS and I am just not able to detect it.
Any help and input would be quite appreciatedHello everyone. I am currently using the ga function in order to find the best parameters for a discrete GPC controller. However, more often than not, the execution of this algorithm ends up in error.
First, let me show the fitness function that I am currently using:
function J = simplanta(individuo)
Np = individuo(1);
Nc = individuo(2);
rw = individuo(3);
ts=1/2000; % sampling time
t=0:ts:1; % sim time
f0=50;
r=1+1.5.*sin(2*pi*f0*t); % reference signal
Ldata=length(t); % # of time points
%Discrete Model
Ad =[0.4134 0.4536 0; -0.2404 0.7876 0; -0.4366 0.4224 0.7738];
Bd =[0.1331; 0.4528; 0.1273];
Cd=[0 0 1];
% Specified Gain Calc
n=length(Ad); %order%
Omega = 2*pi*f0*ts;
gamma = ( 2*cos(Omega) ) + 1;
E=[0 1 0; 0 0 1; 1 -gamma gamma];
sigma = [0;0;1];
% prediction matrices
A=[Ad zeros(n,3); sigma*Cd*Ad E];
B=[Bd; sigma*Cd*Bd];
C=[zeros(1,3) sigma’ ];
% MPC
nau = length(A);
Rb = rw*eye(Nc,Nc);
% F e Phi
F=zeros(Np,nau);
for i=1:Np
F(i,:)=C*(A^i);
end
Phi = zeros(Np, Nc);
%1st column:
for linha=1:Np
Phi(linha,1) = C*(A^(linha-1))*B;
end
%other column
for col =2: Nc
Phi(col:Np, col) = Phi(1:Np-(col-1),1);
end
PTP = Phi’*Phi;
if (Nc == 1)
vetor10 = [1];
else
vetor10 = [ 1 zeros(1,Nc-1)];
end
Hessiana=inv(PTP + Rb);
Kbs = -1*vetor10*Hessiana*(Phi’)*F;
% control sim
x = zeros(n,Ldata+1); %
y = zeros(1,Ldata); %
erro =zeros(1,Ldata); %
u =zeros(1,Ldata); %
xk_1=zeros(n,1); %x(k-1)
xk_2=zeros(n,1); %x(k-2)
xk_3=zeros(n,1); %x(k-3)
uk_1=0; %u(k-1)
uk_2=0; %u(k-2)
uk_3=0; %u(k-3)
ek_1=0; %e(k-1)
ek_2=0; %e(k-2)
% closed loop sim
for k=1:Ldata
xk = x(:,k); %
rk = r(k);
yk = Cd*xk; %
ek = rk-yk; %
qk = xk_3+(-gamma*xk_2)+(gamma*xk_1)-xk;
xbarra= [qk;ek_2;ek_1;ek];
vk=Kbs*xbarra;
uk= uk_3 + gamma*(uk_1-uk_2)-vk;
%
x(:,k+1) = (Ad*xk)+(Bd*uk);
%
erro(k) = ek;
u(k) = uk;
y(k) = yk;
%
xk_3 = xk_2;
xk_2 = xk_1;
xk_1 = xk;
uk_3 = uk_2;
uk_2 = uk_1;
uk_1 = uk;
ek_2 = ek_1;
ek_1 = ek;
end
%Fit func
up = max(abs(u))/1000; %peak control law
erro_rmse = rmse(r,y); % RMSE
% settling time
max_e = max(erro); %
valor_acom = 0.02*max_e; %
ind_acom = find(erro >= -valor_acom & erro <= valor_acom, 1); %
t_ae = t(ind_acom); %
J=0.2*up + 0.7*erro_rmse + 0.1*t_ae;
With this fitness function I am calling the ga function with the following parameters:
A_des = [0 0 -1; -1 1 0; 1 0 0; 0 -1 0];
b_des = [0 0 100 -2]’;
intcon = [1 2]; os
lb = [2 2 0];
ub = [100 99 60];
%Declaração das opções de funcionamento do AG
options = optimoptions("ga","CreationFcn","gacreationuniformint",…
"Display","iter","MutationFcn","mutationpower",…
"SelectionFcn","selectionroulette",…
"PlotFcn",["gaplotdistance", "gaplotselection","gaplotstopping",…
"gaplotbestf","gaplotbestindiv"]);
[best_ind, cost] = ga(@simplanta, 3, A_des, b_des, [], [], lb, ub, [],…
intcon, options)
param = infoPlant(best_ind)
However, sometimes (and to be quite frankly more often than not) MATLAB shows me this error during the execution of this code:
Unable to perform assignment because the size of the left side is 1-by-1 and the
size of the right side is 1-by-0.
Error in fcnvectorizer (line 19)
y(i,:) = feval(fun,(pop(i,:)));
Error in gaminlppenaltyfcn
Error in gapenalty
Error in stepGA (line 63)
nextScore = FitnessFcn(pop);
Error in galincon (line 86)
[score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn);
Error in gapenalty
Error in ga (line 412)
[x,fval,exitFlag,output,population,scores] = gapenalty(FitnessFcn,nvars,…
Error in ga_implementation (line 60)
[best_ind, cost] = ga(@simplanta, 3, A_des, b_des, [], [], lb, ub, [],…
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
I am quite frankly at loss as of why that would happen, since it sometimes runs smoothly, so it seems that it isn’t necessarily a code syntax error of my part. Or perhaps it IS and I am just not able to detect it.
Any help and input would be quite appreciated Hello everyone. I am currently using the ga function in order to find the best parameters for a discrete GPC controller. However, more often than not, the execution of this algorithm ends up in error.
First, let me show the fitness function that I am currently using:
function J = simplanta(individuo)
Np = individuo(1);
Nc = individuo(2);
rw = individuo(3);
ts=1/2000; % sampling time
t=0:ts:1; % sim time
f0=50;
r=1+1.5.*sin(2*pi*f0*t); % reference signal
Ldata=length(t); % # of time points
%Discrete Model
Ad =[0.4134 0.4536 0; -0.2404 0.7876 0; -0.4366 0.4224 0.7738];
Bd =[0.1331; 0.4528; 0.1273];
Cd=[0 0 1];
% Specified Gain Calc
n=length(Ad); %order%
Omega = 2*pi*f0*ts;
gamma = ( 2*cos(Omega) ) + 1;
E=[0 1 0; 0 0 1; 1 -gamma gamma];
sigma = [0;0;1];
% prediction matrices
A=[Ad zeros(n,3); sigma*Cd*Ad E];
B=[Bd; sigma*Cd*Bd];
C=[zeros(1,3) sigma’ ];
% MPC
nau = length(A);
Rb = rw*eye(Nc,Nc);
% F e Phi
F=zeros(Np,nau);
for i=1:Np
F(i,:)=C*(A^i);
end
Phi = zeros(Np, Nc);
%1st column:
for linha=1:Np
Phi(linha,1) = C*(A^(linha-1))*B;
end
%other column
for col =2: Nc
Phi(col:Np, col) = Phi(1:Np-(col-1),1);
end
PTP = Phi’*Phi;
if (Nc == 1)
vetor10 = [1];
else
vetor10 = [ 1 zeros(1,Nc-1)];
end
Hessiana=inv(PTP + Rb);
Kbs = -1*vetor10*Hessiana*(Phi’)*F;
% control sim
x = zeros(n,Ldata+1); %
y = zeros(1,Ldata); %
erro =zeros(1,Ldata); %
u =zeros(1,Ldata); %
xk_1=zeros(n,1); %x(k-1)
xk_2=zeros(n,1); %x(k-2)
xk_3=zeros(n,1); %x(k-3)
uk_1=0; %u(k-1)
uk_2=0; %u(k-2)
uk_3=0; %u(k-3)
ek_1=0; %e(k-1)
ek_2=0; %e(k-2)
% closed loop sim
for k=1:Ldata
xk = x(:,k); %
rk = r(k);
yk = Cd*xk; %
ek = rk-yk; %
qk = xk_3+(-gamma*xk_2)+(gamma*xk_1)-xk;
xbarra= [qk;ek_2;ek_1;ek];
vk=Kbs*xbarra;
uk= uk_3 + gamma*(uk_1-uk_2)-vk;
%
x(:,k+1) = (Ad*xk)+(Bd*uk);
%
erro(k) = ek;
u(k) = uk;
y(k) = yk;
%
xk_3 = xk_2;
xk_2 = xk_1;
xk_1 = xk;
uk_3 = uk_2;
uk_2 = uk_1;
uk_1 = uk;
ek_2 = ek_1;
ek_1 = ek;
end
%Fit func
up = max(abs(u))/1000; %peak control law
erro_rmse = rmse(r,y); % RMSE
% settling time
max_e = max(erro); %
valor_acom = 0.02*max_e; %
ind_acom = find(erro >= -valor_acom & erro <= valor_acom, 1); %
t_ae = t(ind_acom); %
J=0.2*up + 0.7*erro_rmse + 0.1*t_ae;
With this fitness function I am calling the ga function with the following parameters:
A_des = [0 0 -1; -1 1 0; 1 0 0; 0 -1 0];
b_des = [0 0 100 -2]’;
intcon = [1 2]; os
lb = [2 2 0];
ub = [100 99 60];
%Declaração das opções de funcionamento do AG
options = optimoptions("ga","CreationFcn","gacreationuniformint",…
"Display","iter","MutationFcn","mutationpower",…
"SelectionFcn","selectionroulette",…
"PlotFcn",["gaplotdistance", "gaplotselection","gaplotstopping",…
"gaplotbestf","gaplotbestindiv"]);
[best_ind, cost] = ga(@simplanta, 3, A_des, b_des, [], [], lb, ub, [],…
intcon, options)
param = infoPlant(best_ind)
However, sometimes (and to be quite frankly more often than not) MATLAB shows me this error during the execution of this code:
Unable to perform assignment because the size of the left side is 1-by-1 and the
size of the right side is 1-by-0.
Error in fcnvectorizer (line 19)
y(i,:) = feval(fun,(pop(i,:)));
Error in gaminlppenaltyfcn
Error in gapenalty
Error in stepGA (line 63)
nextScore = FitnessFcn(pop);
Error in galincon (line 86)
[score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn);
Error in gapenalty
Error in ga (line 412)
[x,fval,exitFlag,output,population,scores] = gapenalty(FitnessFcn,nvars,…
Error in ga_implementation (line 60)
[best_ind, cost] = ga(@simplanta, 3, A_des, b_des, [], [], lb, ub, [],…
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
I am quite frankly at loss as of why that would happen, since it sometimes runs smoothly, so it seems that it isn’t necessarily a code syntax error of my part. Or perhaps it IS and I am just not able to detect it.
Any help and input would be quite appreciated ga, fitness function MATLAB Answers — New Questions
Create array of customAntennaStl with multiple feeding points
Hi,
I am new to Matlab.
I want to create an array of antennas from a STL model I have made.
So far my code looks like this:
antenna = customAntennaStl(FileName=…*insert filepath*);
antenna.createFeed([0.55 0.635 0],1);
% Reduce the mesh size for faster calculations
mesh(antenna, MaxEdgeLength = 0.05);
figure
show(antenna)
I have tried unsuccessfully to create an array out of this single element. All the methods I found only work for predesigned antennas.
Ideally I want to create a square array of such antennas that would look like the photo attached, with multiple feeding points, since the antennas are not attached.
Please note that I am not attached to using a customAntennaStl, I would be interested in any other method, as long as I can roughly keep the shape of the antenna. The antenna can also be flattened to two dimensions .
——–
For completeness in the simulation I want to do, antennas facing each other are driven with opposite phases at a certain frequency. The two pairs of antennas are driven in quadrature.
Necessary files are attached.Hi,
I am new to Matlab.
I want to create an array of antennas from a STL model I have made.
So far my code looks like this:
antenna = customAntennaStl(FileName=…*insert filepath*);
antenna.createFeed([0.55 0.635 0],1);
% Reduce the mesh size for faster calculations
mesh(antenna, MaxEdgeLength = 0.05);
figure
show(antenna)
I have tried unsuccessfully to create an array out of this single element. All the methods I found only work for predesigned antennas.
Ideally I want to create a square array of such antennas that would look like the photo attached, with multiple feeding points, since the antennas are not attached.
Please note that I am not attached to using a customAntennaStl, I would be interested in any other method, as long as I can roughly keep the shape of the antenna. The antenna can also be flattened to two dimensions .
——–
For completeness in the simulation I want to do, antennas facing each other are driven with opposite phases at a certain frequency. The two pairs of antennas are driven in quadrature.
Necessary files are attached. Hi,
I am new to Matlab.
I want to create an array of antennas from a STL model I have made.
So far my code looks like this:
antenna = customAntennaStl(FileName=…*insert filepath*);
antenna.createFeed([0.55 0.635 0],1);
% Reduce the mesh size for faster calculations
mesh(antenna, MaxEdgeLength = 0.05);
figure
show(antenna)
I have tried unsuccessfully to create an array out of this single element. All the methods I found only work for predesigned antennas.
Ideally I want to create a square array of such antennas that would look like the photo attached, with multiple feeding points, since the antennas are not attached.
Please note that I am not attached to using a customAntennaStl, I would be interested in any other method, as long as I can roughly keep the shape of the antenna. The antenna can also be flattened to two dimensions .
——–
For completeness in the simulation I want to do, antennas facing each other are driven with opposite phases at a certain frequency. The two pairs of antennas are driven in quadrature.
Necessary files are attached. antenna, array, custom MATLAB Answers — New Questions
Why am I getting the error “api-ms-win-crt-runtime-l1-1-0.dll is missing” or “std::out_of_range std::exception::what: unregistered feature: webui” when running the MathWorks Product installer or MATLAB?
Why am I getting the error "api-ms-win-crt-runtime-l1-1-0.dll is missing" or "std::out_of_range std::exception::what: unregistered feature: webui" when running the MathWorks Product installer or MATLAB?Why am I getting the error "api-ms-win-crt-runtime-l1-1-0.dll is missing" or "std::out_of_range std::exception::what: unregistered feature: webui" when running the MathWorks Product installer or MATLAB? Why am I getting the error "api-ms-win-crt-runtime-l1-1-0.dll is missing" or "std::out_of_range std::exception::what: unregistered feature: webui" when running the MathWorks Product installer or MATLAB? MATLAB Answers — New Questions
Pcolor with two x axes and two y axes
I have some data Z (say MxN) matrix which i visualize with pcolor(X,Y,Z). I’d like the plot to display:
1) The colorbar;
2) Left and right yaxes with different scales
3) Top and bottom xaxes (or two xaxes on the bottom), one giving X in some units, the other its inverse (2*pi/X)
I have not found (by myself) any snippet on the community forum implementing all of these simultaneously, but it would help me tremendously.I have some data Z (say MxN) matrix which i visualize with pcolor(X,Y,Z). I’d like the plot to display:
1) The colorbar;
2) Left and right yaxes with different scales
3) Top and bottom xaxes (or two xaxes on the bottom), one giving X in some units, the other its inverse (2*pi/X)
I have not found (by myself) any snippet on the community forum implementing all of these simultaneously, but it would help me tremendously. I have some data Z (say MxN) matrix which i visualize with pcolor(X,Y,Z). I’d like the plot to display:
1) The colorbar;
2) Left and right yaxes with different scales
3) Top and bottom xaxes (or two xaxes on the bottom), one giving X in some units, the other its inverse (2*pi/X)
I have not found (by myself) any snippet on the community forum implementing all of these simultaneously, but it would help me tremendously. plotting, contour MATLAB Answers — New Questions