Category: Matlab
Category Archives: Matlab
average between cell arrays of doubles
Hello, I’m working with a nested cell array in which each original cell contains a nested cell array of doubles.
For simplicity, the original nested array could have 10 cell arrays within it. For each of those cell arrays, there are 100 doubles that are 30×50 in length. I would like to get the mean/average of all of those doubles such that they go from 100 instances of 30×50 doubles to just 1 single instance of 30×50 double.
This would result with the average value found in each element of the double across the instances. This would mean that the original cell array is now 10 cells, with each having only one instance of 30×50 double as their individual averages.
Please let me know if you need more information to help me with calculating the average. Thank you!Hello, I’m working with a nested cell array in which each original cell contains a nested cell array of doubles.
For simplicity, the original nested array could have 10 cell arrays within it. For each of those cell arrays, there are 100 doubles that are 30×50 in length. I would like to get the mean/average of all of those doubles such that they go from 100 instances of 30×50 doubles to just 1 single instance of 30×50 double.
This would result with the average value found in each element of the double across the instances. This would mean that the original cell array is now 10 cells, with each having only one instance of 30×50 double as their individual averages.
Please let me know if you need more information to help me with calculating the average. Thank you! Hello, I’m working with a nested cell array in which each original cell contains a nested cell array of doubles.
For simplicity, the original nested array could have 10 cell arrays within it. For each of those cell arrays, there are 100 doubles that are 30×50 in length. I would like to get the mean/average of all of those doubles such that they go from 100 instances of 30×50 doubles to just 1 single instance of 30×50 double.
This would result with the average value found in each element of the double across the instances. This would mean that the original cell array is now 10 cells, with each having only one instance of 30×50 double as their individual averages.
Please let me know if you need more information to help me with calculating the average. Thank you! nested cell array, average MATLAB Answers — New Questions
Finding accurate inverse of binary circulant matrix
I would like to find the inverse of a binary circulant matrix using MATLAB. I have the 24×24 binary circulant matrix stored in BCM and use the function inv(BCM) and I get a lot of garbage values. I have the inverse matrix that I am expecting to get, which is the multiplicative inverse of BCM. When I multiply them in MATLAB, I get the identity matrix which is correct. However, I’m going to need to calculate new inverses of new matrices and would like to do so with MATLAB instead of guessing over and over. How can I do this?
Both BCM and it’s inverse are stored in the attached Excel spreadsheet. Thank you!
Garbage Values:I would like to find the inverse of a binary circulant matrix using MATLAB. I have the 24×24 binary circulant matrix stored in BCM and use the function inv(BCM) and I get a lot of garbage values. I have the inverse matrix that I am expecting to get, which is the multiplicative inverse of BCM. When I multiply them in MATLAB, I get the identity matrix which is correct. However, I’m going to need to calculate new inverses of new matrices and would like to do so with MATLAB instead of guessing over and over. How can I do this?
Both BCM and it’s inverse are stored in the attached Excel spreadsheet. Thank you!
Garbage Values: I would like to find the inverse of a binary circulant matrix using MATLAB. I have the 24×24 binary circulant matrix stored in BCM and use the function inv(BCM) and I get a lot of garbage values. I have the inverse matrix that I am expecting to get, which is the multiplicative inverse of BCM. When I multiply them in MATLAB, I get the identity matrix which is correct. However, I’m going to need to calculate new inverses of new matrices and would like to do so with MATLAB instead of guessing over and over. How can I do this?
Both BCM and it’s inverse are stored in the attached Excel spreadsheet. Thank you!
Garbage Values: matrix, matrices, binary, circulant matrix, inverse MATLAB Answers — New Questions
I want to calculate distances in 3D space. How do I apply my code to all tables in all cells?
Hi,
I want to use the formula d = sqrt((x2 – x1)^2 + (y2 – y1)^2 + (z2 – z1)^2) to calculate two distances. Each distance is between two points in 3D space twice. Once from point A to point B, and one is from point A to point C. I have a data set with cell array where each cell contains tables.
he tables in the cells are built up so that the x, y and z positional coordinates of point A are in column 1, 2 and 3. The x, y, and z positional coordinates of point B are in columns 4, 5, and 6. And the x, y, and z positional coordinates of point C are in columns 7, 8 and 9.
I have the code below:
results_distances = cell(size(results_nooutliers));
% Initialize a cell array to store the distances
results_distances = cell(size(results_nooutliers));
% Loop through each cell in the results_no_outliers array
for i = 1:numel(results_nooutliers)
% Get the current table for the participant
this_cell = results_nooutliers{i};
% Check for empty cells
if isempty(this_cell)
continue; % Skip empty cells
end
% Initialize arrays to store distances for right hand and left hand
distances_A_B = zeros(size(this_cell, 1), 1);
distances_A_C = zeros(size(this_cell, 1), 1);
% Calculate distances for each row in the table
for row = 1:size(this_cell, 1)
% Calculate distance for left hand
distances_A_B(row) = sqrt((this_cell{row, 4} – this_cell{row, 1})^2 + …
(this_cell{row, 5} – this_cell{row, 2})^2 + …
(this_cell{row, 6} – this_cell{row, 3})^2);
% Calculate distance for right hand
distances_A_C(row) = sqrt((this_cell{row, 7} – this_cell{row, 1})^2 + …
(this_cell{row, 8} – this_cell{row, 2})^2 + …
(this_cell{row, 9} – this_cell{row, 3})^2);
end
% Store distances for the current participant in a table
results_distances{i} = table(distances_A_B, distances_A_C, ‘VariableNames’, {‘A_B_Distance’, ‘A_C_Distance’});
end
When running I get the error:
Undefined function ‘minus’ for input arguments of type ‘table’.
Can anybody tell me what I am doing incorrectly?
I have attached a small sample of my data set (it is much longer in actuality).
Thanks for the help!Hi,
I want to use the formula d = sqrt((x2 – x1)^2 + (y2 – y1)^2 + (z2 – z1)^2) to calculate two distances. Each distance is between two points in 3D space twice. Once from point A to point B, and one is from point A to point C. I have a data set with cell array where each cell contains tables.
he tables in the cells are built up so that the x, y and z positional coordinates of point A are in column 1, 2 and 3. The x, y, and z positional coordinates of point B are in columns 4, 5, and 6. And the x, y, and z positional coordinates of point C are in columns 7, 8 and 9.
I have the code below:
results_distances = cell(size(results_nooutliers));
% Initialize a cell array to store the distances
results_distances = cell(size(results_nooutliers));
% Loop through each cell in the results_no_outliers array
for i = 1:numel(results_nooutliers)
% Get the current table for the participant
this_cell = results_nooutliers{i};
% Check for empty cells
if isempty(this_cell)
continue; % Skip empty cells
end
% Initialize arrays to store distances for right hand and left hand
distances_A_B = zeros(size(this_cell, 1), 1);
distances_A_C = zeros(size(this_cell, 1), 1);
% Calculate distances for each row in the table
for row = 1:size(this_cell, 1)
% Calculate distance for left hand
distances_A_B(row) = sqrt((this_cell{row, 4} – this_cell{row, 1})^2 + …
(this_cell{row, 5} – this_cell{row, 2})^2 + …
(this_cell{row, 6} – this_cell{row, 3})^2);
% Calculate distance for right hand
distances_A_C(row) = sqrt((this_cell{row, 7} – this_cell{row, 1})^2 + …
(this_cell{row, 8} – this_cell{row, 2})^2 + …
(this_cell{row, 9} – this_cell{row, 3})^2);
end
% Store distances for the current participant in a table
results_distances{i} = table(distances_A_B, distances_A_C, ‘VariableNames’, {‘A_B_Distance’, ‘A_C_Distance’});
end
When running I get the error:
Undefined function ‘minus’ for input arguments of type ‘table’.
Can anybody tell me what I am doing incorrectly?
I have attached a small sample of my data set (it is much longer in actuality).
Thanks for the help! Hi,
I want to use the formula d = sqrt((x2 – x1)^2 + (y2 – y1)^2 + (z2 – z1)^2) to calculate two distances. Each distance is between two points in 3D space twice. Once from point A to point B, and one is from point A to point C. I have a data set with cell array where each cell contains tables.
he tables in the cells are built up so that the x, y and z positional coordinates of point A are in column 1, 2 and 3. The x, y, and z positional coordinates of point B are in columns 4, 5, and 6. And the x, y, and z positional coordinates of point C are in columns 7, 8 and 9.
I have the code below:
results_distances = cell(size(results_nooutliers));
% Initialize a cell array to store the distances
results_distances = cell(size(results_nooutliers));
% Loop through each cell in the results_no_outliers array
for i = 1:numel(results_nooutliers)
% Get the current table for the participant
this_cell = results_nooutliers{i};
% Check for empty cells
if isempty(this_cell)
continue; % Skip empty cells
end
% Initialize arrays to store distances for right hand and left hand
distances_A_B = zeros(size(this_cell, 1), 1);
distances_A_C = zeros(size(this_cell, 1), 1);
% Calculate distances for each row in the table
for row = 1:size(this_cell, 1)
% Calculate distance for left hand
distances_A_B(row) = sqrt((this_cell{row, 4} – this_cell{row, 1})^2 + …
(this_cell{row, 5} – this_cell{row, 2})^2 + …
(this_cell{row, 6} – this_cell{row, 3})^2);
% Calculate distance for right hand
distances_A_C(row) = sqrt((this_cell{row, 7} – this_cell{row, 1})^2 + …
(this_cell{row, 8} – this_cell{row, 2})^2 + …
(this_cell{row, 9} – this_cell{row, 3})^2);
end
% Store distances for the current participant in a table
results_distances{i} = table(distances_A_B, distances_A_C, ‘VariableNames’, {‘A_B_Distance’, ‘A_C_Distance’});
end
When running I get the error:
Undefined function ‘minus’ for input arguments of type ‘table’.
Can anybody tell me what I am doing incorrectly?
I have attached a small sample of my data set (it is much longer in actuality).
Thanks for the help! tables, rows, cell array, error, function, distances MATLAB Answers — New Questions
Delay Balancing Error (RTL Code/ IP Core generation)
Hallo everybody
I am using MATLAB/SIMULINK and HDL Coder to generate and IP Core for the ZedBoard DevKit.
I am encountering an issue with the "Delay Balancing" option. Basically SIMULINK got stuck during the HDL Code generation with the following error message:
“Error Delay balancing unsuccessful because Delay introduced in feedback loop cannot be path balanced. Offending Block: ……/Trigonometric Function”
1. Could someone please explain me the reason why this is happening ?
2. Could someone please explain me what should I do to avoid this situation?
I find a workaround for this issue. I have done the following changes:
– I put the "Trigonometric Fucntion" blocks into a subsystem (called "Trigonometric Fcn")
– I have disabled the "BalanceDelays" option from the HDL Coder properties
– I have set to "OFF" the "BalanceDelays" option for the "TOP" subsystem of the model
– I have left set to "Inherit" the "BalanceDelays" option for the other subsystems of the model
– but I have set to "ON" the "BalanceDelays" option for the "Trigonometric Fcn" subsystems of the model
– I have generated the "Validation Model" and I have verified that the results match the original one
This allow me to generate the HDL code and continue to the creation of the IP Core and the Vivado project.
But I would like to keep the BalanceDelays option "ON" otherwise the HDL code won’t be optimised in terms of area and timing performance.
3. Could someone please give me the correct solution to this error?
I am sorry, but I cannot share the code otherwise I would attached the model and other useful information.
Thank you in advance,
Andrea ForadoriHallo everybody
I am using MATLAB/SIMULINK and HDL Coder to generate and IP Core for the ZedBoard DevKit.
I am encountering an issue with the "Delay Balancing" option. Basically SIMULINK got stuck during the HDL Code generation with the following error message:
“Error Delay balancing unsuccessful because Delay introduced in feedback loop cannot be path balanced. Offending Block: ……/Trigonometric Function”
1. Could someone please explain me the reason why this is happening ?
2. Could someone please explain me what should I do to avoid this situation?
I find a workaround for this issue. I have done the following changes:
– I put the "Trigonometric Fucntion" blocks into a subsystem (called "Trigonometric Fcn")
– I have disabled the "BalanceDelays" option from the HDL Coder properties
– I have set to "OFF" the "BalanceDelays" option for the "TOP" subsystem of the model
– I have left set to "Inherit" the "BalanceDelays" option for the other subsystems of the model
– but I have set to "ON" the "BalanceDelays" option for the "Trigonometric Fcn" subsystems of the model
– I have generated the "Validation Model" and I have verified that the results match the original one
This allow me to generate the HDL code and continue to the creation of the IP Core and the Vivado project.
But I would like to keep the BalanceDelays option "ON" otherwise the HDL code won’t be optimised in terms of area and timing performance.
3. Could someone please give me the correct solution to this error?
I am sorry, but I cannot share the code otherwise I would attached the model and other useful information.
Thank you in advance,
Andrea Foradori Hallo everybody
I am using MATLAB/SIMULINK and HDL Coder to generate and IP Core for the ZedBoard DevKit.
I am encountering an issue with the "Delay Balancing" option. Basically SIMULINK got stuck during the HDL Code generation with the following error message:
“Error Delay balancing unsuccessful because Delay introduced in feedback loop cannot be path balanced. Offending Block: ……/Trigonometric Function”
1. Could someone please explain me the reason why this is happening ?
2. Could someone please explain me what should I do to avoid this situation?
I find a workaround for this issue. I have done the following changes:
– I put the "Trigonometric Fucntion" blocks into a subsystem (called "Trigonometric Fcn")
– I have disabled the "BalanceDelays" option from the HDL Coder properties
– I have set to "OFF" the "BalanceDelays" option for the "TOP" subsystem of the model
– I have left set to "Inherit" the "BalanceDelays" option for the other subsystems of the model
– but I have set to "ON" the "BalanceDelays" option for the "Trigonometric Fcn" subsystems of the model
– I have generated the "Validation Model" and I have verified that the results match the original one
This allow me to generate the HDL code and continue to the creation of the IP Core and the Vivado project.
But I would like to keep the BalanceDelays option "ON" otherwise the HDL code won’t be optimised in terms of area and timing performance.
3. Could someone please give me the correct solution to this error?
I am sorry, but I cannot share the code otherwise I would attached the model and other useful information.
Thank you in advance,
Andrea Foradori matlab, simulink, simulink hdl coder MATLAB Answers — New Questions
Accessing data from same variables within different tables in a structural array
Hi, I am fairly new at this, so please bear with me…
I have created a struct 1×20 containing twenty 87×6 tables, each containing data from different patients in a study (n=1:20).
Each table is made up of the same 6 variables: TimeAge, TimeCooling, TempCore, etc.. (others really don’t matter).
p(n).data.TimeCooling
p(n).data.TempCore
TimeAge and TimeCooling are both in hours and each range from approximately 0 to 85.
How can I access the data from the tables for specific time points?
I would like to find the mean of the variable TempCore of all patients at the same timepoint. (i.e. I want to know the mean of all patients at TimeCooling = 1 hour, then at 2 hours, etc.)
There is some missing data in TempCore that may need to be accounted for.
Any help would be greatly appreciated!Hi, I am fairly new at this, so please bear with me…
I have created a struct 1×20 containing twenty 87×6 tables, each containing data from different patients in a study (n=1:20).
Each table is made up of the same 6 variables: TimeAge, TimeCooling, TempCore, etc.. (others really don’t matter).
p(n).data.TimeCooling
p(n).data.TempCore
TimeAge and TimeCooling are both in hours and each range from approximately 0 to 85.
How can I access the data from the tables for specific time points?
I would like to find the mean of the variable TempCore of all patients at the same timepoint. (i.e. I want to know the mean of all patients at TimeCooling = 1 hour, then at 2 hours, etc.)
There is some missing data in TempCore that may need to be accounted for.
Any help would be greatly appreciated! Hi, I am fairly new at this, so please bear with me…
I have created a struct 1×20 containing twenty 87×6 tables, each containing data from different patients in a study (n=1:20).
Each table is made up of the same 6 variables: TimeAge, TimeCooling, TempCore, etc.. (others really don’t matter).
p(n).data.TimeCooling
p(n).data.TempCore
TimeAge and TimeCooling are both in hours and each range from approximately 0 to 85.
How can I access the data from the tables for specific time points?
I would like to find the mean of the variable TempCore of all patients at the same timepoint. (i.e. I want to know the mean of all patients at TimeCooling = 1 hour, then at 2 hours, etc.)
There is some missing data in TempCore that may need to be accounted for.
Any help would be greatly appreciated! table, array, basic MATLAB Answers — New Questions
Create zero-thickness surface in a 3D partial differential equation problem
I am struggling to create the geometry that I want to use in the Matlab PDE modeling interface. I want my model to consist of a zero-thickness triangulated sheet embedded in a tetrahedral mesh of a sphere. I need to address the faces or nodes that lie on the sheets in order to prescribe boundary conditions there.
It’s easy to create the outer sphere in the PDE modeling environment:
g1 = multisphere(R)
However I am really struggling to define the zero thickness triangulated sheet geometry inside the sphere.
g2 = geometryFromMesh(mesh,nodes,elements) throws an error if the triangulation described by the input node and element lists does not form a closed boundary. This seems like a limitation of the modeling interface. Any ideas on how to create the geometry within the PDE modeling environment?
Alternatively…
Using a workaround, I created the FE mesh outside the PDE modeling environment. I am able to import this entire mesh into the interface just fine, albiet without any Faces, Edges, or Vertices definitions.
However, it’s apparently not possible to prescribe boundary conditions directly at mesh nodes in the PDE modeling interface – boundary conditions can only be prescribed onto geometry vertices. Is there a way to map mesh nodes to geometry vertices?I am struggling to create the geometry that I want to use in the Matlab PDE modeling interface. I want my model to consist of a zero-thickness triangulated sheet embedded in a tetrahedral mesh of a sphere. I need to address the faces or nodes that lie on the sheets in order to prescribe boundary conditions there.
It’s easy to create the outer sphere in the PDE modeling environment:
g1 = multisphere(R)
However I am really struggling to define the zero thickness triangulated sheet geometry inside the sphere.
g2 = geometryFromMesh(mesh,nodes,elements) throws an error if the triangulation described by the input node and element lists does not form a closed boundary. This seems like a limitation of the modeling interface. Any ideas on how to create the geometry within the PDE modeling environment?
Alternatively…
Using a workaround, I created the FE mesh outside the PDE modeling environment. I am able to import this entire mesh into the interface just fine, albiet without any Faces, Edges, or Vertices definitions.
However, it’s apparently not possible to prescribe boundary conditions directly at mesh nodes in the PDE modeling interface – boundary conditions can only be prescribed onto geometry vertices. Is there a way to map mesh nodes to geometry vertices? I am struggling to create the geometry that I want to use in the Matlab PDE modeling interface. I want my model to consist of a zero-thickness triangulated sheet embedded in a tetrahedral mesh of a sphere. I need to address the faces or nodes that lie on the sheets in order to prescribe boundary conditions there.
It’s easy to create the outer sphere in the PDE modeling environment:
g1 = multisphere(R)
However I am really struggling to define the zero thickness triangulated sheet geometry inside the sphere.
g2 = geometryFromMesh(mesh,nodes,elements) throws an error if the triangulation described by the input node and element lists does not form a closed boundary. This seems like a limitation of the modeling interface. Any ideas on how to create the geometry within the PDE modeling environment?
Alternatively…
Using a workaround, I created the FE mesh outside the PDE modeling environment. I am able to import this entire mesh into the interface just fine, albiet without any Faces, Edges, or Vertices definitions.
However, it’s apparently not possible to prescribe boundary conditions directly at mesh nodes in the PDE modeling interface – boundary conditions can only be prescribed onto geometry vertices. Is there a way to map mesh nodes to geometry vertices? partial differential equations, mesh nodes, importgeometry, geometryfrommesh MATLAB Answers — New Questions
integral of the besselj function
how to count the integral of the besselj function from 0 to 4pi?how to count the integral of the besselj function from 0 to 4pi? how to count the integral of the besselj function from 0 to 4pi? besselj, integral, matlab MATLAB Answers — New Questions
I have purchased the Signal Processing Toolbox but still get an error when trying to use a function
I have purchased the Signal Processing Toolbox, but MATLAB still throws a "you need the Signal Processing Toolbox" error when I try to use the square function per the screenshot. I have tried reinstalling MATLAB and restarting the program.I have purchased the Signal Processing Toolbox, but MATLAB still throws a "you need the Signal Processing Toolbox" error when I try to use the square function per the screenshot. I have tried reinstalling MATLAB and restarting the program. I have purchased the Signal Processing Toolbox, but MATLAB still throws a "you need the Signal Processing Toolbox" error when I try to use the square function per the screenshot. I have tried reinstalling MATLAB and restarting the program. signal processing MATLAB Answers — New Questions
One function is greater than other
I would like to determine the range of values for ( z ) where the following inequality holds true:
this is my trying
syms z real
assume(z > exp(1))
% Define the function
f = z – 8.02 * log(z) – (3.359 / 21.233) * log(z) * z;
sol = solve(f > 0, z, ‘ReturnConditions’, true);
vpa(sol.conditions)I would like to determine the range of values for ( z ) where the following inequality holds true:
this is my trying
syms z real
assume(z > exp(1))
% Define the function
f = z – 8.02 * log(z) – (3.359 / 21.233) * log(z) * z;
sol = solve(f > 0, z, ‘ReturnConditions’, true);
vpa(sol.conditions) I would like to determine the range of values for ( z ) where the following inequality holds true:
this is my trying
syms z real
assume(z > exp(1))
% Define the function
f = z – 8.02 * log(z) – (3.359 / 21.233) * log(z) * z;
sol = solve(f > 0, z, ‘ReturnConditions’, true);
vpa(sol.conditions) @staff MATLAB Answers — New Questions
Inverse model for feedforward control
Hello,
I want to implement a feedforward control for good trajectory tracking (feedback path for disturbance rejection comes afterwards).
The system model is an electrical RL-circuit in series with a voltage source. (schematics).
I determined the continuous transfer function to be:
The inverse of this is
(I know that this transfer function can not be realized in physical systems since, but I would hope that simulink lets me simulate the ideal system).
If I combine G^-1 and G in simulink, I would expect to obtain ideal trajectory tracking, because G^-1 * G = 1
However the following model only achieves ideal tracking, if I add a factor of 6 at the marked position. (R=3, L – 0.004, solver is fixed step ode4, 1e-4s stepsize)
Why do I need to add a factor of 6 there?Hello,
I want to implement a feedforward control for good trajectory tracking (feedback path for disturbance rejection comes afterwards).
The system model is an electrical RL-circuit in series with a voltage source. (schematics).
I determined the continuous transfer function to be:
The inverse of this is
(I know that this transfer function can not be realized in physical systems since, but I would hope that simulink lets me simulate the ideal system).
If I combine G^-1 and G in simulink, I would expect to obtain ideal trajectory tracking, because G^-1 * G = 1
However the following model only achieves ideal tracking, if I add a factor of 6 at the marked position. (R=3, L – 0.004, solver is fixed step ode4, 1e-4s stepsize)
Why do I need to add a factor of 6 there? Hello,
I want to implement a feedforward control for good trajectory tracking (feedback path for disturbance rejection comes afterwards).
The system model is an electrical RL-circuit in series with a voltage source. (schematics).
I determined the continuous transfer function to be:
The inverse of this is
(I know that this transfer function can not be realized in physical systems since, but I would hope that simulink lets me simulate the ideal system).
If I combine G^-1 and G in simulink, I would expect to obtain ideal trajectory tracking, because G^-1 * G = 1
However the following model only achieves ideal tracking, if I add a factor of 6 at the marked position. (R=3, L – 0.004, solver is fixed step ode4, 1e-4s stepsize)
Why do I need to add a factor of 6 there? simulink, feedforward, control, laplace MATLAB Answers — New Questions
Vectorized Levenshtein distances between arrays of text labels?
I have to compare "N" ID labels (several thousand) to each other in order to determine which are mistypings of each other. The labels have up to 20 characters. Preliminarily, I am considering the calculation of the N(N-1)/2 Levenshtein distances between them and using clustering which labels correspond to the same ID. It is being done in Python, but none of the Levenshtein distance implementations are vectorized. The NxN array of distances is iterated through on an element-by-element basis.
I thought that there might be a vectorized Matlab version of Levenshtein distance, which I could package for deployment and invocation from Python. I found the a few shown in the Annex below, as well as an "editDistance" function available in R2023b. None of these vectorize the calculation of N(N-2)/2 distances. I’m surprised that a vectorized implementation doesn’t exist. Am I missing something obvious?
Annex: Matlab implementations of Levenshtein distance
https://people.math.sc.edu/Burkardt/m_src/levenshtein/levenshtein.html
https://www.mathworks.com/matlabcentral/fileexchange/17585-calculation-of-distance-between-strings
https://blogs.mathworks.com/cleve/2017/08/14/levenshtein-edit-distance-between-stringsI have to compare "N" ID labels (several thousand) to each other in order to determine which are mistypings of each other. The labels have up to 20 characters. Preliminarily, I am considering the calculation of the N(N-1)/2 Levenshtein distances between them and using clustering which labels correspond to the same ID. It is being done in Python, but none of the Levenshtein distance implementations are vectorized. The NxN array of distances is iterated through on an element-by-element basis.
I thought that there might be a vectorized Matlab version of Levenshtein distance, which I could package for deployment and invocation from Python. I found the a few shown in the Annex below, as well as an "editDistance" function available in R2023b. None of these vectorize the calculation of N(N-2)/2 distances. I’m surprised that a vectorized implementation doesn’t exist. Am I missing something obvious?
Annex: Matlab implementations of Levenshtein distance
https://people.math.sc.edu/Burkardt/m_src/levenshtein/levenshtein.html
https://www.mathworks.com/matlabcentral/fileexchange/17585-calculation-of-distance-between-strings
https://blogs.mathworks.com/cleve/2017/08/14/levenshtein-edit-distance-between-strings I have to compare "N" ID labels (several thousand) to each other in order to determine which are mistypings of each other. The labels have up to 20 characters. Preliminarily, I am considering the calculation of the N(N-1)/2 Levenshtein distances between them and using clustering which labels correspond to the same ID. It is being done in Python, but none of the Levenshtein distance implementations are vectorized. The NxN array of distances is iterated through on an element-by-element basis.
I thought that there might be a vectorized Matlab version of Levenshtein distance, which I could package for deployment and invocation from Python. I found the a few shown in the Annex below, as well as an "editDistance" function available in R2023b. None of these vectorize the calculation of N(N-2)/2 distances. I’m surprised that a vectorized implementation doesn’t exist. Am I missing something obvious?
Annex: Matlab implementations of Levenshtein distance
https://people.math.sc.edu/Burkardt/m_src/levenshtein/levenshtein.html
https://www.mathworks.com/matlabcentral/fileexchange/17585-calculation-of-distance-between-strings
https://blogs.mathworks.com/cleve/2017/08/14/levenshtein-edit-distance-between-strings levenshtein-distance, vectorized MATLAB Answers — New Questions
difference between 2 values in a vector
Hello Community.
Asking for your help again to find a solution…..
I have a vector with several data points, I’d like to get the difference between each value that is not equal to CERO.
I’m using "diff" command however this includes the difference betwee values that are equal to CERO, here is an example.
x = [0.2 0.0 0.0 0.0 0.25 0.0 0.0 0.0 0.3 0.0 0.0 0.4 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.35 ]
I tried this : b = diff(x)
b = -0.20 0.0 0.0 0.25 -0.25 0.0 0.0 0.30 -0.30 0.0 0.40 -0.40 0.0 0.0 0.10 -0.10 0.0 0.0 0.35
it gives me the difference between each data point
What I’m trying to get is the difference between each point that is not equal to cero like this:
b = 0.0 0.0 0.0 0.0 0.05 0.0 0.0 0.0 0.05 0.0 0.0 0.1 0.0 0.0 0.0 -0.3 0.0 0.0 0.0 0.25
I don’t want to eliminate the ceros in between if I do so it will change the length of the vector and I need to keep same lenght to compare Vs other signals.
the number of ceros between each data value is not always the same, could be 3 ceros in between but it could be 2, 4, 6…..
as always I thank you in advance, your feedback will be higly appreciated.Hello Community.
Asking for your help again to find a solution…..
I have a vector with several data points, I’d like to get the difference between each value that is not equal to CERO.
I’m using "diff" command however this includes the difference betwee values that are equal to CERO, here is an example.
x = [0.2 0.0 0.0 0.0 0.25 0.0 0.0 0.0 0.3 0.0 0.0 0.4 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.35 ]
I tried this : b = diff(x)
b = -0.20 0.0 0.0 0.25 -0.25 0.0 0.0 0.30 -0.30 0.0 0.40 -0.40 0.0 0.0 0.10 -0.10 0.0 0.0 0.35
it gives me the difference between each data point
What I’m trying to get is the difference between each point that is not equal to cero like this:
b = 0.0 0.0 0.0 0.0 0.05 0.0 0.0 0.0 0.05 0.0 0.0 0.1 0.0 0.0 0.0 -0.3 0.0 0.0 0.0 0.25
I don’t want to eliminate the ceros in between if I do so it will change the length of the vector and I need to keep same lenght to compare Vs other signals.
the number of ceros between each data value is not always the same, could be 3 ceros in between but it could be 2, 4, 6…..
as always I thank you in advance, your feedback will be higly appreciated. Hello Community.
Asking for your help again to find a solution…..
I have a vector with several data points, I’d like to get the difference between each value that is not equal to CERO.
I’m using "diff" command however this includes the difference betwee values that are equal to CERO, here is an example.
x = [0.2 0.0 0.0 0.0 0.25 0.0 0.0 0.0 0.3 0.0 0.0 0.4 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.35 ]
I tried this : b = diff(x)
b = -0.20 0.0 0.0 0.25 -0.25 0.0 0.0 0.30 -0.30 0.0 0.40 -0.40 0.0 0.0 0.10 -0.10 0.0 0.0 0.35
it gives me the difference between each data point
What I’m trying to get is the difference between each point that is not equal to cero like this:
b = 0.0 0.0 0.0 0.0 0.05 0.0 0.0 0.0 0.05 0.0 0.0 0.1 0.0 0.0 0.0 -0.3 0.0 0.0 0.0 0.25
I don’t want to eliminate the ceros in between if I do so it will change the length of the vector and I need to keep same lenght to compare Vs other signals.
the number of ceros between each data value is not always the same, could be 3 ceros in between but it could be 2, 4, 6…..
as always I thank you in advance, your feedback will be higly appreciated. matlab MATLAB Answers — New Questions
looping thru multiple line data in UIAxes plot and writing all X,Y data to an array
Hello, i have a set of line plots on a UIAxes on a UIFigure using Appdesigner.
Note each plot has differing X coordinates
I want a way to be able to save all these plots so that I can revisit later and add further plots to it.
The approach I was going to take was to access the line objects and loop through assigning each X,Y datat set to a data array that I could save out and then recal at a later date.
ax=app.UIAxes;
L=ax.XLim;
L2=L(2); % Get max number on x-axis
h1 = findall(ax, ‘type’, ‘line’) % Get just line objects for now
n=numel(h1); % Number of line plots (will do text objectes later)
H=nan(L2,2*n) % Create an array of Nans to hold all data (row,cols)
% Each line requires its X data to be saved also
Now loop thru’ all line items and splat the X,Y data to the array
for(i=1:n)
t = h1(i)
H(:,(2*i)-1)=(t.XData)’;
H(:,2*i)=(t.YData)’;
end
H
But Im getting the following error
Unable to perform assignment because the size of the left side is 120-by-1 and the size of the right side is 100-by-1.
Error in GenericDataAnalysis/ReadHeadersButtonPushed (line 533)
H(:,(2*i)-1)=(t.XData)’;
I suspect its to do with non-equal length of data sets. Perhaps I need some sort of padding for the missing data?
This is my current output:
L2 =
120
h1 =
7×1 Line array:
Line (20s Delay)
Line (15s Delay)
Line (9s Delay)
Line (5s Delay)
Line (2s Delay)
Line (FC Top)
Line (FC Btm)
The second part of my question, is whats the best approach to retain the colours and text objects?
Remember, i don’t just want the graphic saved, I want to be able to add data to it later from within my GUI.
Thanks
JasonHello, i have a set of line plots on a UIAxes on a UIFigure using Appdesigner.
Note each plot has differing X coordinates
I want a way to be able to save all these plots so that I can revisit later and add further plots to it.
The approach I was going to take was to access the line objects and loop through assigning each X,Y datat set to a data array that I could save out and then recal at a later date.
ax=app.UIAxes;
L=ax.XLim;
L2=L(2); % Get max number on x-axis
h1 = findall(ax, ‘type’, ‘line’) % Get just line objects for now
n=numel(h1); % Number of line plots (will do text objectes later)
H=nan(L2,2*n) % Create an array of Nans to hold all data (row,cols)
% Each line requires its X data to be saved also
Now loop thru’ all line items and splat the X,Y data to the array
for(i=1:n)
t = h1(i)
H(:,(2*i)-1)=(t.XData)’;
H(:,2*i)=(t.YData)’;
end
H
But Im getting the following error
Unable to perform assignment because the size of the left side is 120-by-1 and the size of the right side is 100-by-1.
Error in GenericDataAnalysis/ReadHeadersButtonPushed (line 533)
H(:,(2*i)-1)=(t.XData)’;
I suspect its to do with non-equal length of data sets. Perhaps I need some sort of padding for the missing data?
This is my current output:
L2 =
120
h1 =
7×1 Line array:
Line (20s Delay)
Line (15s Delay)
Line (9s Delay)
Line (5s Delay)
Line (2s Delay)
Line (FC Top)
Line (FC Btm)
The second part of my question, is whats the best approach to retain the colours and text objects?
Remember, i don’t just want the graphic saved, I want to be able to add data to it later from within my GUI.
Thanks
Jason Hello, i have a set of line plots on a UIAxes on a UIFigure using Appdesigner.
Note each plot has differing X coordinates
I want a way to be able to save all these plots so that I can revisit later and add further plots to it.
The approach I was going to take was to access the line objects and loop through assigning each X,Y datat set to a data array that I could save out and then recal at a later date.
ax=app.UIAxes;
L=ax.XLim;
L2=L(2); % Get max number on x-axis
h1 = findall(ax, ‘type’, ‘line’) % Get just line objects for now
n=numel(h1); % Number of line plots (will do text objectes later)
H=nan(L2,2*n) % Create an array of Nans to hold all data (row,cols)
% Each line requires its X data to be saved also
Now loop thru’ all line items and splat the X,Y data to the array
for(i=1:n)
t = h1(i)
H(:,(2*i)-1)=(t.XData)’;
H(:,2*i)=(t.YData)’;
end
H
But Im getting the following error
Unable to perform assignment because the size of the left side is 120-by-1 and the size of the right side is 100-by-1.
Error in GenericDataAnalysis/ReadHeadersButtonPushed (line 533)
H(:,(2*i)-1)=(t.XData)’;
I suspect its to do with non-equal length of data sets. Perhaps I need some sort of padding for the missing data?
This is my current output:
L2 =
120
h1 =
7×1 Line array:
Line (20s Delay)
Line (15s Delay)
Line (9s Delay)
Line (5s Delay)
Line (2s Delay)
Line (FC Top)
Line (FC Btm)
The second part of my question, is whats the best approach to retain the colours and text objects?
Remember, i don’t just want the graphic saved, I want to be able to add data to it later from within my GUI.
Thanks
Jason uiaxes, plot MATLAB Answers — New Questions
finding value in 2d array function of x and y
Hi all, I realise this may be the first time I ask a question even though I’ve been using the forum for 12 years. Kudos to you for asking every question and answering everything that ever crossed my mind. Here’s my question:
Input data:
I have two vectors, Torque effmap.chainTQ and Speed effmap.chainRPM. They are two columns 1×100 elements
There is also a 2D array, much like below. For every (Torque,Speed) pair, there is a corresponding Efficiency value effmap.chainRPM
Processing:
I have a new pair of vectors, say vehicle.wheeltorque and vehicle.wheelspeed which are 1×1000. They represent a duty cycle, which the vehicle is going thru.
For every set of (vehicle.wheeltorque ,vehicle.wheelspeed) I need the code to find the closest value of Efficiency. I can’t figure this one out. I suppose it should be a double for loop of sorts and I found array indexing might be needed, but so far I couldn’t get it to work.
Example efficiency map:
What I tried, and works, is to take the base efficiency map, use interp2 and meshrid to refine it, and for a given single set of (testspeed,testtq) I can extract the Efficiency value – see the "point" value:
effmap.chainRPM = xlsread (’03b_DummychainLossmap’,’Chain’, ‘B3:B23’)
effmap.chainTQ = xlsread (’03b_DummychainLossmap’,’Chain’, ‘C2:W2’)
effmap.chainLoss = xlsread (’03b_DummychainLossmap’,’Chain’, ‘C3:W23’)
surf(effmap.chainRPM,effmap.chainTQ,effmap.chainLoss)
[MeshX,MeshY] = meshgrid(0:10:2000,0:10:2000) %mesh to create more points in a map/array
MeshQ = interp2(effmap.chainRPM,effmap.chainTQ,effmap.chainLoss,MeshX,MeshY,’spline’);
surf(MeshX,MeshY,MeshQ)
testspeed = 200
testtq = 1000
point = interp2(MeshX,MeshY,MeshQ,testtq,testspeed) %so now I know it works
However, it doesn’t work for a full vector of torque and speed :
linear_indices = sub2ind(MeshQ, MeshY(1,:), MeshX(1,:))
logical_indices = (MeshQ(:, 1) == MeshX & MeshQ(:, 2) == MeshY)
extracted_values = MeshQ(logical_indices, 🙂
for vehicle.wheeltorque(1:) to vehicle.wheeltorque(1:size(vehicle.wheeltorque))
………………..
I tried it in many ways, but fundamentally I don’t understand what the logic of the code should be. Help? Last thing, it needs to store the efficiency values in a vector for further analysis.
Cheers, ask if not clearHi all, I realise this may be the first time I ask a question even though I’ve been using the forum for 12 years. Kudos to you for asking every question and answering everything that ever crossed my mind. Here’s my question:
Input data:
I have two vectors, Torque effmap.chainTQ and Speed effmap.chainRPM. They are two columns 1×100 elements
There is also a 2D array, much like below. For every (Torque,Speed) pair, there is a corresponding Efficiency value effmap.chainRPM
Processing:
I have a new pair of vectors, say vehicle.wheeltorque and vehicle.wheelspeed which are 1×1000. They represent a duty cycle, which the vehicle is going thru.
For every set of (vehicle.wheeltorque ,vehicle.wheelspeed) I need the code to find the closest value of Efficiency. I can’t figure this one out. I suppose it should be a double for loop of sorts and I found array indexing might be needed, but so far I couldn’t get it to work.
Example efficiency map:
What I tried, and works, is to take the base efficiency map, use interp2 and meshrid to refine it, and for a given single set of (testspeed,testtq) I can extract the Efficiency value – see the "point" value:
effmap.chainRPM = xlsread (’03b_DummychainLossmap’,’Chain’, ‘B3:B23’)
effmap.chainTQ = xlsread (’03b_DummychainLossmap’,’Chain’, ‘C2:W2’)
effmap.chainLoss = xlsread (’03b_DummychainLossmap’,’Chain’, ‘C3:W23’)
surf(effmap.chainRPM,effmap.chainTQ,effmap.chainLoss)
[MeshX,MeshY] = meshgrid(0:10:2000,0:10:2000) %mesh to create more points in a map/array
MeshQ = interp2(effmap.chainRPM,effmap.chainTQ,effmap.chainLoss,MeshX,MeshY,’spline’);
surf(MeshX,MeshY,MeshQ)
testspeed = 200
testtq = 1000
point = interp2(MeshX,MeshY,MeshQ,testtq,testspeed) %so now I know it works
However, it doesn’t work for a full vector of torque and speed :
linear_indices = sub2ind(MeshQ, MeshY(1,:), MeshX(1,:))
logical_indices = (MeshQ(:, 1) == MeshX & MeshQ(:, 2) == MeshY)
extracted_values = MeshQ(logical_indices, 🙂
for vehicle.wheeltorque(1:) to vehicle.wheeltorque(1:size(vehicle.wheeltorque))
………………..
I tried it in many ways, but fundamentally I don’t understand what the logic of the code should be. Help? Last thing, it needs to store the efficiency values in a vector for further analysis.
Cheers, ask if not clear Hi all, I realise this may be the first time I ask a question even though I’ve been using the forum for 12 years. Kudos to you for asking every question and answering everything that ever crossed my mind. Here’s my question:
Input data:
I have two vectors, Torque effmap.chainTQ and Speed effmap.chainRPM. They are two columns 1×100 elements
There is also a 2D array, much like below. For every (Torque,Speed) pair, there is a corresponding Efficiency value effmap.chainRPM
Processing:
I have a new pair of vectors, say vehicle.wheeltorque and vehicle.wheelspeed which are 1×1000. They represent a duty cycle, which the vehicle is going thru.
For every set of (vehicle.wheeltorque ,vehicle.wheelspeed) I need the code to find the closest value of Efficiency. I can’t figure this one out. I suppose it should be a double for loop of sorts and I found array indexing might be needed, but so far I couldn’t get it to work.
Example efficiency map:
What I tried, and works, is to take the base efficiency map, use interp2 and meshrid to refine it, and for a given single set of (testspeed,testtq) I can extract the Efficiency value – see the "point" value:
effmap.chainRPM = xlsread (’03b_DummychainLossmap’,’Chain’, ‘B3:B23’)
effmap.chainTQ = xlsread (’03b_DummychainLossmap’,’Chain’, ‘C2:W2’)
effmap.chainLoss = xlsread (’03b_DummychainLossmap’,’Chain’, ‘C3:W23’)
surf(effmap.chainRPM,effmap.chainTQ,effmap.chainLoss)
[MeshX,MeshY] = meshgrid(0:10:2000,0:10:2000) %mesh to create more points in a map/array
MeshQ = interp2(effmap.chainRPM,effmap.chainTQ,effmap.chainLoss,MeshX,MeshY,’spline’);
surf(MeshX,MeshY,MeshQ)
testspeed = 200
testtq = 1000
point = interp2(MeshX,MeshY,MeshQ,testtq,testspeed) %so now I know it works
However, it doesn’t work for a full vector of torque and speed :
linear_indices = sub2ind(MeshQ, MeshY(1,:), MeshX(1,:))
logical_indices = (MeshQ(:, 1) == MeshX & MeshQ(:, 2) == MeshY)
extracted_values = MeshQ(logical_indices, 🙂
for vehicle.wheeltorque(1:) to vehicle.wheeltorque(1:size(vehicle.wheeltorque))
………………..
I tried it in many ways, but fundamentally I don’t understand what the logic of the code should be. Help? Last thing, it needs to store the efficiency values in a vector for further analysis.
Cheers, ask if not clear map, array, efficiency, dutycycle, script MATLAB Answers — New Questions
Why do I receive License Manager Error -13?
When I start MATLAB I receive the following error:
ERROR: License Manager Error -13.
No SERVER lines in license fileWhen I start MATLAB I receive the following error:
ERROR: License Manager Error -13.
No SERVER lines in license file When I start MATLAB I receive the following error:
ERROR: License Manager Error -13.
No SERVER lines in license file MATLAB Answers — New Questions
How do I sort these 2D-Points to get a proper surf plot of this function
Hello! I am currently trying to plot the function
on the unit disk . I wrote a function to get some evaluationpoints inside and on the boundary of the disk but when I plot the function on it I get very weird results. I already discussed a similar problem in a previous question and a nice person explained to me that the problem was the way my points where sorted in the matrix and therefore the reshaping didn’t work as desired. Since I get the same problem in the surf plot again, I am quite sure that this is the same case here.
In the function that I wrote to generate points I first started to lay a grid on a square. After that I sort out every point that is outside of the circle or that is on the boundary of the circle. Lastly I put points on the boundary of the circle. The function takes parameters and . First two parameters are the bounds for the square . The parameter is going to be the squareroot of the number of Points we will end up with. The function gives back Matrices xint, xbdy and x. xint holds the interior points and xbdy the points on the boundary of the circle. x should have both points together but there is still the problem on how I sort these… The rows of these matrices are points in that means e.g. x is gonna be a Matrix.
[~,~,~] = GetCircleGrid(-1,1,30); %Example
function [xint,xbdy,x] = GetCircleGrid(a,b,N)
% Radius of Circle
r = (b-a)/2;
% Centerpoint of Circle
x0 = a+r;
y0 = a+r;
% First get a Grid on the whole square
[xsqr1,xsqr2] = meshgrid(linspace(a,b,N),linspace(a,b,N));
xsqr = [xsqr1(:),xsqr2(:)];
% Now get rid of Points outside of Circle
k=1; % counter
for j=1:N^2
if sqrt((xsqr(j,1)-x0)^2+(xsqr(j,2)-y0)^2) < r % If distance from centerpoint is < r
xint(k,:) = xsqr(j,:);
k=k+1;
end
end
NB = N^2-(k-1); % Number of points for boundary so we end up with N^2 points in total
% Get the Boundarypoints
theta = linspace(0,2*pi,NB);
xbdy = zeros(NB,2);
xbdy(:,1) = x0 + r*cos(theta)’;
xbdy(:,2) = y0 + r*sin(theta)’;
x = sortrows([xint; xbdy]); % How to sort these…? 🙁
scatter(xint(:,1),xint(:,2),’ob’);
axis equal;
hold on;
scatter(xbdy(:,1),xbdy(:,2),’or’);
hold off;
end
The picture show, this is exactly how I want it too look for later usage… Now I wanted to plot the above function (for later usage too…) on the unit disc:
% The function
u = @(x) (5/4)*(1-x(:,1).^2-x(:,2).^2).*sin(pi*x(:,1))+1;
% Get some evaluation points …
N = 30;
[xint,xbdy,x]=GetCircleGrid(-1,1,N); % … in the unit disk
% Reshape evaluation points
X = reshape(x(:,1),N,N); % not working well…
Y = reshape(x(:,2),N,N); % not working well…
U = reshape(u(x),N,N); % evaluate the function
% Plot the function as well as the evaluationpoints
figure(1)
surf(X,Y,U,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title(‘f(x,y)’)
hold on;
scatter3(X,Y,zeros(N,N),’og’);
hold off;
As you can see the plot has some weird lines that are not wanted. How should I sort the points in x to get a proper surf plot? In addition to that I wanted to plot the inner points in a different collor than the boundary points but since the number of points inside and the number of points on the boundary of the disc are not square numbers I don’t know how to use reshape for xint and xboundary…
Thank you very much for your help! Kind regard, Max.Hello! I am currently trying to plot the function
on the unit disk . I wrote a function to get some evaluationpoints inside and on the boundary of the disk but when I plot the function on it I get very weird results. I already discussed a similar problem in a previous question and a nice person explained to me that the problem was the way my points where sorted in the matrix and therefore the reshaping didn’t work as desired. Since I get the same problem in the surf plot again, I am quite sure that this is the same case here.
In the function that I wrote to generate points I first started to lay a grid on a square. After that I sort out every point that is outside of the circle or that is on the boundary of the circle. Lastly I put points on the boundary of the circle. The function takes parameters and . First two parameters are the bounds for the square . The parameter is going to be the squareroot of the number of Points we will end up with. The function gives back Matrices xint, xbdy and x. xint holds the interior points and xbdy the points on the boundary of the circle. x should have both points together but there is still the problem on how I sort these… The rows of these matrices are points in that means e.g. x is gonna be a Matrix.
[~,~,~] = GetCircleGrid(-1,1,30); %Example
function [xint,xbdy,x] = GetCircleGrid(a,b,N)
% Radius of Circle
r = (b-a)/2;
% Centerpoint of Circle
x0 = a+r;
y0 = a+r;
% First get a Grid on the whole square
[xsqr1,xsqr2] = meshgrid(linspace(a,b,N),linspace(a,b,N));
xsqr = [xsqr1(:),xsqr2(:)];
% Now get rid of Points outside of Circle
k=1; % counter
for j=1:N^2
if sqrt((xsqr(j,1)-x0)^2+(xsqr(j,2)-y0)^2) < r % If distance from centerpoint is < r
xint(k,:) = xsqr(j,:);
k=k+1;
end
end
NB = N^2-(k-1); % Number of points for boundary so we end up with N^2 points in total
% Get the Boundarypoints
theta = linspace(0,2*pi,NB);
xbdy = zeros(NB,2);
xbdy(:,1) = x0 + r*cos(theta)’;
xbdy(:,2) = y0 + r*sin(theta)’;
x = sortrows([xint; xbdy]); % How to sort these…? 🙁
scatter(xint(:,1),xint(:,2),’ob’);
axis equal;
hold on;
scatter(xbdy(:,1),xbdy(:,2),’or’);
hold off;
end
The picture show, this is exactly how I want it too look for later usage… Now I wanted to plot the above function (for later usage too…) on the unit disc:
% The function
u = @(x) (5/4)*(1-x(:,1).^2-x(:,2).^2).*sin(pi*x(:,1))+1;
% Get some evaluation points …
N = 30;
[xint,xbdy,x]=GetCircleGrid(-1,1,N); % … in the unit disk
% Reshape evaluation points
X = reshape(x(:,1),N,N); % not working well…
Y = reshape(x(:,2),N,N); % not working well…
U = reshape(u(x),N,N); % evaluate the function
% Plot the function as well as the evaluationpoints
figure(1)
surf(X,Y,U,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title(‘f(x,y)’)
hold on;
scatter3(X,Y,zeros(N,N),’og’);
hold off;
As you can see the plot has some weird lines that are not wanted. How should I sort the points in x to get a proper surf plot? In addition to that I wanted to plot the inner points in a different collor than the boundary points but since the number of points inside and the number of points on the boundary of the disc are not square numbers I don’t know how to use reshape for xint and xboundary…
Thank you very much for your help! Kind regard, Max. Hello! I am currently trying to plot the function
on the unit disk . I wrote a function to get some evaluationpoints inside and on the boundary of the disk but when I plot the function on it I get very weird results. I already discussed a similar problem in a previous question and a nice person explained to me that the problem was the way my points where sorted in the matrix and therefore the reshaping didn’t work as desired. Since I get the same problem in the surf plot again, I am quite sure that this is the same case here.
In the function that I wrote to generate points I first started to lay a grid on a square. After that I sort out every point that is outside of the circle or that is on the boundary of the circle. Lastly I put points on the boundary of the circle. The function takes parameters and . First two parameters are the bounds for the square . The parameter is going to be the squareroot of the number of Points we will end up with. The function gives back Matrices xint, xbdy and x. xint holds the interior points and xbdy the points on the boundary of the circle. x should have both points together but there is still the problem on how I sort these… The rows of these matrices are points in that means e.g. x is gonna be a Matrix.
[~,~,~] = GetCircleGrid(-1,1,30); %Example
function [xint,xbdy,x] = GetCircleGrid(a,b,N)
% Radius of Circle
r = (b-a)/2;
% Centerpoint of Circle
x0 = a+r;
y0 = a+r;
% First get a Grid on the whole square
[xsqr1,xsqr2] = meshgrid(linspace(a,b,N),linspace(a,b,N));
xsqr = [xsqr1(:),xsqr2(:)];
% Now get rid of Points outside of Circle
k=1; % counter
for j=1:N^2
if sqrt((xsqr(j,1)-x0)^2+(xsqr(j,2)-y0)^2) < r % If distance from centerpoint is < r
xint(k,:) = xsqr(j,:);
k=k+1;
end
end
NB = N^2-(k-1); % Number of points for boundary so we end up with N^2 points in total
% Get the Boundarypoints
theta = linspace(0,2*pi,NB);
xbdy = zeros(NB,2);
xbdy(:,1) = x0 + r*cos(theta)’;
xbdy(:,2) = y0 + r*sin(theta)’;
x = sortrows([xint; xbdy]); % How to sort these…? 🙁
scatter(xint(:,1),xint(:,2),’ob’);
axis equal;
hold on;
scatter(xbdy(:,1),xbdy(:,2),’or’);
hold off;
end
The picture show, this is exactly how I want it too look for later usage… Now I wanted to plot the above function (for later usage too…) on the unit disc:
% The function
u = @(x) (5/4)*(1-x(:,1).^2-x(:,2).^2).*sin(pi*x(:,1))+1;
% Get some evaluation points …
N = 30;
[xint,xbdy,x]=GetCircleGrid(-1,1,N); % … in the unit disk
% Reshape evaluation points
X = reshape(x(:,1),N,N); % not working well…
Y = reshape(x(:,2),N,N); % not working well…
U = reshape(u(x),N,N); % evaluate the function
% Plot the function as well as the evaluationpoints
figure(1)
surf(X,Y,U,’FaceAlpha’,0.5,’EdgeColor’,’interp’);
colormap cool; camlight; lighting gouraud; material dull;
title(‘f(x,y)’)
hold on;
scatter3(X,Y,zeros(N,N),’og’);
hold off;
As you can see the plot has some weird lines that are not wanted. How should I sort the points in x to get a proper surf plot? In addition to that I wanted to plot the inner points in a different collor than the boundary points but since the number of points inside and the number of points on the boundary of the disc are not square numbers I don’t know how to use reshape for xint and xboundary…
Thank you very much for your help! Kind regard, Max. surf, plotting, surface, matrix, reshape MATLAB Answers — New Questions
Function (in 2024a) to separate implicit directory parts from a folder string?
In MATLAB versions from 2014 to 2023b there was an internal utility function called matlab.internal.language.introspective.separateImplicitDirs
Its job was to identify portions of a folder structure that were implicit (like +packageName on the end of myFolder/+packageName).
That function no longer exists in 2024a. This is possibly due to the change in nomenclature from packages to namespaces. Does anyone know a replacement function? I could of course just copy the function from 2023b (it is just a set of regexp tasks) but pointing to the inbuilt version would be nice.
Thanks,
SvenIn MATLAB versions from 2014 to 2023b there was an internal utility function called matlab.internal.language.introspective.separateImplicitDirs
Its job was to identify portions of a folder structure that were implicit (like +packageName on the end of myFolder/+packageName).
That function no longer exists in 2024a. This is possibly due to the change in nomenclature from packages to namespaces. Does anyone know a replacement function? I could of course just copy the function from 2023b (it is just a set of regexp tasks) but pointing to the inbuilt version would be nice.
Thanks,
Sven In MATLAB versions from 2014 to 2023b there was an internal utility function called matlab.internal.language.introspective.separateImplicitDirs
Its job was to identify portions of a folder structure that were implicit (like +packageName on the end of myFolder/+packageName).
That function no longer exists in 2024a. This is possibly due to the change in nomenclature from packages to namespaces. Does anyone know a replacement function? I could of course just copy the function from 2023b (it is just a set of regexp tasks) but pointing to the inbuilt version would be nice.
Thanks,
Sven implicit, folders, directories, packages, namespaces MATLAB Answers — New Questions
how to make simulation faster when using subsystems
Hello everyone,
I am working on a simulation project and need some help. When I use a single subsystem, the simulation runs quickly. However, when I duplicate the subsystem, the simulation slows down drastically, with 1 second of simulation time taking over 30 minutes in real time.
I have already implemented all the solver suggestions, but the issue persists.
Any suggestions on how to speed up the simulation would be greatly appreciated!Hello everyone,
I am working on a simulation project and need some help. When I use a single subsystem, the simulation runs quickly. However, when I duplicate the subsystem, the simulation slows down drastically, with 1 second of simulation time taking over 30 minutes in real time.
I have already implemented all the solver suggestions, but the issue persists.
Any suggestions on how to speed up the simulation would be greatly appreciated! Hello everyone,
I am working on a simulation project and need some help. When I use a single subsystem, the simulation runs quickly. However, when I duplicate the subsystem, the simulation slows down drastically, with 1 second of simulation time taking over 30 minutes in real time.
I have already implemented all the solver suggestions, but the issue persists.
Any suggestions on how to speed up the simulation would be greatly appreciated! matlab, simulink, subsystems, simulation, speed MATLAB Answers — New Questions
Save all the plots
Each time I run my code it produces 100 figures. So, I have to waste my time and save each one of them. Is there a command that can do that work for me by saving all the figures at once?Each time I run my code it produces 100 figures. So, I have to waste my time and save each one of them. Is there a command that can do that work for me by saving all the figures at once? Each time I run my code it produces 100 figures. So, I have to waste my time and save each one of them. Is there a command that can do that work for me by saving all the figures at once? save, save plot, plot MATLAB Answers — New Questions
Are functions called in parfor independent from each other
Hello everyone!
I have a question about using parfor loop related to my statistics test. I am trying to split my test from one that has 1000 iterations to four parallel tests that have 250 iterations to save time. Am I right saying that there is no influence between workers involved in this and the test result will correspond regular 1000 iteration test? The program has no errors
Script text:
S = 250;
D = zeros(4,1);
F = zeros(4,1);
d = 4;
parfor e = 1:d
[D(e,1),F(e,1)] = MonteCarlo(S);
end
disp(‘D = ‘);
disp((D(1,1)+D(2,1)+D(3,1)+D(4,1))/(d*S));
disp(‘F=’);
disp((F(1,1)+F(2,1)+F(3,1)+F(4,1))/(d*S));Hello everyone!
I have a question about using parfor loop related to my statistics test. I am trying to split my test from one that has 1000 iterations to four parallel tests that have 250 iterations to save time. Am I right saying that there is no influence between workers involved in this and the test result will correspond regular 1000 iteration test? The program has no errors
Script text:
S = 250;
D = zeros(4,1);
F = zeros(4,1);
d = 4;
parfor e = 1:d
[D(e,1),F(e,1)] = MonteCarlo(S);
end
disp(‘D = ‘);
disp((D(1,1)+D(2,1)+D(3,1)+D(4,1))/(d*S));
disp(‘F=’);
disp((F(1,1)+F(2,1)+F(3,1)+F(4,1))/(d*S)); Hello everyone!
I have a question about using parfor loop related to my statistics test. I am trying to split my test from one that has 1000 iterations to four parallel tests that have 250 iterations to save time. Am I right saying that there is no influence between workers involved in this and the test result will correspond regular 1000 iteration test? The program has no errors
Script text:
S = 250;
D = zeros(4,1);
F = zeros(4,1);
d = 4;
parfor e = 1:d
[D(e,1),F(e,1)] = MonteCarlo(S);
end
disp(‘D = ‘);
disp((D(1,1)+D(2,1)+D(3,1)+D(4,1))/(d*S));
disp(‘F=’);
disp((F(1,1)+F(2,1)+F(3,1)+F(4,1))/(d*S)); local variables, parfor, function, monte carlo MATLAB Answers — New Questions