## Category: Matlab

### Category Archives: Matlab

## How does the ischange function handle 3D vectors and a set ‘threshold’?

I am running the ischange function on an Nx3 matrix of 3D vector data (vector angles wrt axis). I understand that the ischange function detects significant changes in data. My question is how is it detecting those changes? Does it take a column of data and compare the top and bottom neighboring cell values? Does it take a row of data and compare the values on either side of the cell? Does it take the entire vector (3 angles wrt X,Y,Z axes) and compare it with the neighboring cell vectors? Or does it take the vector and compare it with all the neighboring vectors in the 3D image?

Additionally, how does the ‘threshold’ change the results? Initially I believed that the threshold was the value you set to tell the function what is considered an "abrupt" change, but after reviewing the function documentation I see that this is not the case. However, I still do not understand what the ‘threshold’ does.

Using Matlab R2021aI am running the ischange function on an Nx3 matrix of 3D vector data (vector angles wrt axis). I understand that the ischange function detects significant changes in data. My question is how is it detecting those changes? Does it take a column of data and compare the top and bottom neighboring cell values? Does it take a row of data and compare the values on either side of the cell? Does it take the entire vector (3 angles wrt X,Y,Z axes) and compare it with the neighboring cell vectors? Or does it take the vector and compare it with all the neighboring vectors in the 3D image?

Additionally, how does the ‘threshold’ change the results? Initially I believed that the threshold was the value you set to tell the function what is considered an "abrupt" change, but after reviewing the function documentation I see that this is not the case. However, I still do not understand what the ‘threshold’ does.

Using Matlab R2021a I am running the ischange function on an Nx3 matrix of 3D vector data (vector angles wrt axis). I understand that the ischange function detects significant changes in data. My question is how is it detecting those changes? Does it take a column of data and compare the top and bottom neighboring cell values? Does it take a row of data and compare the values on either side of the cell? Does it take the entire vector (3 angles wrt X,Y,Z axes) and compare it with the neighboring cell vectors? Or does it take the vector and compare it with all the neighboring vectors in the 3D image?

Additionally, how does the ‘threshold’ change the results? Initially I believed that the threshold was the value you set to tell the function what is considered an "abrupt" change, but after reviewing the function documentation I see that this is not the case. However, I still do not understand what the ‘threshold’ does.

Using Matlab R2021a ischange, threshold, vector angle, vector matrix, matrix, 3d MATLAB Answers — New Questions

## Proximity Matrix of Random Forest

I want to know how to get the proximity matrix of random forest in Matlab. For random forest, I build the model through fitcensemble with bag method. The concept of proximity matrix is not complex. It is a N by N matrix for N data points. Element (i, j) of proximity matrix represents the number of trees x_i nad x_j end in the same leaf. The proximity usually is scaled with the total number of trees. I want to know how to extract related information within Matlab.I want to know how to get the proximity matrix of random forest in Matlab. For random forest, I build the model through fitcensemble with bag method. The concept of proximity matrix is not complex. It is a N by N matrix for N data points. Element (i, j) of proximity matrix represents the number of trees x_i nad x_j end in the same leaf. The proximity usually is scaled with the total number of trees. I want to know how to extract related information within Matlab. I want to know how to get the proximity matrix of random forest in Matlab. For random forest, I build the model through fitcensemble with bag method. The concept of proximity matrix is not complex. It is a N by N matrix for N data points. Element (i, j) of proximity matrix represents the number of trees x_i nad x_j end in the same leaf. The proximity usually is scaled with the total number of trees. I want to know how to extract related information within Matlab. proximity matrix, random forest, machine learning, classification MATLAB Answers — New Questions

## Compute Gradients over FE mesh using Nodal Solution

I have computed the solution to an electrostatics problem using the finite element method in a slightly non-standard workflow (I could not figure out how to accomplish this within the PDE modeling environment, see here):

Define finite element mesh outside the PDE modeling environment

Create an electrostatics model and import the mesh

Use FEM = assembleFEMatrices(model) to assemble the global stiffness matrix

Manually prescribe Dirichlet boundary conditions at mesh nodes by constructing an H matrix (not sure what the technical term here is – a condensation operator, a boundary condition applicator, a row eliminator?) and using the pdenullorth(H). By the way – it’s strange that this function does not have any documentation that I can find!

Solve the FE problem using a backslash operation. Here’s steps 3-5 (tetMesh struct contains the tetrahedral mesh I’ve imported, and catNodes & anNodes identify the nodes where I’d like to prescribe voltage boundary conditions):

%assemble matrices (right now F is always zero)

FEM = assembleFEMatrices(model,"KF");

%create a vector of prescribed voltages

Vd = sparse(tetMesh.nNodes,1);

Vd(tetMesh.catNodes) = 1000;

Vd(tetMesh.anNodes) = 0;

%form the consdensing matrix

H = sparse(1:tetMesh.nDirichlet,[tetMesh.catNodes tetMesh.anNodes],…

ones(tetMesh.nDirichlet,1),tetMesh.nDirichlet,tetMesh.nNodes);

[B,~] = pdenullorth(H);

% form the reduced matrix algebra problem

Kc = B’*FEM.K*B;

Fc = B’*(FEM.F-(FEM.K*Vd));

%compute the FE solution

u = B*(KcFc) + Vd;

This works fine – I can now plot the nodal solutions (the electric potential) over the problem domain:

Now, I would like to compute the derived quantities associated with normal electrostatics solutions – namely the Electric Field, which is simply the gradient of the Electric Potential Field.

Ordinarily result = solvepde(model) would compute this quantity automatically – but I computed my solution simply using . Is there a way to perform this using the FE mesh that the problem was solved on? I have a hunch that the shape functions and their derivatives embedded in the FE mesh will produce a more accurate gradient field than if I project the solution to a uniform grid, compute a gradient, and project back. For this reason I would like to avoid using scatteredInterpolant().I have computed the solution to an electrostatics problem using the finite element method in a slightly non-standard workflow (I could not figure out how to accomplish this within the PDE modeling environment, see here):

