Category: Matlab
Category Archives: Matlab
Macroscopic Specimen image Sectioning
Hi everyone,
Would I be able to make an image similar to this in MATLAB?Hi everyone,
Would I be able to make an image similar to this in MATLAB? Hi everyone,
Would I be able to make an image similar to this in MATLAB? image analysis, image processing MATLAB Answers — New Questions
Use of private method and properties from a MATLAB class to a MATLAB function
I have a MATLAB file and there are couple of functions defined, I split two of the functions into new function files and invoked them in the main class file, so now the issue is there are some methods functions and properties which are set to private, so because of this the new function files arent able to get those methods and properties, the option I had is to keep Access/Set Access to public, but that is not an expectation here,
So, can anyone help or suggest here without making access change how to fix this issue, Any help is highly appreciated.I have a MATLAB file and there are couple of functions defined, I split two of the functions into new function files and invoked them in the main class file, so now the issue is there are some methods functions and properties which are set to private, so because of this the new function files arent able to get those methods and properties, the option I had is to keep Access/Set Access to public, but that is not an expectation here,
So, can anyone help or suggest here without making access change how to fix this issue, Any help is highly appreciated. I have a MATLAB file and there are couple of functions defined, I split two of the functions into new function files and invoked them in the main class file, so now the issue is there are some methods functions and properties which are set to private, so because of this the new function files arent able to get those methods and properties, the option I had is to keep Access/Set Access to public, but that is not an expectation here,
So, can anyone help or suggest here without making access change how to fix this issue, Any help is highly appreciated. matlab code, script, class MATLAB Answers — New Questions
Error Installing MATLAB engine API for Python
I am trying to install the MATLAB engine for Python on my computer and when I write
python setup.py install
I get the following error:
error: could not create ‘build’: Access is denied
The same error also occurs when I try _’builddir’_
I also have administrator access on my computer so I am confused as to why I am being denied.
Any help would be greatly appreciated!I am trying to install the MATLAB engine for Python on my computer and when I write
python setup.py install
I get the following error:
error: could not create ‘build’: Access is denied
The same error also occurs when I try _’builddir’_
I also have administrator access on my computer so I am confused as to why I am being denied.
Any help would be greatly appreciated! I am trying to install the MATLAB engine for Python on my computer and when I write
python setup.py install
I get the following error:
error: could not create ‘build’: Access is denied
The same error also occurs when I try _’builddir’_
I also have administrator access on my computer so I am confused as to why I am being denied.
Any help would be greatly appreciated! matlab, python, error api MATLAB Answers — New Questions
Replacing one line (or one part of a line) in a text file
Hello. I have a config file that contains 1 specific line that I want to change just the number (in this case from 1000 to e.g. 235)
This is my code so far:
%Get current Value
FilePath=’C:Program FilesTeledyne DALSASaperaCamFilesUsermyCamera.ccf’
Filedata = readlines(FilePath)
TF = contains(Filedata,"Time Integrate Duration=")
k = find(TF,1);
expStr=Filedata(TF);
ReportMessage(app,expStr); %My report function that reports to a UITextarea
oldLine=Filedata(k)
Filedata(k) ="Time Integrate Duration=235" %this is the new line I want
[fid, msg] = fopen(‘FilePath’, ‘w’)
if fid < 1;
error(‘could not write output file because "%s"’, msg);
end
fwrite(fid, strjoin(Filedata, ‘n’));
fclose(fid);
But it doesn’t seem to be changing the file
I also enclose the config file (text)Hello. I have a config file that contains 1 specific line that I want to change just the number (in this case from 1000 to e.g. 235)
This is my code so far:
%Get current Value
FilePath=’C:Program FilesTeledyne DALSASaperaCamFilesUsermyCamera.ccf’
Filedata = readlines(FilePath)
TF = contains(Filedata,"Time Integrate Duration=")
k = find(TF,1);
expStr=Filedata(TF);
ReportMessage(app,expStr); %My report function that reports to a UITextarea
oldLine=Filedata(k)
Filedata(k) ="Time Integrate Duration=235" %this is the new line I want
[fid, msg] = fopen(‘FilePath’, ‘w’)
if fid < 1;
error(‘could not write output file because "%s"’, msg);
end
fwrite(fid, strjoin(Filedata, ‘n’));
fclose(fid);
But it doesn’t seem to be changing the file
I also enclose the config file (text) Hello. I have a config file that contains 1 specific line that I want to change just the number (in this case from 1000 to e.g. 235)
This is my code so far:
%Get current Value
FilePath=’C:Program FilesTeledyne DALSASaperaCamFilesUsermyCamera.ccf’
Filedata = readlines(FilePath)
TF = contains(Filedata,"Time Integrate Duration=")
k = find(TF,1);
expStr=Filedata(TF);
ReportMessage(app,expStr); %My report function that reports to a UITextarea
oldLine=Filedata(k)
Filedata(k) ="Time Integrate Duration=235" %this is the new line I want
[fid, msg] = fopen(‘FilePath’, ‘w’)
if fid < 1;
error(‘could not write output file because "%s"’, msg);
end
fwrite(fid, strjoin(Filedata, ‘n’));
fclose(fid);
But it doesn’t seem to be changing the file
I also enclose the config file (text) readlines, contains, fwrite MATLAB Answers — New Questions
Why does MATLAB Runtime cache (CTF extraction path) get corrupted after running the executable for several number of times?
We have a .NET application where functions of a MATLAB Compiler SDK generated DLL are called.
It happens that the MATLAB Runtime cache gets corrupt, such that executing the DLL function always results in error.
This happens only after running the application for several number of times. When I manually delete the entire MATLAB Runtime cache directory helps resolving the issue. I am wondering what could be the reason for corrupted CTF extraction.We have a .NET application where functions of a MATLAB Compiler SDK generated DLL are called.
It happens that the MATLAB Runtime cache gets corrupt, such that executing the DLL function always results in error.
This happens only after running the application for several number of times. When I manually delete the entire MATLAB Runtime cache directory helps resolving the issue. I am wondering what could be the reason for corrupted CTF extraction. We have a .NET application where functions of a MATLAB Compiler SDK generated DLL are called.
It happens that the MATLAB Runtime cache gets corrupt, such that executing the DLL function always results in error.
This happens only after running the application for several number of times. When I manually delete the entire MATLAB Runtime cache directory helps resolving the issue. I am wondering what could be the reason for corrupted CTF extraction. corrupted, mcr MATLAB Answers — New Questions
3D system definition: How btaining the angle between a single axis and a plane
Hello, I am having trouble obtaining the angle between a vector and a plane which are defined by two different rotation matrix.
I have two objects, A and B, which are defined by rotation matrices R (Rotation matrix from global origin to A) and R’ (Rotation matrix from global origin to B).
R = [a b c; d e f; g h i]
R’= [a’ b’ c’; d’ e’ f’; g’ h’ i’]
I want to obtain the rotation in degrees between the axis X from object A to the plane XZ (and eventually XY) from object B.
Thank you in advance.
AlonsoHello, I am having trouble obtaining the angle between a vector and a plane which are defined by two different rotation matrix.
I have two objects, A and B, which are defined by rotation matrices R (Rotation matrix from global origin to A) and R’ (Rotation matrix from global origin to B).
R = [a b c; d e f; g h i]
R’= [a’ b’ c’; d’ e’ f’; g’ h’ i’]
I want to obtain the rotation in degrees between the axis X from object A to the plane XZ (and eventually XY) from object B.
Thank you in advance.
Alonso Hello, I am having trouble obtaining the angle between a vector and a plane which are defined by two different rotation matrix.
I have two objects, A and B, which are defined by rotation matrices R (Rotation matrix from global origin to A) and R’ (Rotation matrix from global origin to B).
R = [a b c; d e f; g h i]
R’= [a’ b’ c’; d’ e’ f’; g’ h’ i’]
I want to obtain the rotation in degrees between the axis X from object A to the plane XZ (and eventually XY) from object B.
Thank you in advance.
Alonso 3d kinematics, rotation matrices MATLAB Answers — New Questions
Performance Issue using cell() to convert Python data types to Matlab
I have a Python list of 50,000 elements in Matlab, and using the cell() function to convert it to Matlab cell array is taking over an hour, while on my coworkers machine it takes less than a minute. We are both using Python 3.9, Matlab 2021b, and my VM is v4cpu 16G RAM. Also, when trying to pause or stop the execution of cell() Matlab freezes, and has to be forcefully shut down.
Note – The code below executed instantly in this website, but takes over an hour on Matlab 2021b installed on my local.
pyrun("py_list = list(range(50000))");
cellArray = cell(pyrun(‘py_list’, ‘py_list’));I have a Python list of 50,000 elements in Matlab, and using the cell() function to convert it to Matlab cell array is taking over an hour, while on my coworkers machine it takes less than a minute. We are both using Python 3.9, Matlab 2021b, and my VM is v4cpu 16G RAM. Also, when trying to pause or stop the execution of cell() Matlab freezes, and has to be forcefully shut down.
Note – The code below executed instantly in this website, but takes over an hour on Matlab 2021b installed on my local.
pyrun("py_list = list(range(50000))");
cellArray = cell(pyrun(‘py_list’, ‘py_list’)); I have a Python list of 50,000 elements in Matlab, and using the cell() function to convert it to Matlab cell array is taking over an hour, while on my coworkers machine it takes less than a minute. We are both using Python 3.9, Matlab 2021b, and my VM is v4cpu 16G RAM. Also, when trying to pause or stop the execution of cell() Matlab freezes, and has to be forcefully shut down.
Note – The code below executed instantly in this website, but takes over an hour on Matlab 2021b installed on my local.
pyrun("py_list = list(range(50000))");
cellArray = cell(pyrun(‘py_list’, ‘py_list’)); python, cell MATLAB Answers — New Questions
Line following AGV Simulation Issue
I’m planning to simulate a warehouse with line following AGVs. I would like the warehouse as the one in Mobile Robotics Simulation Toolbox. However, instead of using probabilistic methods, I want each robot to strictly follow predefined paths/lines without deviating. How can I configure these paths and ensure the robots follow them while avoiding collisions with each other? Thank you
Control and Simulate Multiple Warehouse Robots – MATLAB & Simulink (mathworks.com)I’m planning to simulate a warehouse with line following AGVs. I would like the warehouse as the one in Mobile Robotics Simulation Toolbox. However, instead of using probabilistic methods, I want each robot to strictly follow predefined paths/lines without deviating. How can I configure these paths and ensure the robots follow them while avoiding collisions with each other? Thank you
Control and Simulate Multiple Warehouse Robots – MATLAB & Simulink (mathworks.com) I’m planning to simulate a warehouse with line following AGVs. I would like the warehouse as the one in Mobile Robotics Simulation Toolbox. However, instead of using probabilistic methods, I want each robot to strictly follow predefined paths/lines without deviating. How can I configure these paths and ensure the robots follow them while avoiding collisions with each other? Thank you
Control and Simulate Multiple Warehouse Robots – MATLAB & Simulink (mathworks.com) control, line, warehouse, robots, robot, robotics, mobile robotics simulation toolbox, mobile, agv MATLAB Answers — New Questions
How to resolve the error “Could not access MATLAB Runtime component cache fl:filesystem:InvalidArgument”?
I am attempting to run a compiled application. However, I am encountering the following error:
Could not access the MATLAB Runtime component cache.
Details: fl:filesystem:InvalidArgument; component cache root:;
componentname: APP_NAME
How can I resolve this error?I am attempting to run a compiled application. However, I am encountering the following error:
Could not access the MATLAB Runtime component cache.
Details: fl:filesystem:InvalidArgument; component cache root:;
componentname: APP_NAME
How can I resolve this error? I am attempting to run a compiled application. However, I am encountering the following error:
Could not access the MATLAB Runtime component cache.
Details: fl:filesystem:InvalidArgument; component cache root:;
componentname: APP_NAME
How can I resolve this error? mcr, runtime, component, cache, deployed, app, application MATLAB Answers — New Questions
Finding intersection between line plot and horizontal line
I’ve been trying to find the full width at half max (FWHM) some data points. There are about 1000 data points (intensity on the y and angle on the x), and when I plot them, there is a line drawn to connect all the points. My current method for calculating the FWHM is to use the find function and locate the points in the original data that are closest to the half max.
Is it possible to use the line drawn to connect all the points and find the intersection between that and a horizontal line at the half max? I’ve tired using the find function like:
intersection = find(intensity == halfMax);
However this returns an empty vector (unsurprisngly). If there was a way to access the points on the line that connect my original data, this would make it a more accurate calculation.
The attached graph is semilogy, please let me know if you know it this is possible or need clarification.I’ve been trying to find the full width at half max (FWHM) some data points. There are about 1000 data points (intensity on the y and angle on the x), and when I plot them, there is a line drawn to connect all the points. My current method for calculating the FWHM is to use the find function and locate the points in the original data that are closest to the half max.
Is it possible to use the line drawn to connect all the points and find the intersection between that and a horizontal line at the half max? I’ve tired using the find function like:
intersection = find(intensity == halfMax);
However this returns an empty vector (unsurprisngly). If there was a way to access the points on the line that connect my original data, this would make it a more accurate calculation.
The attached graph is semilogy, please let me know if you know it this is possible or need clarification. I’ve been trying to find the full width at half max (FWHM) some data points. There are about 1000 data points (intensity on the y and angle on the x), and when I plot them, there is a line drawn to connect all the points. My current method for calculating the FWHM is to use the find function and locate the points in the original data that are closest to the half max.
Is it possible to use the line drawn to connect all the points and find the intersection between that and a horizontal line at the half max? I’ve tired using the find function like:
intersection = find(intensity == halfMax);
However this returns an empty vector (unsurprisngly). If there was a way to access the points on the line that connect my original data, this would make it a more accurate calculation.
The attached graph is semilogy, please let me know if you know it this is possible or need clarification. fwhm, data plot MATLAB Answers — New Questions
Error in for loop: Index exceeds matrix dimensions.
Hi everyone! I need help with my code.I have a matrix (300×300) with some equal rows, and I need to eliminate the duplicate rows. I can’t solve the error. Can anyone help me??Thank you very much!
Below I copy the part of the code with the error and a simplified example.
clear all
matrix_f=[1 2 3; 1 2 3; 4 5 6; 7 8 9; 7 8 9; 10 11 12];
for k=1:length(matrix_f(:,1))
if matrix_f(k,1)==matrix_f(k+1,1)
matrix_f(k+1,:)=[];
end
endHi everyone! I need help with my code.I have a matrix (300×300) with some equal rows, and I need to eliminate the duplicate rows. I can’t solve the error. Can anyone help me??Thank you very much!
Below I copy the part of the code with the error and a simplified example.
clear all
matrix_f=[1 2 3; 1 2 3; 4 5 6; 7 8 9; 7 8 9; 10 11 12];
for k=1:length(matrix_f(:,1))
if matrix_f(k,1)==matrix_f(k+1,1)
matrix_f(k+1,:)=[];
end
end Hi everyone! I need help with my code.I have a matrix (300×300) with some equal rows, and I need to eliminate the duplicate rows. I can’t solve the error. Can anyone help me??Thank you very much!
Below I copy the part of the code with the error and a simplified example.
clear all
matrix_f=[1 2 3; 1 2 3; 4 5 6; 7 8 9; 7 8 9; 10 11 12];
for k=1:length(matrix_f(:,1))
if matrix_f(k,1)==matrix_f(k+1,1)
matrix_f(k+1,:)=[];
end
end for, for loop, matrix, index exceeds matrix dimensions. MATLAB Answers — New Questions
finding the remainder of the division of two symbolic variables
I want to get 2*V^2 from the operation below
syms A V
rem(2*V^2+3A,A)
but it seems like rem() function does not work with symbolic variables. Is there a way to achieve this in another way?I want to get 2*V^2 from the operation below
syms A V
rem(2*V^2+3A,A)
but it seems like rem() function does not work with symbolic variables. Is there a way to achieve this in another way? I want to get 2*V^2 from the operation below
syms A V
rem(2*V^2+3A,A)
but it seems like rem() function does not work with symbolic variables. Is there a way to achieve this in another way? symbolic MATLAB Answers — New Questions
Parfeval with backgorund pool cannot read XML file
Inside the parfeval I am using xml_read with an XML path. This function works properly with a parpool object but not with a backgorundPoolInside the parfeval I am using xml_read with an XML path. This function works properly with a parpool object but not with a backgorundPool Inside the parfeval I am using xml_read with an XML path. This function works properly with a parpool object but not with a backgorundPool backgroundpool, parfeval MATLAB Answers — New Questions
code does not call a designed function that works in other program
Hello and sorry for this long query. I am not very good at this , I have to admit it.
I am encountering an issue when trying to apply custom boundary conditions in a PDE model using MATLAB. Specifically, I have a custom boundary condition function mybc1 that works correctly in another code when using structuralBC to apply displacement conditions to vertices. However, in my current code, when I try to use applyBoundaryCondition to set mixed boundary conditions on specific faces, it seems that the solver does not enter the custom boundary condition function mybc1.
Here’s a brief description of what I am trying to do:
Model Definition: I have defined a PDE model with certain geometry and mesh.
Boundary Condition Application: I attempt to apply mixed boundary conditions on specific faces using applyBoundaryCondition with the u parameter set to a custom function handle @(location, state)mybc1(location, state, dis, ts, in).
Issue: It appears that the solver does not call the mybc1 function during the solution process. I verified this by setting breakpoints inside mybc1, which are never hit.
The mybc1 function interpolates the acceleration data (dis) at the times specified by the solver (state.time) and returns the corresponding values. This function has been tested and works correctly in another program with structuralBC.
code as follows:
%____________Define dimensions of the plate________________________________
len = 1.22; % length in x direction
width = 1.22; % Width in y direction
sq_side = 0.10; % Side length of the squares in corners
% Create the geometry description matrix___________________________________
% —–Define the outer boundary——————————————-
outer_boundary = [3, 4, 0, len, len, 0, 0, 0, width, width]’;
%——Define squares in the corners—————————————
square_1 = [3, 4, 0, sq_side, sq_side, 0, 0, 0, sq_side, sq_side]’;
square_2 = [3, 4, len – sq_side, len, len, len – sq_side, 0, 0, sq_side, sq_side]’;
square_3 = [3, 4, len – sq_side, len, len, len – sq_side, width – sq_side, width – sq_side, width, width]’;
square_4 = [3, 4, 0, sq_side, sq_side, 0, width – sq_side, width – sq_side, width, width]’;
%——Combine all the geometries——————————————
gdm = [outer_boundary, square_1, square_2, square_3, square_4];
%——Define the names for each region————————————
ns = (char(‘R1′,’R2′,’R3′,’R4′,’R5′))’;
sf = ‘R1+R2+R3+R4+R5’;
%——-Create the geometry————————————————
model = createpde(2);
geometryFromEdges(model, decsg(gdm, sf, ns));
%——-Generate the mesh and plot the geometry—————————-
msh = generateMesh(model, ‘Hmax’, 0.1); % Use ‘Hmax’ to control mesh density
figure
pdemesh(model)
%_____________Create the different regions of the model___________________
% Obtain nodes and elements of the mesh
[p,e,t] = meshToPet(model.Mesh);
% ———-Plot with Faces labels—————————————-
figure;
pdegplot(model, ‘FaceLabels’, ‘on’, ‘FaceAlpha’, 0.5);
figure
pdemesh(model, ‘NodeLabels’, ‘on’);
% Definition of the constants
E = 4E9;
h_thick = 0.05;
nu = 0.3;
mass = 100;
D = E*h_thick^3/(12*(1-nu)^2);
% Now we create the PDE systems as symbolic equations_____________________
syms pres
syms u1(x,y,t) u2(x,y,t)
pdeeq = [-laplacian(u1,[x y])+u2; D*laplacian(u2,[x y])+ mass*diff(u1,t,t)-pres];
symcoeffs = pdeCoefficients(pdeeq,[u1,u2],’Symbolic’,true);
c2=symcoeffs.c;
m2=symcoeffs.m;
%——Display the symbolic coefficients———————————–
structfun(@disp,symcoeffs);
symcoeffs=subs(symcoeffs,pres,1);
coeffs=pdeCoefficientsToDouble(symcoeffs);
%——pass these coefficients to the pde model—————————-
specifyCoefficients(model,’m’,coeffs.m,’d’,coeffs.d,’c’,…
coeffs.c,’a’,coeffs.a,’f’,coeffs.f);
% INITIAL CONDITIONS ——————————————————
setInitialConditions(model,[0;0],[0;0]);
%USE THE DATA FROM ASHMOLEAN AS BOUNDARY CONDITIONS————————
%load the vector containing the acceleration values
load(totaldata.mat’, ‘DATA’,…
‘TIME’,’fs’);
ac=DATA;
% ——-Create vector time, not starting in 0
num_samples = size(DATA, 1);
dt = 1 / fs; % interval between measurements
t = (1:num_samples) * dt; % vector of times
% TRANSFORM ACCELERATIONS INTO DISPLACEMENTS_______________________________
acvedi=AccVelDis(962.54,1005.11,992.35,ac,fs,t);
dis=acvedi{3};
t=[0,t]; % I start the time at 0
% Boundary conditions in the faces using the displacement vectors
in=0; %counter variable
Faces=[1,2,3,5]; %Vector with faces numbers
for jk = 1:numel(Faces)
in=in+1;%add 1 in every loop to access the different measurmentes contained in the matrix acceleration
face= Faces(jk);
dis1=dis(:,in);
applyBoundaryCondition(model,"mixed","Face",[face,face],"u",@(location,state)mybc1(location,state,dis1,t),"EquationIndex",1,"q",[0 0],"g",0);
%applyBoundaryCondition(model,"dirichlet","Face",face,"h",[0 0 ; 0 1],"r",bcfunc)
end
in=0;
tim=[t(2) t(3)]; %tim represents the time of interest to solve the pde
res=solvepde(model, tim);
% Access the solution at the nodal locations
sol=res.NodalSolution;
And this is the function that works in another code:
function bcMatrix = mybc1(location,state,acs,ti)
%This function is use to extrapolate the values of acceleration for the
%time instances chosen by the system to do the integration of the system.
%as imput it requires the measurements matrix and the corresponding time
%measurements. As output, it provices the extrapoleted values for the state
%time
T=state.time;
% Check if T is NaN and assign the previous value if true
if isnan(T)
vq = NaN(size(location.x)); %this is what documentation says????
else
ac = acs; %gets the value of the corresponding acceleration
vq = interp1(ti, ac, T); %interpolates it
end
bcMatrix = vq;
end
I would really appreciate any help/guidanceHello and sorry for this long query. I am not very good at this , I have to admit it.
I am encountering an issue when trying to apply custom boundary conditions in a PDE model using MATLAB. Specifically, I have a custom boundary condition function mybc1 that works correctly in another code when using structuralBC to apply displacement conditions to vertices. However, in my current code, when I try to use applyBoundaryCondition to set mixed boundary conditions on specific faces, it seems that the solver does not enter the custom boundary condition function mybc1.
Here’s a brief description of what I am trying to do:
Model Definition: I have defined a PDE model with certain geometry and mesh.
Boundary Condition Application: I attempt to apply mixed boundary conditions on specific faces using applyBoundaryCondition with the u parameter set to a custom function handle @(location, state)mybc1(location, state, dis, ts, in).
Issue: It appears that the solver does not call the mybc1 function during the solution process. I verified this by setting breakpoints inside mybc1, which are never hit.
The mybc1 function interpolates the acceleration data (dis) at the times specified by the solver (state.time) and returns the corresponding values. This function has been tested and works correctly in another program with structuralBC.
code as follows:
%____________Define dimensions of the plate________________________________
len = 1.22; % length in x direction
width = 1.22; % Width in y direction
sq_side = 0.10; % Side length of the squares in corners
% Create the geometry description matrix___________________________________
% —–Define the outer boundary——————————————-
outer_boundary = [3, 4, 0, len, len, 0, 0, 0, width, width]’;
%——Define squares in the corners—————————————
square_1 = [3, 4, 0, sq_side, sq_side, 0, 0, 0, sq_side, sq_side]’;
square_2 = [3, 4, len – sq_side, len, len, len – sq_side, 0, 0, sq_side, sq_side]’;
square_3 = [3, 4, len – sq_side, len, len, len – sq_side, width – sq_side, width – sq_side, width, width]’;
square_4 = [3, 4, 0, sq_side, sq_side, 0, width – sq_side, width – sq_side, width, width]’;
%——Combine all the geometries——————————————
gdm = [outer_boundary, square_1, square_2, square_3, square_4];
%——Define the names for each region————————————
ns = (char(‘R1′,’R2′,’R3′,’R4′,’R5′))’;
sf = ‘R1+R2+R3+R4+R5’;
%——-Create the geometry————————————————
model = createpde(2);
geometryFromEdges(model, decsg(gdm, sf, ns));
%——-Generate the mesh and plot the geometry—————————-
msh = generateMesh(model, ‘Hmax’, 0.1); % Use ‘Hmax’ to control mesh density
figure
pdemesh(model)
%_____________Create the different regions of the model___________________
% Obtain nodes and elements of the mesh
[p,e,t] = meshToPet(model.Mesh);
% ———-Plot with Faces labels—————————————-
figure;
pdegplot(model, ‘FaceLabels’, ‘on’, ‘FaceAlpha’, 0.5);
figure
pdemesh(model, ‘NodeLabels’, ‘on’);
% Definition of the constants
E = 4E9;
h_thick = 0.05;
nu = 0.3;
mass = 100;
D = E*h_thick^3/(12*(1-nu)^2);
% Now we create the PDE systems as symbolic equations_____________________
syms pres
syms u1(x,y,t) u2(x,y,t)
pdeeq = [-laplacian(u1,[x y])+u2; D*laplacian(u2,[x y])+ mass*diff(u1,t,t)-pres];
symcoeffs = pdeCoefficients(pdeeq,[u1,u2],’Symbolic’,true);
c2=symcoeffs.c;
m2=symcoeffs.m;
%——Display the symbolic coefficients———————————–
structfun(@disp,symcoeffs);
symcoeffs=subs(symcoeffs,pres,1);
coeffs=pdeCoefficientsToDouble(symcoeffs);
%——pass these coefficients to the pde model—————————-
specifyCoefficients(model,’m’,coeffs.m,’d’,coeffs.d,’c’,…
coeffs.c,’a’,coeffs.a,’f’,coeffs.f);
% INITIAL CONDITIONS ——————————————————
setInitialConditions(model,[0;0],[0;0]);
%USE THE DATA FROM ASHMOLEAN AS BOUNDARY CONDITIONS————————
%load the vector containing the acceleration values
load(totaldata.mat’, ‘DATA’,…
‘TIME’,’fs’);
ac=DATA;
% ——-Create vector time, not starting in 0
num_samples = size(DATA, 1);
dt = 1 / fs; % interval between measurements
t = (1:num_samples) * dt; % vector of times
% TRANSFORM ACCELERATIONS INTO DISPLACEMENTS_______________________________
acvedi=AccVelDis(962.54,1005.11,992.35,ac,fs,t);
dis=acvedi{3};
t=[0,t]; % I start the time at 0
% Boundary conditions in the faces using the displacement vectors
in=0; %counter variable
Faces=[1,2,3,5]; %Vector with faces numbers
for jk = 1:numel(Faces)
in=in+1;%add 1 in every loop to access the different measurmentes contained in the matrix acceleration
face= Faces(jk);
dis1=dis(:,in);
applyBoundaryCondition(model,"mixed","Face",[face,face],"u",@(location,state)mybc1(location,state,dis1,t),"EquationIndex",1,"q",[0 0],"g",0);
%applyBoundaryCondition(model,"dirichlet","Face",face,"h",[0 0 ; 0 1],"r",bcfunc)
end
in=0;
tim=[t(2) t(3)]; %tim represents the time of interest to solve the pde
res=solvepde(model, tim);
% Access the solution at the nodal locations
sol=res.NodalSolution;
And this is the function that works in another code:
function bcMatrix = mybc1(location,state,acs,ti)
%This function is use to extrapolate the values of acceleration for the
%time instances chosen by the system to do the integration of the system.
%as imput it requires the measurements matrix and the corresponding time
%measurements. As output, it provices the extrapoleted values for the state
%time
T=state.time;
% Check if T is NaN and assign the previous value if true
if isnan(T)
vq = NaN(size(location.x)); %this is what documentation says????
else
ac = acs; %gets the value of the corresponding acceleration
vq = interp1(ti, ac, T); %interpolates it
end
bcMatrix = vq;
end
I would really appreciate any help/guidance Hello and sorry for this long query. I am not very good at this , I have to admit it.
I am encountering an issue when trying to apply custom boundary conditions in a PDE model using MATLAB. Specifically, I have a custom boundary condition function mybc1 that works correctly in another code when using structuralBC to apply displacement conditions to vertices. However, in my current code, when I try to use applyBoundaryCondition to set mixed boundary conditions on specific faces, it seems that the solver does not enter the custom boundary condition function mybc1.
Here’s a brief description of what I am trying to do:
Model Definition: I have defined a PDE model with certain geometry and mesh.
Boundary Condition Application: I attempt to apply mixed boundary conditions on specific faces using applyBoundaryCondition with the u parameter set to a custom function handle @(location, state)mybc1(location, state, dis, ts, in).
Issue: It appears that the solver does not call the mybc1 function during the solution process. I verified this by setting breakpoints inside mybc1, which are never hit.
The mybc1 function interpolates the acceleration data (dis) at the times specified by the solver (state.time) and returns the corresponding values. This function has been tested and works correctly in another program with structuralBC.
code as follows:
%____________Define dimensions of the plate________________________________
len = 1.22; % length in x direction
width = 1.22; % Width in y direction
sq_side = 0.10; % Side length of the squares in corners
% Create the geometry description matrix___________________________________
% —–Define the outer boundary——————————————-
outer_boundary = [3, 4, 0, len, len, 0, 0, 0, width, width]’;
%——Define squares in the corners—————————————
square_1 = [3, 4, 0, sq_side, sq_side, 0, 0, 0, sq_side, sq_side]’;
square_2 = [3, 4, len – sq_side, len, len, len – sq_side, 0, 0, sq_side, sq_side]’;
square_3 = [3, 4, len – sq_side, len, len, len – sq_side, width – sq_side, width – sq_side, width, width]’;
square_4 = [3, 4, 0, sq_side, sq_side, 0, width – sq_side, width – sq_side, width, width]’;
%——Combine all the geometries——————————————
gdm = [outer_boundary, square_1, square_2, square_3, square_4];
%——Define the names for each region————————————
ns = (char(‘R1′,’R2′,’R3′,’R4′,’R5′))’;
sf = ‘R1+R2+R3+R4+R5’;
%——-Create the geometry————————————————
model = createpde(2);
geometryFromEdges(model, decsg(gdm, sf, ns));
%——-Generate the mesh and plot the geometry—————————-
msh = generateMesh(model, ‘Hmax’, 0.1); % Use ‘Hmax’ to control mesh density
figure
pdemesh(model)
%_____________Create the different regions of the model___________________
% Obtain nodes and elements of the mesh
[p,e,t] = meshToPet(model.Mesh);
% ———-Plot with Faces labels—————————————-
figure;
pdegplot(model, ‘FaceLabels’, ‘on’, ‘FaceAlpha’, 0.5);
figure
pdemesh(model, ‘NodeLabels’, ‘on’);
% Definition of the constants
E = 4E9;
h_thick = 0.05;
nu = 0.3;
mass = 100;
D = E*h_thick^3/(12*(1-nu)^2);
% Now we create the PDE systems as symbolic equations_____________________
syms pres
syms u1(x,y,t) u2(x,y,t)
pdeeq = [-laplacian(u1,[x y])+u2; D*laplacian(u2,[x y])+ mass*diff(u1,t,t)-pres];
symcoeffs = pdeCoefficients(pdeeq,[u1,u2],’Symbolic’,true);
c2=symcoeffs.c;
m2=symcoeffs.m;
%——Display the symbolic coefficients———————————–
structfun(@disp,symcoeffs);
symcoeffs=subs(symcoeffs,pres,1);
coeffs=pdeCoefficientsToDouble(symcoeffs);
%——pass these coefficients to the pde model—————————-
specifyCoefficients(model,’m’,coeffs.m,’d’,coeffs.d,’c’,…
coeffs.c,’a’,coeffs.a,’f’,coeffs.f);
% INITIAL CONDITIONS ——————————————————
setInitialConditions(model,[0;0],[0;0]);
%USE THE DATA FROM ASHMOLEAN AS BOUNDARY CONDITIONS————————
%load the vector containing the acceleration values
load(totaldata.mat’, ‘DATA’,…
‘TIME’,’fs’);
ac=DATA;
% ——-Create vector time, not starting in 0
num_samples = size(DATA, 1);
dt = 1 / fs; % interval between measurements
t = (1:num_samples) * dt; % vector of times
% TRANSFORM ACCELERATIONS INTO DISPLACEMENTS_______________________________
acvedi=AccVelDis(962.54,1005.11,992.35,ac,fs,t);
dis=acvedi{3};
t=[0,t]; % I start the time at 0
% Boundary conditions in the faces using the displacement vectors
in=0; %counter variable
Faces=[1,2,3,5]; %Vector with faces numbers
for jk = 1:numel(Faces)
in=in+1;%add 1 in every loop to access the different measurmentes contained in the matrix acceleration
face= Faces(jk);
dis1=dis(:,in);
applyBoundaryCondition(model,"mixed","Face",[face,face],"u",@(location,state)mybc1(location,state,dis1,t),"EquationIndex",1,"q",[0 0],"g",0);
%applyBoundaryCondition(model,"dirichlet","Face",face,"h",[0 0 ; 0 1],"r",bcfunc)
end
in=0;
tim=[t(2) t(3)]; %tim represents the time of interest to solve the pde
res=solvepde(model, tim);
% Access the solution at the nodal locations
sol=res.NodalSolution;
And this is the function that works in another code:
function bcMatrix = mybc1(location,state,acs,ti)
%This function is use to extrapolate the values of acceleration for the
%time instances chosen by the system to do the integration of the system.
%as imput it requires the measurements matrix and the corresponding time
%measurements. As output, it provices the extrapoleted values for the state
%time
T=state.time;
% Check if T is NaN and assign the previous value if true
if isnan(T)
vq = NaN(size(location.x)); %this is what documentation says????
else
ac = acs; %gets the value of the corresponding acceleration
vq = interp1(ti, ac, T); %interpolates it
end
bcMatrix = vq;
end
I would really appreciate any help/guidance handles, pde, applyboundaryconditions, function, differential equations MATLAB Answers — New Questions
Friend Function implementation in MATLAB
Typically, the private properties of a class are not accessible by any other class or function from outside.
But, a friend function can be granted special access to private and protected members of a class in C++.
For further reference: https://en.cppreference.com/w/cpp/language/friend
Is there any way, I can implement this in MATLAB?
It would be really helpful if anyone could provide a sample code illustrating the implementation in MATLAB.
Thanks in advance.Typically, the private properties of a class are not accessible by any other class or function from outside.
But, a friend function can be granted special access to private and protected members of a class in C++.
For further reference: https://en.cppreference.com/w/cpp/language/friend
Is there any way, I can implement this in MATLAB?
It would be really helpful if anyone could provide a sample code illustrating the implementation in MATLAB.
Thanks in advance. Typically, the private properties of a class are not accessible by any other class or function from outside.
But, a friend function can be granted special access to private and protected members of a class in C++.
For further reference: https://en.cppreference.com/w/cpp/language/friend
Is there any way, I can implement this in MATLAB?
It would be really helpful if anyone could provide a sample code illustrating the implementation in MATLAB.
Thanks in advance. matlab, oop, programming MATLAB Answers — New Questions
How to use indices of one matrix as entries of another matrix?
Hello, I have two matrices, M1 ans M2. They both have rows and columns fom 0 to 9 and a to f (16 * 16) matrix.
Mi matrix is filled with random numbers form 0 to 255 in hex decimal notation.
The second matrix M2 is empty but has the same row and column indexs. I need to fill M2 with the help of M1. For eample, in M2, at row 3 and colm 4 ( 34,the first entry of M1) will be 00 ( index of the first entry of M1). In M2 at row 6 col A, the entry will be 01, at row 2 col 9, the entry will be 02, and so on.
%% % Initialize M2 with zeros
M2 = zeros(16,16);
for row = 0:15
for col = 0:15
% get the value from M1
value= M1(row+1,col+1);
% Convert the values to row and col indices for M2
hexStr=dec2hex(value,2); % convert to 2 digit hex
M2_row=hex2dec(hexStr(1))+1;% convert first digit to decimal
M2_col=hex2dec(hexStr(2))+1;% convert first digit to decimal
% %Debugging
% % place the original rows and columns in M2
%
M2(M2_row, M2_col)=row*16+col;
end
end
M2;
If anyone can help.Hello, I have two matrices, M1 ans M2. They both have rows and columns fom 0 to 9 and a to f (16 * 16) matrix.
Mi matrix is filled with random numbers form 0 to 255 in hex decimal notation.
The second matrix M2 is empty but has the same row and column indexs. I need to fill M2 with the help of M1. For eample, in M2, at row 3 and colm 4 ( 34,the first entry of M1) will be 00 ( index of the first entry of M1). In M2 at row 6 col A, the entry will be 01, at row 2 col 9, the entry will be 02, and so on.
%% % Initialize M2 with zeros
M2 = zeros(16,16);
for row = 0:15
for col = 0:15
% get the value from M1
value= M1(row+1,col+1);
% Convert the values to row and col indices for M2
hexStr=dec2hex(value,2); % convert to 2 digit hex
M2_row=hex2dec(hexStr(1))+1;% convert first digit to decimal
M2_col=hex2dec(hexStr(2))+1;% convert first digit to decimal
% %Debugging
% % place the original rows and columns in M2
%
M2(M2_row, M2_col)=row*16+col;
end
end
M2;
If anyone can help. Hello, I have two matrices, M1 ans M2. They both have rows and columns fom 0 to 9 and a to f (16 * 16) matrix.
Mi matrix is filled with random numbers form 0 to 255 in hex decimal notation.
The second matrix M2 is empty but has the same row and column indexs. I need to fill M2 with the help of M1. For eample, in M2, at row 3 and colm 4 ( 34,the first entry of M1) will be 00 ( index of the first entry of M1). In M2 at row 6 col A, the entry will be 01, at row 2 col 9, the entry will be 02, and so on.
%% % Initialize M2 with zeros
M2 = zeros(16,16);
for row = 0:15
for col = 0:15
% get the value from M1
value= M1(row+1,col+1);
% Convert the values to row and col indices for M2
hexStr=dec2hex(value,2); % convert to 2 digit hex
M2_row=hex2dec(hexStr(1))+1;% convert first digit to decimal
M2_col=hex2dec(hexStr(2))+1;% convert first digit to decimal
% %Debugging
% % place the original rows and columns in M2
%
M2(M2_row, M2_col)=row*16+col;
end
end
M2;
If anyone can help. matrix indexes MATLAB Answers — New Questions
How to create an overall legend that includes all appeared data groups?
I’m trying to make a plot, using the tiledlayout function to create 4 subplots, while in the first subplot, there are 5 data groups, while the remaining subplots only have four of those 5 groups. If I create an overall legend, it will only show 4 groups that appeared in all the subplots, and automatically omit the extra one that’s only shown in the first subplot, how to include that grounp into the overall legend as well? Thanks!I’m trying to make a plot, using the tiledlayout function to create 4 subplots, while in the first subplot, there are 5 data groups, while the remaining subplots only have four of those 5 groups. If I create an overall legend, it will only show 4 groups that appeared in all the subplots, and automatically omit the extra one that’s only shown in the first subplot, how to include that grounp into the overall legend as well? Thanks! I’m trying to make a plot, using the tiledlayout function to create 4 subplots, while in the first subplot, there are 5 data groups, while the remaining subplots only have four of those 5 groups. If I create an overall legend, it will only show 4 groups that appeared in all the subplots, and automatically omit the extra one that’s only shown in the first subplot, how to include that grounp into the overall legend as well? Thanks! plotting, legend, tiledlayout, subplots MATLAB Answers — New Questions
How to get cluster data after clustering in EEGLAB ?
Hello everyone
Hello everyone,I’m encountering some difficulties while analyzing EEG data using EEGLab. After clustering ICs using the K-means algorithm, I’m unsure about how to select meaningful clusters for further analysis.Specifically, I’d like to plot ERSPs for a chosen cluster (e.g., cluster 2) and then apply bootstrapping to the entire epoch. Subsequently, I want to set all non-significant ERSP values (p > 0.05) compared to this distribution to zero dB.Hello everyone
Hello everyone,I’m encountering some difficulties while analyzing EEG data using EEGLab. After clustering ICs using the K-means algorithm, I’m unsure about how to select meaningful clusters for further analysis.Specifically, I’d like to plot ERSPs for a chosen cluster (e.g., cluster 2) and then apply bootstrapping to the entire epoch. Subsequently, I want to set all non-significant ERSP values (p > 0.05) compared to this distribution to zero dB. Hello everyone
Hello everyone,I’m encountering some difficulties while analyzing EEG data using EEGLab. After clustering ICs using the K-means algorithm, I’m unsure about how to select meaningful clusters for further analysis.Specifically, I’d like to plot ERSPs for a chosen cluster (e.g., cluster 2) and then apply bootstrapping to the entire epoch. Subsequently, I want to set all non-significant ERSP values (p > 0.05) compared to this distribution to zero dB. matlab, eeglab, eeg, ersp, clustering MATLAB Answers — New Questions
Only algebraic system equations in Model Predictive Control Toolbox?
My goal ist to use Model Predictive Control (MPC) for high-level planning. Instead of having differential equations I want to use only algebraic equations in the state function.
The equations would be in the form . Is there a way to define the MPC state functions as such?
Preferably I would use the nonlinear version of MPC.
Thank you very much.
Best regards,
MartinMy goal ist to use Model Predictive Control (MPC) for high-level planning. Instead of having differential equations I want to use only algebraic equations in the state function.
The equations would be in the form . Is there a way to define the MPC state functions as such?
Preferably I would use the nonlinear version of MPC.
Thank you very much.
Best regards,
Martin My goal ist to use Model Predictive Control (MPC) for high-level planning. Instead of having differential equations I want to use only algebraic equations in the state function.
The equations would be in the form . Is there a way to define the MPC state functions as such?
Preferably I would use the nonlinear version of MPC.
Thank you very much.
Best regards,
Martin mpc, algebraic equation MATLAB Answers — New Questions
Controller update in a discrete system
Hello everyone, I have a question
I have a continuous system that updates every 0.001 seconds.
In addition to this, I have a controller that should be updated with a delay of at least 100 times the system (ie every 100 iterations it is updated)
My question is this:
Do I need to calculate the signal and its derivatives and in addition the error and its derivative with T or with dt? I’m not sure..
The system is denoted as y_pk
The required signal is denoted as y_dk
This is part of my code:
dt=0.001; %discrete time
T=0.1; %continoues time
y_d = sin(1 * time); % desired signal
dy_d = diff(y_d) / dt;
ddy_d = diff(dy_d) / dt;
%initialize:
y_dk1=0; dy_dk1=0; uk2=0; uk1=0;
firstrun=true;
for j = 1:length(time)
y_dk = y_d(j);
if mod(j, 100) == 0 ||firstrun
T=dt; % ??
dy_dk = (y_dk-y_dk1)/T; %derv of y_dk
ddy_dk = (dy_dk – dy_dk1)/T; %second derv of y_dk
ek = y_dk – y_pk;
de_k = dy_dk – dy_pk;
uk = (1/c)*(a1*dy_pk + b1*(dy_pk)^2 + a2*y_pk + b2*(y_pk)^2 +k_p*ek + k_d*de_k + ddy_dk); % u: control input
% Store data for nex step:
uk2=uk1;
uk1=uk;
firstrun=false;
end
y_pk = …. ; %update each 0.001 second (continoues time)
dy_pk = (y_pk-y_pk1)/dt; %derv of y_pk
% Store data for nex step: system
y_pk2=y_pk1;
y_pk1=y_pk;
Thank you all!! :)Hello everyone, I have a question
I have a continuous system that updates every 0.001 seconds.
In addition to this, I have a controller that should be updated with a delay of at least 100 times the system (ie every 100 iterations it is updated)
My question is this:
Do I need to calculate the signal and its derivatives and in addition the error and its derivative with T or with dt? I’m not sure..
The system is denoted as y_pk
The required signal is denoted as y_dk
This is part of my code:
dt=0.001; %discrete time
T=0.1; %continoues time
y_d = sin(1 * time); % desired signal
dy_d = diff(y_d) / dt;
ddy_d = diff(dy_d) / dt;
%initialize:
y_dk1=0; dy_dk1=0; uk2=0; uk1=0;
firstrun=true;
for j = 1:length(time)
y_dk = y_d(j);
if mod(j, 100) == 0 ||firstrun
T=dt; % ??
dy_dk = (y_dk-y_dk1)/T; %derv of y_dk
ddy_dk = (dy_dk – dy_dk1)/T; %second derv of y_dk
ek = y_dk – y_pk;
de_k = dy_dk – dy_pk;
uk = (1/c)*(a1*dy_pk + b1*(dy_pk)^2 + a2*y_pk + b2*(y_pk)^2 +k_p*ek + k_d*de_k + ddy_dk); % u: control input
% Store data for nex step:
uk2=uk1;
uk1=uk;
firstrun=false;
end
y_pk = …. ; %update each 0.001 second (continoues time)
dy_pk = (y_pk-y_pk1)/dt; %derv of y_pk
% Store data for nex step: system
y_pk2=y_pk1;
y_pk1=y_pk;
Thank you all!! 🙂 Hello everyone, I have a question
I have a continuous system that updates every 0.001 seconds.
In addition to this, I have a controller that should be updated with a delay of at least 100 times the system (ie every 100 iterations it is updated)
My question is this:
Do I need to calculate the signal and its derivatives and in addition the error and its derivative with T or with dt? I’m not sure..
The system is denoted as y_pk
The required signal is denoted as y_dk
This is part of my code:
dt=0.001; %discrete time
T=0.1; %continoues time
y_d = sin(1 * time); % desired signal
dy_d = diff(y_d) / dt;
ddy_d = diff(dy_d) / dt;
%initialize:
y_dk1=0; dy_dk1=0; uk2=0; uk1=0;
firstrun=true;
for j = 1:length(time)
y_dk = y_d(j);
if mod(j, 100) == 0 ||firstrun
T=dt; % ??
dy_dk = (y_dk-y_dk1)/T; %derv of y_dk
ddy_dk = (dy_dk – dy_dk1)/T; %second derv of y_dk
ek = y_dk – y_pk;
de_k = dy_dk – dy_pk;
uk = (1/c)*(a1*dy_pk + b1*(dy_pk)^2 + a2*y_pk + b2*(y_pk)^2 +k_p*ek + k_d*de_k + ddy_dk); % u: control input
% Store data for nex step:
uk2=uk1;
uk1=uk;
firstrun=false;
end
y_pk = …. ; %update each 0.001 second (continoues time)
dy_pk = (y_pk-y_pk1)/dt; %derv of y_pk
% Store data for nex step: system
y_pk2=y_pk1;
y_pk1=y_pk;
Thank you all!! 🙂 control, discrete system, controller MATLAB Answers — New Questions