Define finite element mesh outside the PDE modeling environment

Create an electrostatics model and import the mesh

Use FEM = assembleFEMatrices(model) to assemble the global stiffness matrix

Manually prescribe Dirichlet boundary conditions at mesh nodes by constructing an H matrix (not sure what the technical term here is – a condensation operator, a boundary condition applicator, a row eliminator?) and using the pdenullorth(H). By the way – it’s strange that this function does not have any documentation that I can find!

Solve the FE problem using a backslash operation. Here’s steps 3-5 (tetMesh struct contains the tetrahedral mesh I’ve imported, and catNodes & anNodes identify the nodes where I’d like to prescribe voltage boundary conditions):

%assemble matrices (right now F is always zero)

FEM = assembleFEMatrices(model,"KF");

%create a vector of prescribed voltages

Vd = sparse(tetMesh.nNodes,1);

Vd(tetMesh.catNodes) = 1000;

Vd(tetMesh.anNodes) = 0;

%form the consdensing matrix

H = sparse(1:tetMesh.nDirichlet,[tetMesh.catNodes tetMesh.anNodes],…

ones(tetMesh.nDirichlet,1),tetMesh.nDirichlet,tetMesh.nNodes);

[B,~] = pdenullorth(H);

% form the reduced matrix algebra problem

Kc = B’*FEM.K*B;

Fc = B’*(FEM.F-(FEM.K*Vd));

%compute the FE solution

u = B*(KcFc) + Vd;

This works fine – I can now plot the nodal solutions (the electric potential) over the problem domain:

Now, I would like to compute the derived quantities associated with normal electrostatics solutions – namely the Electric Field, which is simply the gradient of the Electric Potential Field.

Ordinarily result = solvepde(model) would compute this quantity automatically – but I computed my solution simply using . Is there a way to perform this using the FE mesh that the problem was solved on? I have a hunch that the shape functions and their derivatives embedded in the FE mesh will produce a more accurate gradient field than if I project the solution to a uniform grid, compute a gradient, and project back. For this reason I would like to avoid using scatteredInterpolant(). I have computed the solution to an electrostatics problem using the finite element method in a slightly non-standard workflow (I could not figure out how to accomplish this within the PDE modeling environment, see here):

Define finite element mesh outside the PDE modeling environment

Create an electrostatics model and import the mesh

Use FEM = assembleFEMatrices(model) to assemble the global stiffness matrix

Manually prescribe Dirichlet boundary conditions at mesh nodes by constructing an H matrix (not sure what the technical term here is – a condensation operator, a boundary condition applicator, a row eliminator?) and using the pdenullorth(H). By the way – it’s strange that this function does not have any documentation that I can find!

Solve the FE problem using a backslash operation. Here’s steps 3-5 (tetMesh struct contains the tetrahedral mesh I’ve imported, and catNodes & anNodes identify the nodes where I’d like to prescribe voltage boundary conditions):

%assemble matrices (right now F is always zero)

FEM = assembleFEMatrices(model,"KF");

%create a vector of prescribed voltages

Vd = sparse(tetMesh.nNodes,1);

Vd(tetMesh.catNodes) = 1000;

Vd(tetMesh.anNodes) = 0;

%form the consdensing matrix

H = sparse(1:tetMesh.nDirichlet,[tetMesh.catNodes tetMesh.anNodes],…

ones(tetMesh.nDirichlet,1),tetMesh.nDirichlet,tetMesh.nNodes);

[B,~] = pdenullorth(H);

% form the reduced matrix algebra problem

Kc = B’*FEM.K*B;

Fc = B’*(FEM.F-(FEM.K*Vd));

%compute the FE solution

u = B*(KcFc) + Vd;

This works fine – I can now plot the nodal solutions (the electric potential) over the problem domain:

Now, I would like to compute the derived quantities associated with normal electrostatics solutions – namely the Electric Field, which is simply the gradient of the Electric Potential Field.

Ordinarily result = solvepde(model) would compute this quantity automatically – but I computed my solution simply using . Is there a way to perform this using the FE mesh that the problem was solved on? I have a hunch that the shape functions and their derivatives embedded in the FE mesh will produce a more accurate gradient field than if I project the solution to a uniform grid, compute a gradient, and project back. For this reason I would like to avoid using scatteredInterpolant(). partial differential equations, gradient, electric field, finite element mesh, post-process, pde modeling MATLAB Answers — New Questions

## how to replace elements in top third, middle third, and bottom third of matix

This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.

My task is the following:

Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:

M = trio(2,4)

M =

1 1 1 1

1 1 1 1

2 2 2 2

2 2 2 2

3 3 3 3

3 3 3 3

This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.

function T = trio (n, m)

T = randi (10, (3 * n) , m);

T ( 1:n , 🙂 = 1;

T ( (n+1):(end-(n-1)) , 🙂 = 2;

T ( (n+3):end, 🙂 = 3;

end

How is it possible to call out only top third, middle third, and bottom third of any matrix?

Thank you in advance.This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.

My task is the following:

Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:

M = trio(2,4)

M =

1 1 1 1

1 1 1 1

2 2 2 2

2 2 2 2

3 3 3 3

3 3 3 3

This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.

function T = trio (n, m)

T = randi (10, (3 * n) , m);

T ( 1:n , 🙂 = 1;

T ( (n+1):(end-(n-1)) , 🙂 = 2;

T ( (n+3):end, 🙂 = 3;

end

How is it possible to call out only top third, middle third, and bottom third of any matrix?

Thank you in advance. This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.

My task is the following:

Write a function called trio that takes two positive integer inputs n and m. The function returns a 3n-by-m matrix called T. The top third of T (an n by m submatrix) is all 1s, the middle third is all 2-s while the bottom third is all 3-s. See example below:

M = trio(2,4)

M =

1 1 1 1

1 1 1 1

2 2 2 2

2 2 2 2

3 3 3 3

3 3 3 3

This is the code that I wrote, but it only works for T = trio (4,3). I want my code to work for any input of n,m.

function T = trio (n, m)

T = randi (10, (3 * n) , m);

T ( 1:n , 🙂 = 1;

T ( (n+1):(end-(n-1)) , 🙂 = 2;

T ( (n+3):end, 🙂 = 3;

end

How is it possible to call out only top third, middle third, and bottom third of any matrix?

Thank you in advance. matrix manipulation, homework, soft-lock MATLAB Answers — New Questions

## rosgenmsg(folderpath) from custom ros msgs add on causes Index exceeds the number of array elements (0).

Hello,

I’m trying to get Matlab to be able to use some custom ROS msgs from a ROS package that follows the required structure has worked in other environments. I’ve followed the instructions at https://www.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html but will get a ‘Index exceeds the number of array elements (0).’ Error on the rosgenmsg(folderpath)

Any one run into this issue before or is this a bug.Hello,

I’m trying to get Matlab to be able to use some custom ROS msgs from a ROS package that follows the required structure has worked in other environments. I’ve followed the instructions at https://www.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html but will get a ‘Index exceeds the number of array elements (0).’ Error on the rosgenmsg(folderpath)

Any one run into this issue before or is this a bug. Hello,

I’m trying to get Matlab to be able to use some custom ROS msgs from a ROS package that follows the required structure has worked in other environments. I’ve followed the instructions at https://www.mathworks.com/help/ros/ug/create-custom-messages-from-ros-package.html but will get a ‘Index exceeds the number of array elements (0).’ Error on the rosgenmsg(folderpath)

Any one run into this issue before or is this a bug. ros, custom messages, rosgenmsg MATLAB Answers — New Questions

## PV MPPT FLC using Boost DC-DC Converter

I am simulating a solar panel system using MPPT FLC. I want to ask why most of the models I refer to on the internet use a 20 ohm load for this method.

In reality, when I try to change to any other arbitrary load, the simulation graph shows very strong oscillations and is not optimal.

And the optimal load for a 213.15W panel is 3.95 ohms, from what I know.I am simulating a solar panel system using MPPT FLC. I want to ask why most of the models I refer to on the internet use a 20 ohm load for this method.

In reality, when I try to change to any other arbitrary load, the simulation graph shows very strong oscillations and is not optimal.

And the optimal load for a 213.15W panel is 3.95 ohms, from what I know. I am simulating a solar panel system using MPPT FLC. I want to ask why most of the models I refer to on the internet use a 20 ohm load for this method.

In reality, when I try to change to any other arbitrary load, the simulation graph shows very strong oscillations and is not optimal.

And the optimal load for a 213.15W panel is 3.95 ohms, from what I know. pv mppt flc using boost dc-dc converter MATLAB Answers — New Questions

## Describe the solution trajectory of differential systems with mixed time-varying delay

Hi everyone, please help me write the matlab code to describe the solution trajectory for the class differential systems with mixed time-varying delay as follows

Thank you very much!Hi everyone, please help me write the matlab code to describe the solution trajectory for the class differential systems with mixed time-varying delay as follows

Thank you very much! Hi everyone, please help me write the matlab code to describe the solution trajectory for the class differential systems with mixed time-varying delay as follows

Thank you very much! oed MATLAB Answers — New Questions

## Power Spectral Density of a bipolar digital signal

I am having a difficult time trying to plot the power spectral density of a bipolar digital signal with random values, based on an array. For example:

signal=[0 -1 1 0 1 -1];

Then I create a time vector based on a transfer rate of a specified value like this:

D=160000 % rate transfer of 160Kbps

t=[0:1/D:length(signal)/D];

And I plot the signal like this:

stairs(t,signal);

My signal looks like this :

My question is what should I do to be able to represent the power spectral density of such a signal? Is there a more direct way in Matlab than it would be by implementing all kinds of formulas? In theory, my plot should look roughly like this:

Thanks in advance!I am having a difficult time trying to plot the power spectral density of a bipolar digital signal with random values, based on an array. For example:

signal=[0 -1 1 0 1 -1];

Then I create a time vector based on a transfer rate of a specified value like this:

D=160000 % rate transfer of 160Kbps

t=[0:1/D:length(signal)/D];

And I plot the signal like this:

stairs(t,signal);

My signal looks like this :

My question is what should I do to be able to represent the power spectral density of such a signal? Is there a more direct way in Matlab than it would be by implementing all kinds of formulas? In theory, my plot should look roughly like this:

Thanks in advance! I am having a difficult time trying to plot the power spectral density of a bipolar digital signal with random values, based on an array. For example:

signal=[0 -1 1 0 1 -1];

Then I create a time vector based on a transfer rate of a specified value like this:

D=160000 % rate transfer of 160Kbps

t=[0:1/D:length(signal)/D];

And I plot the signal like this:

stairs(t,signal);

My signal looks like this :

My question is what should I do to be able to represent the power spectral density of such a signal? Is there a more direct way in Matlab than it would be by implementing all kinds of formulas? In theory, my plot should look roughly like this:

Thanks in advance! psd, power spectral density, digital signal, array based signal MATLAB Answers — New Questions

## Error: Conversion to logical from sym is not possible

Hello there. I get the following error for my code: "Conversion to logical from sym is not possible".

I need the if statement due to the root in my equation: if my d gets negativ, it can’t solve the equation anymore. that is why i would like to have the following condition that in case of a negativ number it will put d equal to zero.

How can I include if statements in a solver (so having values that are saved as syms)? I need the solver function because the real equation is way more complex but having a root.

Also how can I export the solution to a excel file? I don’t understand as the solution is still saved as sym. is there the possibility to convert a sym to a double in the end of the code?

syms x

a = 30

b = 20

c = 10

if d > 0

d = (x-c).*2

else d = 0

end

eqn = a + b – 200.*x – d^0.5 == 0

sol_x = vpasolve(eqn, x)Hello there. I get the following error for my code: "Conversion to logical from sym is not possible".

I need the if statement due to the root in my equation: if my d gets negativ, it can’t solve the equation anymore. that is why i would like to have the following condition that in case of a negativ number it will put d equal to zero.

How can I include if statements in a solver (so having values that are saved as syms)? I need the solver function because the real equation is way more complex but having a root.

Also how can I export the solution to a excel file? I don’t understand as the solution is still saved as sym. is there the possibility to convert a sym to a double in the end of the code?

syms x

a = 30

b = 20

c = 10

if d > 0

d = (x-c).*2

else d = 0

end

eqn = a + b – 200.*x – d^0.5 == 0

sol_x = vpasolve(eqn, x) Hello there. I get the following error for my code: "Conversion to logical from sym is not possible".

I need the if statement due to the root in my equation: if my d gets negativ, it can’t solve the equation anymore. that is why i would like to have the following condition that in case of a negativ number it will put d equal to zero.

How can I include if statements in a solver (so having values that are saved as syms)? I need the solver function because the real equation is way more complex but having a root.

Also how can I export the solution to a excel file? I don’t understand as the solution is still saved as sym. is there the possibility to convert a sym to a double in the end of the code?

syms x

a = 30

b = 20

c = 10

if d > 0

d = (x-c).*2

else d = 0

end

eqn = a + b – 200.*x – d^0.5 == 0

sol_x = vpasolve(eqn, x) sym MATLAB Answers — New Questions

## How to apply attention mechanism to object detection in RGB images

Hello, as this is my first time using MATLAB for research in deep learning, I am not very proficient yet. Can someone give me an example of how to apply attention mechanisms such as attention layers and self-attention layers to object detection in RGB images? Thank you very much.Hello, as this is my first time using MATLAB for research in deep learning, I am not very proficient yet. Can someone give me an example of how to apply attention mechanisms such as attention layers and self-attention layers to object detection in RGB images? Thank you very much. Hello, as this is my first time using MATLAB for research in deep learning, I am not very proficient yet. Can someone give me an example of how to apply attention mechanisms such as attention layers and self-attention layers to object detection in RGB images? Thank you very much. deep learning, attention mechanism, rgb image MATLAB Answers — New Questions

## Problem in “Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function”, Task 1, MatLab Fundamentals

I am currently finishing the course "MatLab Fundamentals" but I cannot reach 100% because in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 1, I’m not able to answer in the correct way to that Task. Since I thought I answered right, I checked the solution and it was the same as my script; however even copying and pasting the solution script and trying to submit the Task, it appears to be "Incorrect" (Is pp calculated from the function paretoperc?). I can’t understand if I’m missing something or if there’s some kind of problem since also the solution script doesn’t work. What can I do?

Here’s the code:

Task 1

pp = paretoperc(medals)

Task 2

Further Practice

function pp = paretoperc(x)

% Cumulative contribution of data points (in order)

cc = cumsum(sort(x(:),"descend")); % (:) to ensure column vector

cc = 100*cc/cc(end); % Normalize to percentage

% Corresponding percentiles (column vector to match cc)

pct = (1:numel(x))’;

pct = 100*pct/numel(pct); % Normalize to percentage

% Find the number of data values needed so that

% P% of the data is in (100-P)% of the values

idx = find(cc >= (100-pct),1,"first");

pp = cc(idx);

endI am currently finishing the course "MatLab Fundamentals" but I cannot reach 100% because in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 1, I’m not able to answer in the correct way to that Task. Since I thought I answered right, I checked the solution and it was the same as my script; however even copying and pasting the solution script and trying to submit the Task, it appears to be "Incorrect" (Is pp calculated from the function paretoperc?). I can’t understand if I’m missing something or if there’s some kind of problem since also the solution script doesn’t work. What can I do?

Here’s the code:

Task 1

pp = paretoperc(medals)

Task 2

Further Practice

function pp = paretoperc(x)

% Cumulative contribution of data points (in order)

cc = cumsum(sort(x(:),"descend")); % (:) to ensure column vector

cc = 100*cc/cc(end); % Normalize to percentage

% Corresponding percentiles (column vector to match cc)

pct = (1:numel(x))’;

pct = 100*pct/numel(pct); % Normalize to percentage

% Find the number of data values needed so that

% P% of the data is in (100-P)% of the values

idx = find(cc >= (100-pct),1,"first");

pp = cc(idx);

end I am currently finishing the course "MatLab Fundamentals" but I cannot reach 100% because in "Increasing Automation with Functions > Creating and Calling Functions > (5/5) Create and Call Local Function", Task 1, I’m not able to answer in the correct way to that Task. Since I thought I answered right, I checked the solution and it was the same as my script; however even copying and pasting the solution script and trying to submit the Task, it appears to be "Incorrect" (Is pp calculated from the function paretoperc?). I can’t understand if I’m missing something or if there’s some kind of problem since also the solution script doesn’t work. What can I do?

Here’s the code:

Task 1

pp = paretoperc(medals)

Task 2

Further Practice

function pp = paretoperc(x)

% Cumulative contribution of data points (in order)

cc = cumsum(sort(x(:),"descend")); % (:) to ensure column vector

cc = 100*cc/cc(end); % Normalize to percentage

% Corresponding percentiles (column vector to match cc)

pct = (1:numel(x))’;

pct = 100*pct/numel(pct); % Normalize to percentage

% Find the number of data values needed so that

% P% of the data is in (100-P)% of the values

idx = find(cc >= (100-pct),1,"first");

pp = cc(idx);

end local function MATLAB Answers — New Questions

## what is .data extension in matlab

Hi,

I have the code below:

X=importdata(‘test.csv’);

B = X.data;

I searched for the .data extenion file type , but could not find explaination in matlab !!

please could you explain what is this file type and when i can use it!!!

why not use csv read ? instead of importdata() !!!

ThanksHi,

I have the code below:

X=importdata(‘test.csv’);

B = X.data;

I searched for the .data extenion file type , but could not find explaination in matlab !!

please could you explain what is this file type and when i can use it!!!

why not use csv read ? instead of importdata() !!!

Thanks Hi,

I have the code below:

X=importdata(‘test.csv’);

B = X.data;

I searched for the .data extenion file type , but could not find explaination in matlab !!

please could you explain what is this file type and when i can use it!!!

why not use csv read ? instead of importdata() !!!

Thanks file type, matlab MATLAB Answers — New Questions

## MatLab won’t let me publish to PDF.

When I try to publish to a pdf, MatLab responds with:

Warning: File not found or permission denied

> In publish

In publish

In onCleanup/delete (line 25)

In publish

In publish

Loading remote resource not allowed. Remote resource: http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtdWhen I try to publish to a pdf, MatLab responds with:

Warning: File not found or permission denied

> In publish

In publish

In onCleanup/delete (line 25)

In publish

In publish

Loading remote resource not allowed. Remote resource: http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd When I try to publish to a pdf, MatLab responds with:

Warning: File not found or permission denied

> In publish

In publish

In onCleanup/delete (line 25)

In publish

In publish

Loading remote resource not allowed. Remote resource: http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd pdf, publish MATLAB Answers — New Questions

## I want all possible distinct lists of the pairs of the elements that can be made from a vector having j ones, j twos, and j threes where j is an even integer.

I have a list L of integers comprising j ones, j twos, and j threes, where j is an even integer. For example, if j=4, then the list could be L= [1 1 1 1 2 2 2 2 3 3 3 3] of length 3*j=12. I want to make distinct lists PLi, i = 1,2,….m (i and m are integers) showing various ways to pair the elements of L, using each element from L once and only once. Since there are 3*j elements in L, each PLi will have 3*j/2 pairs. The question is how many distinct lists PLi can be made if the order of the two elements in a pair is immaterial and if the order in which the pairs are listed in each PLi is immaterial. For example, one pair list, call it PL1, could be PL1 = [ [1,1]; [1,1]; [2,3]; [2,2]; [2,3]; [3,3] ] where the pairs are separated by semi-colons. The pair list [ [2,2]; [1,1]; [1,1]; [3,2]; [3,2]; [3,3] ] would not be distinct from PL1, but the pair list PL2=[ [1,1]; [1,2]; [1,3]; [2,2]; [2,3]; [3,3] ] would be distinct.

Is there a MatLab routine/command which, given L, returns all possible distinct lists of 3*j/2 pairs made from L? If not, is there an efficient algorithm to calculate all possible distinct lists PLi for large j or to estimate the dependence of the number of distinct lists (m) on the value of j?

Such a routine/command might be regarded as in the same class as nchoosek(L,2). ?I have a list L of integers comprising j ones, j twos, and j threes, where j is an even integer. For example, if j=4, then the list could be L= [1 1 1 1 2 2 2 2 3 3 3 3] of length 3*j=12. I want to make distinct lists PLi, i = 1,2,….m (i and m are integers) showing various ways to pair the elements of L, using each element from L once and only once. Since there are 3*j elements in L, each PLi will have 3*j/2 pairs. The question is how many distinct lists PLi can be made if the order of the two elements in a pair is immaterial and if the order in which the pairs are listed in each PLi is immaterial. For example, one pair list, call it PL1, could be PL1 = [ [1,1]; [1,1]; [2,3]; [2,2]; [2,3]; [3,3] ] where the pairs are separated by semi-colons. The pair list [ [2,2]; [1,1]; [1,1]; [3,2]; [3,2]; [3,3] ] would not be distinct from PL1, but the pair list PL2=[ [1,1]; [1,2]; [1,3]; [2,2]; [2,3]; [3,3] ] would be distinct.

Is there a MatLab routine/command which, given L, returns all possible distinct lists of 3*j/2 pairs made from L? If not, is there an efficient algorithm to calculate all possible distinct lists PLi for large j or to estimate the dependence of the number of distinct lists (m) on the value of j?

Such a routine/command might be regarded as in the same class as nchoosek(L,2). ? I have a list L of integers comprising j ones, j twos, and j threes, where j is an even integer. For example, if j=4, then the list could be L= [1 1 1 1 2 2 2 2 3 3 3 3] of length 3*j=12. I want to make distinct lists PLi, i = 1,2,….m (i and m are integers) showing various ways to pair the elements of L, using each element from L once and only once. Since there are 3*j elements in L, each PLi will have 3*j/2 pairs. The question is how many distinct lists PLi can be made if the order of the two elements in a pair is immaterial and if the order in which the pairs are listed in each PLi is immaterial. For example, one pair list, call it PL1, could be PL1 = [ [1,1]; [1,1]; [2,3]; [2,2]; [2,3]; [3,3] ] where the pairs are separated by semi-colons. The pair list [ [2,2]; [1,1]; [1,1]; [3,2]; [3,2]; [3,3] ] would not be distinct from PL1, but the pair list PL2=[ [1,1]; [1,2]; [1,3]; [2,2]; [2,3]; [3,3] ] would be distinct.

Is there a MatLab routine/command which, given L, returns all possible distinct lists of 3*j/2 pairs made from L? If not, is there an efficient algorithm to calculate all possible distinct lists PLi for large j or to estimate the dependence of the number of distinct lists (m) on the value of j?

Such a routine/command might be regarded as in the same class as nchoosek(L,2). ? matlab function, mathematics, code generation MATLAB Answers — New Questions

## How can I step up three phase voltage using three phase transformer in MATALB Simulink.

Hello everyone,

I am working on a model in MATLAB where I need to step up a 20 kV three-phase voltage to 200 kV. I used the three-phase transformer from the Simulink library and set the parameters to 20 kV on the primary side and 200 kV on the secondary side. However, when I run the simulation, I do not achieve the desired 200 kV output. Can someone please suggest how I can fix this issue? Additionally, if there are any resources or references that could help me with my query, I would appreciate it.Thank you!Hello everyone,

I am working on a model in MATLAB where I need to step up a 20 kV three-phase voltage to 200 kV. I used the three-phase transformer from the Simulink library and set the parameters to 20 kV on the primary side and 200 kV on the secondary side. However, when I run the simulation, I do not achieve the desired 200 kV output. Can someone please suggest how I can fix this issue? Additionally, if there are any resources or references that could help me with my query, I would appreciate it.Thank you! Hello everyone,

I am working on a model in MATLAB where I need to step up a 20 kV three-phase voltage to 200 kV. I used the three-phase transformer from the Simulink library and set the parameters to 20 kV on the primary side and 200 kV on the secondary side. However, when I run the simulation, I do not achieve the desired 200 kV output. Can someone please suggest how I can fix this issue? Additionally, if there are any resources or references that could help me with my query, I would appreciate it.Thank you! three phase transformere MATLAB Answers — New Questions

## Why do I get “Encountered complex value when computing gradient…” error in my custom network training

I’m training a network with a custom loss fuction, but I got this error when traning the network:

Error using dlarray/dlgradient

Encountered complex value when computing gradient with respect to an output of fullyconnect. Convert all outputs of fullyconnect to real.

The following is my modelloss function:

function [loss,gradients] = modelLoss(net,X,A)

[Nt,Ng] = size(A);

[~,~,miniBatchSize] = size(X);

[Y1,Y2] = forward(net,X); % the network output

Nrf = size(Y1,1)/2;

% convert real value outputs to complex valued vector & matrices : f1, F2

f1_split = reshape(Y1,[Nrf,2,miniBatchSize]);

f1 = squeeze(complex(f1_split(:,1,:),f1_split(:,2,:)));

F2_phase = reshape(Y2,[Nt,Nrf,miniBatchSize]);

F2 = exp(1i*F2_phase)/sqrt(Nt);

% Compute loss.

loss = dlarray(0);

for batch = 1:miniBatchSize % calculate the loss (as temp_loss) in every batch

f = F2(:,:,batch)*f1(:,batch); % f is a complex valued vector

temp_loss = sqrt(sum( ( abs(A’*f).^2-X(:,:,batch) ).^2 )); % temp_loss sould always be real

% A above is a complex matrices of size Ng*Nt

% X is real valued vector of size Ng*1

loss = loss + temp_loss;

end

loss = loss/(miniBatchSize*Ng);

% Compute gradients.

gradients = dlgradient(loss,net.Learnables);

end

And update loss and calculating gradients using dlfeval() as usual.

[loss,gradients] = dlfeval(@modelLoss,net,X,A);

I think I made the traced loss in every calculation as real valued.

Please help me find out where the problem is, thanks!I’m training a network with a custom loss fuction, but I got this error when traning the network:

Error using dlarray/dlgradient

Encountered complex value when computing gradient with respect to an output of fullyconnect. Convert all outputs of fullyconnect to real.

The following is my modelloss function:

function [loss,gradients] = modelLoss(net,X,A)

[Nt,Ng] = size(A);

[~,~,miniBatchSize] = size(X);

[Y1,Y2] = forward(net,X); % the network output

Nrf = size(Y1,1)/2;

% convert real value outputs to complex valued vector & matrices : f1, F2

f1_split = reshape(Y1,[Nrf,2,miniBatchSize]);

f1 = squeeze(complex(f1_split(:,1,:),f1_split(:,2,:)));

F2_phase = reshape(Y2,[Nt,Nrf,miniBatchSize]);

F2 = exp(1i*F2_phase)/sqrt(Nt);

% Compute loss.

loss = dlarray(0);

for batch = 1:miniBatchSize % calculate the loss (as temp_loss) in every batch

f = F2(:,:,batch)*f1(:,batch); % f is a complex valued vector

temp_loss = sqrt(sum( ( abs(A’*f).^2-X(:,:,batch) ).^2 )); % temp_loss sould always be real

% A above is a complex matrices of size Ng*Nt

% X is real valued vector of size Ng*1

loss = loss + temp_loss;

end

loss = loss/(miniBatchSize*Ng);

% Compute gradients.

gradients = dlgradient(loss,net.Learnables);

end

And update loss and calculating gradients using dlfeval() as usual.

[loss,gradients] = dlfeval(@modelLoss,net,X,A);

I think I made the traced loss in every calculation as real valued.

Please help me find out where the problem is, thanks! I’m training a network with a custom loss fuction, but I got this error when traning the network:

Error using dlarray/dlgradient

Encountered complex value when computing gradient with respect to an output of fullyconnect. Convert all outputs of fullyconnect to real.

The following is my modelloss function:

function [loss,gradients] = modelLoss(net,X,A)

[Nt,Ng] = size(A);

[~,~,miniBatchSize] = size(X);

[Y1,Y2] = forward(net,X); % the network output

Nrf = size(Y1,1)/2;

% convert real value outputs to complex valued vector & matrices : f1, F2

f1_split = reshape(Y1,[Nrf,2,miniBatchSize]);

f1 = squeeze(complex(f1_split(:,1,:),f1_split(:,2,:)));

F2_phase = reshape(Y2,[Nt,Nrf,miniBatchSize]);

F2 = exp(1i*F2_phase)/sqrt(Nt);

% Compute loss.

loss = dlarray(0);

for batch = 1:miniBatchSize % calculate the loss (as temp_loss) in every batch

f = F2(:,:,batch)*f1(:,batch); % f is a complex valued vector

temp_loss = sqrt(sum( ( abs(A’*f).^2-X(:,:,batch) ).^2 )); % temp_loss sould always be real

% A above is a complex matrices of size Ng*Nt

% X is real valued vector of size Ng*1

loss = loss + temp_loss;

end

loss = loss/(miniBatchSize*Ng);

% Compute gradients.

gradients = dlgradient(loss,net.Learnables);

end

And update loss and calculating gradients using dlfeval() as usual.

[loss,gradients] = dlfeval(@modelLoss,net,X,A);

I think I made the traced loss in every calculation as real valued.

Please help me find out where the problem is, thanks! dlgradient, complex value when computing gradient MATLAB Answers — New Questions

## Shapefile or KML from 2d Matrix

I created a two-dimensional matrix (720, 1440) of global temperatures based on 0.5 degree latitude/longitude. I’d like to make a projected shapefile or kml from this that I can import into ArcPro or similar GIS platform. I have the mapping toolbox and access to shapewrite but I’m not exactly sure how to accomplish the task.

Any idea would be greatly appreciated.I created a two-dimensional matrix (720, 1440) of global temperatures based on 0.5 degree latitude/longitude. I’d like to make a projected shapefile or kml from this that I can import into ArcPro or similar GIS platform. I have the mapping toolbox and access to shapewrite but I’m not exactly sure how to accomplish the task.

Any idea would be greatly appreciated. I created a two-dimensional matrix (720, 1440) of global temperatures based on 0.5 degree latitude/longitude. I’d like to make a projected shapefile or kml from this that I can import into ArcPro or similar GIS platform. I have the mapping toolbox and access to shapewrite but I’m not exactly sure how to accomplish the task.

Any idea would be greatly appreciated. shapefile, kml, shapewrite, matrix, gis MATLAB Answers — New Questions

## “double” vs. “uint8” input using “imshow” function

When using the command, "imshow(image)", I get an error when "image" has type "double". If I convert "image" to type "uint8", then "imshow" produces the image. Why is there an error with type "double"?When using the command, "imshow(image)", I get an error when "image" has type "double". If I convert "image" to type "uint8", then "imshow" produces the image. Why is there an error with type "double"? When using the command, "imshow(image)", I get an error when "image" has type "double". If I convert "image" to type "uint8", then "imshow" produces the image. Why is there an error with type "double"? double MATLAB Answers — New Questions

## How can I plot 3D graph using x,y,z data with different axis size/limit?

Hello guys!

I am trying to plot a 3D graph on MATLAB, for non-uniform scattered points (not having equal distances between them), where each point has an x,y and z value. However, I want the axis size for each one to be different but MATLAB is only allowing me to plot it with similar axis size/limit for x,y and z. (For example I want x to be from 0 to 30, y from 0 to 40 and z from 0 to 1, but it allows me to only set 1 size/limit for all of them). Do you have any idea on how to plot it with different axis sizes? Or any other software that allows me to do so?

Thank you so much for your help in advance!Hello guys!

I am trying to plot a 3D graph on MATLAB, for non-uniform scattered points (not having equal distances between them), where each point has an x,y and z value. However, I want the axis size for each one to be different but MATLAB is only allowing me to plot it with similar axis size/limit for x,y and z. (For example I want x to be from 0 to 30, y from 0 to 40 and z from 0 to 1, but it allows me to only set 1 size/limit for all of them). Do you have any idea on how to plot it with different axis sizes? Or any other software that allows me to do so?

Thank you so much for your help in advance! Hello guys!

I am trying to plot a 3D graph on MATLAB, for non-uniform scattered points (not having equal distances between them), where each point has an x,y and z value. However, I want the axis size for each one to be different but MATLAB is only allowing me to plot it with similar axis size/limit for x,y and z. (For example I want x to be from 0 to 30, y from 0 to 40 and z from 0 to 1, but it allows me to only set 1 size/limit for all of them). Do you have any idea on how to plot it with different axis sizes? Or any other software that allows me to do so?

Thank you so much for your help in advance! 3d plots, different axis sizes MATLAB Answers — New Questions

## which is the best network to predict vibration response( output) against time varying force (input) ?

will this kind of network work for it. in the attachement coulumn 2 is f(t) input and column 3 is x(t) i.e output? can anyone cross check what i have to modify to get the results correctly.

% Load and preprocess data

inputData = Predictors_train; % Time series force input data (100 values)

outputData = Responsers_train; % Corresponding time series displacement data (100 values)

% Split data into training and validation sets

cvp = 0.6; % 60% for training

idxTrain = 1:round(cvp*length(inputData));

idxVal = (round(cvp*length(inputData))+1):length(inputData);

XTrain = inputData(idxTrain, :);

YTrain = outputData(idxTrain, :);

XVal = inputData(idxVal, :);

YVal = outputData(idxVal, :);

% Define the number of features and responses

numFeatures = size(XTrain, 2); % Number of features in input data

numResponses = size(YTrain, 2); % Number of responses

% Define LSTM network architecture

layers = [ …

sequenceInputLayer(numFeatures)

lstmLayer(12, ‘OutputMode’, ‘sequence’)

dropoutLayer(0.2)

% lstmLayer(32, ‘OutputMode’, ‘sequence’) % ‘sequence’ for sequence-to-sequence

% dropoutLayer(0.2)

fullyConnectedLayer(numResponses)

regressionLayer];

% Specify training options

maxEpochs = 10;

miniBatchSize = 16;

options = trainingOptions(‘adam’, …

‘MaxEpochs’, maxEpochs, …

‘MiniBatchSize’, miniBatchSize, …

‘Shuffle’, ‘every-epoch’, …

‘Plots’, ‘training-progress’, …

‘Verbose’, false);

% Convert training data to cell arrays

XTrain = num2cell(XTrain, 2); % Convert each sequence to a separate cell

YTrain = num2cell(YTrain, 2); % Convert each sequence to a separate cell

% Train LSTM network

net = trainNetwork(XTrain, YTrain, layers, options);

% Validate trained network

YPredVal = predict(net, num2cell(XVal, 2)); % Convert XVal to cell array

valRMSE = sqrt(mean((YVal – cell2mat(YPredVal)).^2)); % Convert YPredVal back to matrix

disp([‘Validation RMSE: ‘, num2str(valRMSE)]);

figure;

plot(cell2mat(YPredVal));

new_input_data = Predictors_test;

% Make predictions on new data

XNew = num2cell(new_input_data, 2); % Convert new input data to cell array

YPred = predict(net, XNew); % Predict using the trained network

Ypred_mat=cell2mat(YPred);

Y_actual = Responsers_test;

figure;

plot(time_series,Ypred_mat,’r’,’LineWidth’,1.2);

hold on;

plot( time_series, Y_actual, ‘b’,’LineWidth’,1);will this kind of network work for it. in the attachement coulumn 2 is f(t) input and column 3 is x(t) i.e output? can anyone cross check what i have to modify to get the results correctly.

% Load and preprocess data

inputData = Predictors_train; % Time series force input data (100 values)

outputData = Responsers_train; % Corresponding time series displacement data (100 values)

% Split data into training and validation sets

cvp = 0.6; % 60% for training

idxTrain = 1:round(cvp*length(inputData));

idxVal = (round(cvp*length(inputData))+1):length(inputData);

XTrain = inputData(idxTrain, :);

YTrain = outputData(idxTrain, :);

XVal = inputData(idxVal, :);

YVal = outputData(idxVal, :);

% Define the number of features and responses

numFeatures = size(XTrain, 2); % Number of features in input data

numResponses = size(YTrain, 2); % Number of responses

% Define LSTM network architecture

layers = [ …

sequenceInputLayer(numFeatures)

lstmLayer(12, ‘OutputMode’, ‘sequence’)

dropoutLayer(0.2)

% lstmLayer(32, ‘OutputMode’, ‘sequence’) % ‘sequence’ for sequence-to-sequence

% dropoutLayer(0.2)

fullyConnectedLayer(numResponses)

regressionLayer];

% Specify training options

maxEpochs = 10;

miniBatchSize = 16;

options = trainingOptions(‘adam’, …

‘MaxEpochs’, maxEpochs, …

‘MiniBatchSize’, miniBatchSize, …

‘Shuffle’, ‘every-epoch’, …

‘Plots’, ‘training-progress’, …

‘Verbose’, false);

% Convert training data to cell arrays

XTrain = num2cell(XTrain, 2); % Convert each sequence to a separate cell

YTrain = num2cell(YTrain, 2); % Convert each sequence to a separate cell

% Train LSTM network

net = trainNetwork(XTrain, YTrain, layers, options);

% Validate trained network

YPredVal = predict(net, num2cell(XVal, 2)); % Convert XVal to cell array

valRMSE = sqrt(mean((YVal – cell2mat(YPredVal)).^2)); % Convert YPredVal back to matrix

disp([‘Validation RMSE: ‘, num2str(valRMSE)]);

figure;

plot(cell2mat(YPredVal));

new_input_data = Predictors_test;

% Make predictions on new data

XNew = num2cell(new_input_data, 2); % Convert new input data to cell array

YPred = predict(net, XNew); % Predict using the trained network

Ypred_mat=cell2mat(YPred);

Y_actual = Responsers_test;

figure;

plot(time_series,Ypred_mat,’r’,’LineWidth’,1.2);

hold on;

plot( time_series, Y_actual, ‘b’,’LineWidth’,1); will this kind of network work for it. in the attachement coulumn 2 is f(t) input and column 3 is x(t) i.e output? can anyone cross check what i have to modify to get the results correctly.

% Load and preprocess data

inputData = Predictors_train; % Time series force input data (100 values)

outputData = Responsers_train; % Corresponding time series displacement data (100 values)

% Split data into training and validation sets

cvp = 0.6; % 60% for training

idxTrain = 1:round(cvp*length(inputData));

idxVal = (round(cvp*length(inputData))+1):length(inputData);

XTrain = inputData(idxTrain, :);

YTrain = outputData(idxTrain, :);

XVal = inputData(idxVal, :);

YVal = outputData(idxVal, :);

% Define the number of features and responses

numFeatures = size(XTrain, 2); % Number of features in input data

numResponses = size(YTrain, 2); % Number of responses

% Define LSTM network architecture

layers = [ …

sequenceInputLayer(numFeatures)

lstmLayer(12, ‘OutputMode’, ‘sequence’)

dropoutLayer(0.2)

% lstmLayer(32, ‘OutputMode’, ‘sequence’) % ‘sequence’ for sequence-to-sequence

% dropoutLayer(0.2)

fullyConnectedLayer(numResponses)

regressionLayer];

% Specify training options

maxEpochs = 10;

miniBatchSize = 16;

options = trainingOptions(‘adam’, …

‘MaxEpochs’, maxEpochs, …

‘MiniBatchSize’, miniBatchSize, …

‘Shuffle’, ‘every-epoch’, …

‘Plots’, ‘training-progress’, …

‘Verbose’, false);

% Convert training data to cell arrays

XTrain = num2cell(XTrain, 2); % Convert each sequence to a separate cell

YTrain = num2cell(YTrain, 2); % Convert each sequence to a separate cell

% Train LSTM network

net = trainNetwork(XTrain, YTrain, layers, options);

% Validate trained network

YPredVal = predict(net, num2cell(XVal, 2)); % Convert XVal to cell array

valRMSE = sqrt(mean((YVal – cell2mat(YPredVal)).^2)); % Convert YPredVal back to matrix

disp([‘Validation RMSE: ‘, num2str(valRMSE)]);

figure;

plot(cell2mat(YPredVal));

new_input_data = Predictors_test;

% Make predictions on new data

XNew = num2cell(new_input_data, 2); % Convert new input data to cell array

YPred = predict(net, XNew); % Predict using the trained network

Ypred_mat=cell2mat(YPred);

Y_actual = Responsers_test;

figure;

plot(time_series,Ypred_mat,’r’,’LineWidth’,1.2);

hold on;

plot( time_series, Y_actual, ‘b’,’LineWidth’,1); matlab, vibration dataset, neural network, lstm MATLAB Answers — New Questions