Category: Matlab
Category Archives: Matlab
Generate matrix combinations with parameters
I have the following matrix (8×6):
M = [T_1 T_2 T_3 0 0 0
T_1 0 T_2 T_3 0 0
T_1 0 0 T_2 T_3 0
T_1 T_2 0 0 T_3 0
0 T_1 T_2 0 0 T_3
0 0 T_1 T_2 0 T_3
0 0 0 T_1 T_2 T_3
0 T_1 0 0 T_2 T_3]
where T has the following possibilities: {1,0,0}, {0,1,0}, {0,0,1} or {1,1,1} and T_i is the i-component of T.
How can I create all possible combinations for M?I have the following matrix (8×6):
M = [T_1 T_2 T_3 0 0 0
T_1 0 T_2 T_3 0 0
T_1 0 0 T_2 T_3 0
T_1 T_2 0 0 T_3 0
0 T_1 T_2 0 0 T_3
0 0 T_1 T_2 0 T_3
0 0 0 T_1 T_2 T_3
0 T_1 0 0 T_2 T_3]
where T has the following possibilities: {1,0,0}, {0,1,0}, {0,0,1} or {1,1,1} and T_i is the i-component of T.
How can I create all possible combinations for M? I have the following matrix (8×6):
M = [T_1 T_2 T_3 0 0 0
T_1 0 T_2 T_3 0 0
T_1 0 0 T_2 T_3 0
T_1 T_2 0 0 T_3 0
0 T_1 T_2 0 0 T_3
0 0 T_1 T_2 0 T_3
0 0 0 T_1 T_2 T_3
0 T_1 0 0 T_2 T_3]
where T has the following possibilities: {1,0,0}, {0,1,0}, {0,0,1} or {1,1,1} and T_i is the i-component of T.
How can I create all possible combinations for M? combinations, matrices MATLAB Answers — New Questions
How to display table values
I am trying to get the command window to show the actual value of my table instead of saying [1×41 double].
Below is my working out:
A=(10:0.1:14);
M; %Array of Maximum values
I; %Array of Index of Maximum values
maxtheta = theta(I);
%%Add Table with A vs M vs I
T = table(A,M,maxtheta,’VariableNames’,{‘a value’,’max db value’,’corresponding angle’})
When i click run, this is what it is displaying:
T =
1×3 table
a value max db value corresponding angle
____________ _____________ ___________________
[1×41 double] [1×41 double] [1×41 double]
How can I get it to show the actual values?I am trying to get the command window to show the actual value of my table instead of saying [1×41 double].
Below is my working out:
A=(10:0.1:14);
M; %Array of Maximum values
I; %Array of Index of Maximum values
maxtheta = theta(I);
%%Add Table with A vs M vs I
T = table(A,M,maxtheta,’VariableNames’,{‘a value’,’max db value’,’corresponding angle’})
When i click run, this is what it is displaying:
T =
1×3 table
a value max db value corresponding angle
____________ _____________ ___________________
[1×41 double] [1×41 double] [1×41 double]
How can I get it to show the actual values? I am trying to get the command window to show the actual value of my table instead of saying [1×41 double].
Below is my working out:
A=(10:0.1:14);
M; %Array of Maximum values
I; %Array of Index of Maximum values
maxtheta = theta(I);
%%Add Table with A vs M vs I
T = table(A,M,maxtheta,’VariableNames’,{‘a value’,’max db value’,’corresponding angle’})
When i click run, this is what it is displaying:
T =
1×3 table
a value max db value corresponding angle
____________ _____________ ___________________
[1×41 double] [1×41 double] [1×41 double]
How can I get it to show the actual values? table, array, values MATLAB Answers — New Questions
directory does not update
When I choose a new program to run the directory does not update, so I have to manually go to "browse for folder" and find where this program is located manually. is there a solution to this or is it a bug?When I choose a new program to run the directory does not update, so I have to manually go to "browse for folder" and find where this program is located manually. is there a solution to this or is it a bug? When I choose a new program to run the directory does not update, so I have to manually go to "browse for folder" and find where this program is located manually. is there a solution to this or is it a bug? directory, browse, matlab, bug MATLAB Answers — New Questions
Calculating Gravity Torque for ABB IRB1410
Can the gravity torque of the ABB IRB1410 with a parallel structure be calculated using the gravityTorque() function of the Robotics System Toolbox?Can the gravity torque of the ABB IRB1410 with a parallel structure be calculated using the gravityTorque() function of the Robotics System Toolbox? Can the gravity torque of the ABB IRB1410 with a parallel structure be calculated using the gravityTorque() function of the Robotics System Toolbox? abb, irb1410, gravity torque MATLAB Answers — New Questions
How to link Autodesk Inventor 2025 files to Simscape Multibody, if you mention that they only have until the Autodesk 2021 version?
Post Content Post Content autodesk inventor 2025, simscape multibody, plugin MATLAB Answers — New Questions
Connecting Fuse in Simscape Transformer Circuit
Apologies if this is a dumb question, but I opened up the power_transformer Simscape example and attempted to add a Simscape Fuse block (Switches and Breakers/Fuse). However when I try to connect a terminal of the fuse to a terminal of the included transformer it won’t allow it (circle with cross inside). It also won’t connect to the included Simscape Fundamental Block/Parallel RLC load. Maybe I need to stick some sort of converter in-line to allow the connection?
Thanks.Apologies if this is a dumb question, but I opened up the power_transformer Simscape example and attempted to add a Simscape Fuse block (Switches and Breakers/Fuse). However when I try to connect a terminal of the fuse to a terminal of the included transformer it won’t allow it (circle with cross inside). It also won’t connect to the included Simscape Fundamental Block/Parallel RLC load. Maybe I need to stick some sort of converter in-line to allow the connection?
Thanks. Apologies if this is a dumb question, but I opened up the power_transformer Simscape example and attempted to add a Simscape Fuse block (Switches and Breakers/Fuse). However when I try to connect a terminal of the fuse to a terminal of the included transformer it won’t allow it (circle with cross inside). It also won’t connect to the included Simscape Fundamental Block/Parallel RLC load. Maybe I need to stick some sort of converter in-line to allow the connection?
Thanks. simulink, simscape, fuse MATLAB Answers — New Questions
Save document with custom properties with actxserver Word
The following script shall change custom properties of a word document using the activexserver syntax for Microsoft Word.
%% Initiallize Word Connection
hdlWord = actxserver(‘Word.Application’);
hdlWord.Visible = true;
%% File and Location
fullLocation = ‘C:UsersNameDocumentsMATLABPropTest.docx’;
hdlDoc = hdlWord.Documents.Open(fullLocation);
%% Property Change
hdlProp = get(hdlDoc.CustomDocumentProperties, ‘Item’, ‘Property1’);
get(hdlProp,’Value’);
set(hdlProp,’Value’,’nice’); % saved as "jealous" before running the script
%% Save Doc
hdlWord.ActiveDocument.SaveAs2(fullLocation)
hdlDoc.Close();
hdlWord.Quit();
The property change itself is working. Sadly, the script is not saving the document. There is no error or warning given out.
If I comment the close functions and click save manually it works fine.
If I save the document as a another file the properties are changed and saved. Therefore, a work around by deleting and renaming and so on would work.
Could someone help me out on how to save the opened document and close it by script?The following script shall change custom properties of a word document using the activexserver syntax for Microsoft Word.
%% Initiallize Word Connection
hdlWord = actxserver(‘Word.Application’);
hdlWord.Visible = true;
%% File and Location
fullLocation = ‘C:UsersNameDocumentsMATLABPropTest.docx’;
hdlDoc = hdlWord.Documents.Open(fullLocation);
%% Property Change
hdlProp = get(hdlDoc.CustomDocumentProperties, ‘Item’, ‘Property1’);
get(hdlProp,’Value’);
set(hdlProp,’Value’,’nice’); % saved as "jealous" before running the script
%% Save Doc
hdlWord.ActiveDocument.SaveAs2(fullLocation)
hdlDoc.Close();
hdlWord.Quit();
The property change itself is working. Sadly, the script is not saving the document. There is no error or warning given out.
If I comment the close functions and click save manually it works fine.
If I save the document as a another file the properties are changed and saved. Therefore, a work around by deleting and renaming and so on would work.
Could someone help me out on how to save the opened document and close it by script? The following script shall change custom properties of a word document using the activexserver syntax for Microsoft Word.
%% Initiallize Word Connection
hdlWord = actxserver(‘Word.Application’);
hdlWord.Visible = true;
%% File and Location
fullLocation = ‘C:UsersNameDocumentsMATLABPropTest.docx’;
hdlDoc = hdlWord.Documents.Open(fullLocation);
%% Property Change
hdlProp = get(hdlDoc.CustomDocumentProperties, ‘Item’, ‘Property1’);
get(hdlProp,’Value’);
set(hdlProp,’Value’,’nice’); % saved as "jealous" before running the script
%% Save Doc
hdlWord.ActiveDocument.SaveAs2(fullLocation)
hdlDoc.Close();
hdlWord.Quit();
The property change itself is working. Sadly, the script is not saving the document. There is no error or warning given out.
If I comment the close functions and click save manually it works fine.
If I save the document as a another file the properties are changed and saved. Therefore, a work around by deleting and renaming and so on would work.
Could someone help me out on how to save the opened document and close it by script? matlab, activexserver, word, save MATLAB Answers — New Questions
Using output of a function into the integral2 Function – Unrecognized function or variable
Hello,
I’m currently facing an issue with using an output of a function into an integral.
I have attached my code for reference:
P_RAD.m
Unfortunately, for this case, I have to use a function in my code because I need it to plot certain parameters. I understand what the error is saying and why it is saying it. I’m trying to see if there is a workaround for this.
This is the integration I am trying to do: See screenshot attached: P_RAD_Integration.png
The error that I’m facing is shown below.
% Unrecognized function or variable ‘U_Rad’.
Error in Patterns (line 200)
P_rad = U_Rad.*sin(theta);Hello,
I’m currently facing an issue with using an output of a function into an integral.
I have attached my code for reference:
P_RAD.m
Unfortunately, for this case, I have to use a function in my code because I need it to plot certain parameters. I understand what the error is saying and why it is saying it. I’m trying to see if there is a workaround for this.
This is the integration I am trying to do: See screenshot attached: P_RAD_Integration.png
The error that I’m facing is shown below.
% Unrecognized function or variable ‘U_Rad’.
Error in Patterns (line 200)
P_rad = U_Rad.*sin(theta); Hello,
I’m currently facing an issue with using an output of a function into an integral.
I have attached my code for reference:
P_RAD.m
Unfortunately, for this case, I have to use a function in my code because I need it to plot certain parameters. I understand what the error is saying and why it is saying it. I’m trying to see if there is a workaround for this.
This is the integration I am trying to do: See screenshot attached: P_RAD_Integration.png
The error that I’m facing is shown below.
% Unrecognized function or variable ‘U_Rad’.
Error in Patterns (line 200)
P_rad = U_Rad.*sin(theta); integral, integration, numerical integration MATLAB Answers — New Questions
Obtain intensity values within the ROIs drawn on image in this script. Then, write and display intensity values within the ROIs on the image.
clear all
close all
% UUT image input
I = imread(‘UUT33.bmp’);
R = imresize(I, [800 1000]); % Resize image to full res
% Define ROI size
ROIWidth = 100;
ROIHeight = 100;
% Number of ROIs in X and Y directions
numROIsX = 3;
numROIsY = 3;
% Calculate the step size for placing ROIs
stepX = floor(size(R, 2) / (numROIsX + 1));
stepY = floor(size(R, 1) / (numROIsY + 1));
% Initialize ROI positions
ROIPositionsX = zeros(numROIsX, 1);
ROIPositionsY = zeros(numROIsY, 1);
% Calculate ROI positions based on the step size
for i = 1:numROIsX
ROIPositionsX(i) = i * stepX – floor(ROIWidth / 2);
end
for j = 1:numROIsY
ROIPositionsY(j) = j * stepY – floor(ROIHeight / 2);
end
% Create ROIs and visualize
figure;
imshow(R); % Display the original image
hold on; % Hold the current plot
% Loop through each ROI position and draw rectangles on image
for i = 1:numROIsX
for j = 1:numROIsY
x = ROIPositionsX(i);
y = ROIPositionsY(j);
rectangle(‘Position’, [x, y, ROIWidth, ROIHeight], ‘EdgeColor’, ‘r’, ‘LineWidth’, 2);
end
end
hold off; % Release hold on current plot
title(‘ROIs on image in exact positions’);
This scirpt inputs an image and draws rectangle ROIs in specific positions on the image. I need to obtain the intensity values within all of the ROIs, and then write in /display the intensity values wihin all of the drawn ROIs on the image. Any ideas?clear all
close all
% UUT image input
I = imread(‘UUT33.bmp’);
R = imresize(I, [800 1000]); % Resize image to full res
% Define ROI size
ROIWidth = 100;
ROIHeight = 100;
% Number of ROIs in X and Y directions
numROIsX = 3;
numROIsY = 3;
% Calculate the step size for placing ROIs
stepX = floor(size(R, 2) / (numROIsX + 1));
stepY = floor(size(R, 1) / (numROIsY + 1));
% Initialize ROI positions
ROIPositionsX = zeros(numROIsX, 1);
ROIPositionsY = zeros(numROIsY, 1);
% Calculate ROI positions based on the step size
for i = 1:numROIsX
ROIPositionsX(i) = i * stepX – floor(ROIWidth / 2);
end
for j = 1:numROIsY
ROIPositionsY(j) = j * stepY – floor(ROIHeight / 2);
end
% Create ROIs and visualize
figure;
imshow(R); % Display the original image
hold on; % Hold the current plot
% Loop through each ROI position and draw rectangles on image
for i = 1:numROIsX
for j = 1:numROIsY
x = ROIPositionsX(i);
y = ROIPositionsY(j);
rectangle(‘Position’, [x, y, ROIWidth, ROIHeight], ‘EdgeColor’, ‘r’, ‘LineWidth’, 2);
end
end
hold off; % Release hold on current plot
title(‘ROIs on image in exact positions’);
This scirpt inputs an image and draws rectangle ROIs in specific positions on the image. I need to obtain the intensity values within all of the ROIs, and then write in /display the intensity values wihin all of the drawn ROIs on the image. Any ideas? clear all
close all
% UUT image input
I = imread(‘UUT33.bmp’);
R = imresize(I, [800 1000]); % Resize image to full res
% Define ROI size
ROIWidth = 100;
ROIHeight = 100;
% Number of ROIs in X and Y directions
numROIsX = 3;
numROIsY = 3;
% Calculate the step size for placing ROIs
stepX = floor(size(R, 2) / (numROIsX + 1));
stepY = floor(size(R, 1) / (numROIsY + 1));
% Initialize ROI positions
ROIPositionsX = zeros(numROIsX, 1);
ROIPositionsY = zeros(numROIsY, 1);
% Calculate ROI positions based on the step size
for i = 1:numROIsX
ROIPositionsX(i) = i * stepX – floor(ROIWidth / 2);
end
for j = 1:numROIsY
ROIPositionsY(j) = j * stepY – floor(ROIHeight / 2);
end
% Create ROIs and visualize
figure;
imshow(R); % Display the original image
hold on; % Hold the current plot
% Loop through each ROI position and draw rectangles on image
for i = 1:numROIsX
for j = 1:numROIsY
x = ROIPositionsX(i);
y = ROIPositionsY(j);
rectangle(‘Position’, [x, y, ROIWidth, ROIHeight], ‘EdgeColor’, ‘r’, ‘LineWidth’, 2);
end
end
hold off; % Release hold on current plot
title(‘ROIs on image in exact positions’);
This scirpt inputs an image and draws rectangle ROIs in specific positions on the image. I need to obtain the intensity values within all of the ROIs, and then write in /display the intensity values wihin all of the drawn ROIs on the image. Any ideas? intensity values in rois in image MATLAB Answers — New Questions
Adding a .mex file to App Designer app
I’d like to use Shuffle to shuffle the rows of a UITable.
https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle
Hopefully it will keep the columns in a row together and can shuffle Var3 along with the numbers since it is a category (‘L’ or ‘R’)
I’ll have to experiment unless someone knows how to call it:
will Y = Shuffle(X, Dim) only shuffle the Dim’ed column leaving the rest alone?
Uh oh separate question: will repose as another ask
If I have to use X(RANDPERM(LENGTH(X)) as the doc shows will that do it?
How?I’d like to use Shuffle to shuffle the rows of a UITable.
https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle
Hopefully it will keep the columns in a row together and can shuffle Var3 along with the numbers since it is a category (‘L’ or ‘R’)
I’ll have to experiment unless someone knows how to call it:
will Y = Shuffle(X, Dim) only shuffle the Dim’ed column leaving the rest alone?
Uh oh separate question: will repose as another ask
If I have to use X(RANDPERM(LENGTH(X)) as the doc shows will that do it?
How? I’d like to use Shuffle to shuffle the rows of a UITable.
https://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle
Hopefully it will keep the columns in a row together and can shuffle Var3 along with the numbers since it is a category (‘L’ or ‘R’)
I’ll have to experiment unless someone knows how to call it:
will Y = Shuffle(X, Dim) only shuffle the Dim’ed column leaving the rest alone?
Uh oh separate question: will repose as another ask
If I have to use X(RANDPERM(LENGTH(X)) as the doc shows will that do it?
How? .mex file, app designer MATLAB Answers — New Questions
kindly help in debugging the following code for optimization
function [ f, g ] = problem_function( x )
D1=x(1);D2=x(2);D3=x(3);D4=x(4);D5=x(5);P1=x(6);P2=x(7);P3=x(8);P4=x(9);P5=x(10);V1=x(11);V2=x(12);V3=x(13);V4=x(14);V5=x(15);
L1=2;L2=3;L3=4;L4=5;L5=6;
L=[L1 L2 L3 L4 L5];
D=[D1 D2 D3 D4 D5];
%%%%%%%%%%%%%%%%%%%%%%%%%
Q1=V1*(3.14/4)*D1^2;
Q2=V2*(3.14/4)*D2^2;
Q3=V3*(3.14/4)*D3^2;
Q4=V4*(3.14/4)*D4^2;
Q5=V5*(3.14/4)*D5^2;
% Objective functions F(X)
CT=2.05*L*D’.^3;
%%%%%%%%%%%%%%%%%%%%%%%
if all(P(1:5)>=18)
CPP=0;
else
CPP=(CT/5)*sum(18-P(1:5));
end
%%%%%%%%%%%%%%%%%%%%
if all(V(1:5)<=10)
CPV=0;
else
CPV=(CT/5)*sum(V(1:5).^2-100);
end
%%%%%%
f=CT+CPV+CPP;
% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)
g(1)=P1-P2-11.7*(L1*Q1^3/D1^5);
g(2)=P2-P3-11.7*(L2*Q2^3/D2^5);
g(3)=P3-P4-11.7*(L3*Q3^3/D3^5);
g(4)=P2-P4-11.7*(L4*Q4^3/D4^5);
g(5)=P4-P5-11.7*(L5*Q5^3/D5^5);
g(6)= 40-Q1;
g(7)=Q1-Q2-Q4;
g(8)=Q2-14-Q3;
g(9)=Q3+Q4-Q5;
end
%%%% the result say Undefined function or variable ‘P’.
Error in example>problem_function (line 82)
if all(P(1:5)>=18)
any helps plz.function [ f, g ] = problem_function( x )
D1=x(1);D2=x(2);D3=x(3);D4=x(4);D5=x(5);P1=x(6);P2=x(7);P3=x(8);P4=x(9);P5=x(10);V1=x(11);V2=x(12);V3=x(13);V4=x(14);V5=x(15);
L1=2;L2=3;L3=4;L4=5;L5=6;
L=[L1 L2 L3 L4 L5];
D=[D1 D2 D3 D4 D5];
%%%%%%%%%%%%%%%%%%%%%%%%%
Q1=V1*(3.14/4)*D1^2;
Q2=V2*(3.14/4)*D2^2;
Q3=V3*(3.14/4)*D3^2;
Q4=V4*(3.14/4)*D4^2;
Q5=V5*(3.14/4)*D5^2;
% Objective functions F(X)
CT=2.05*L*D’.^3;
%%%%%%%%%%%%%%%%%%%%%%%
if all(P(1:5)>=18)
CPP=0;
else
CPP=(CT/5)*sum(18-P(1:5));
end
%%%%%%%%%%%%%%%%%%%%
if all(V(1:5)<=10)
CPV=0;
else
CPV=(CT/5)*sum(V(1:5).^2-100);
end
%%%%%%
f=CT+CPV+CPP;
% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)
g(1)=P1-P2-11.7*(L1*Q1^3/D1^5);
g(2)=P2-P3-11.7*(L2*Q2^3/D2^5);
g(3)=P3-P4-11.7*(L3*Q3^3/D3^5);
g(4)=P2-P4-11.7*(L4*Q4^3/D4^5);
g(5)=P4-P5-11.7*(L5*Q5^3/D5^5);
g(6)= 40-Q1;
g(7)=Q1-Q2-Q4;
g(8)=Q2-14-Q3;
g(9)=Q3+Q4-Q5;
end
%%%% the result say Undefined function or variable ‘P’.
Error in example>problem_function (line 82)
if all(P(1:5)>=18)
any helps plz. function [ f, g ] = problem_function( x )
D1=x(1);D2=x(2);D3=x(3);D4=x(4);D5=x(5);P1=x(6);P2=x(7);P3=x(8);P4=x(9);P5=x(10);V1=x(11);V2=x(12);V3=x(13);V4=x(14);V5=x(15);
L1=2;L2=3;L3=4;L4=5;L5=6;
L=[L1 L2 L3 L4 L5];
D=[D1 D2 D3 D4 D5];
%%%%%%%%%%%%%%%%%%%%%%%%%
Q1=V1*(3.14/4)*D1^2;
Q2=V2*(3.14/4)*D2^2;
Q3=V3*(3.14/4)*D3^2;
Q4=V4*(3.14/4)*D4^2;
Q5=V5*(3.14/4)*D5^2;
% Objective functions F(X)
CT=2.05*L*D’.^3;
%%%%%%%%%%%%%%%%%%%%%%%
if all(P(1:5)>=18)
CPP=0;
else
CPP=(CT/5)*sum(18-P(1:5));
end
%%%%%%%%%%%%%%%%%%%%
if all(V(1:5)<=10)
CPV=0;
else
CPV=(CT/5)*sum(V(1:5).^2-100);
end
%%%%%%
f=CT+CPV+CPP;
% Equality constraints G(X) = 0 MUST COME FIRST in g(1:me)
g(1)=P1-P2-11.7*(L1*Q1^3/D1^5);
g(2)=P2-P3-11.7*(L2*Q2^3/D2^5);
g(3)=P3-P4-11.7*(L3*Q3^3/D3^5);
g(4)=P2-P4-11.7*(L4*Q4^3/D4^5);
g(5)=P4-P5-11.7*(L5*Q5^3/D5^5);
g(6)= 40-Q1;
g(7)=Q1-Q2-Q4;
g(8)=Q2-14-Q3;
g(9)=Q3+Q4-Q5;
end
%%%% the result say Undefined function or variable ‘P’.
Error in example>problem_function (line 82)
if all(P(1:5)>=18)
any helps plz. optimization MATLAB Answers — New Questions
imagesc color map for gridded value
Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,……
length(X)=length(Y)=length(Z).Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,……
length(X)=length(Y)=length(Z). Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,……
length(X)=length(Y)=length(Z). imagesc, colorplot, gridded data plot, matlab MATLAB Answers — New Questions
I am facing an issue in FONT style in the MATLAB 2024a editor window.
While I am keeping the Font style ‘Monospace’, I am getting the different Font styles in the command window and editor window. This is happening especially with the Font name called ‘Monospace’. Can anyone help me in this regard?While I am keeping the Font style ‘Monospace’, I am getting the different Font styles in the command window and editor window. This is happening especially with the Font name called ‘Monospace’. Can anyone help me in this regard? While I am keeping the Font style ‘Monospace’, I am getting the different Font styles in the command window and editor window. This is happening especially with the Font name called ‘Monospace’. Can anyone help me in this regard? font MATLAB Answers — New Questions
Is there a way to log variables from a Matlab Function Block (in Simulink), that is not output?
I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)?I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)? I would like to log variables from a Matlab Function Block (in Simulink) similar to the functionality of a "To Workspace" block saving them in a SimulinkOutput object. As those variables are only internal I cannot connect them to said block. I know, I could simply define them as outputs and only connect them to the "To Workspace" block, but I would like to avoid this work around to keep my model clean (it would be around 10 variables). I have browsed through docu, but could not find something that would solve my issue. So, I am wondering if there is an elegant way to log also variables from a Matlab Function Block (in Simulink) as a an array, like it is possible for signals (connecting them to a "To Workspace" block)? simulink, save, data MATLAB Answers — New Questions
simulation wind profile in simulink
I want to simulate Cp related to wind turbine in Simulink MATLAB, I have the Excel file related to wind speed, I would be grateful if you have the link related to the simulation or if you have a source, please let me knowI want to simulate Cp related to wind turbine in Simulink MATLAB, I have the Excel file related to wind speed, I would be grateful if you have the link related to the simulation or if you have a source, please let me know I want to simulate Cp related to wind turbine in Simulink MATLAB, I have the Excel file related to wind speed, I would be grateful if you have the link related to the simulation or if you have a source, please let me know wind speed profile? MATLAB Answers — New Questions
Can’t find battery on simulink
I am trying to use a battery with measurement outport but I cant find it. I dont know if MATLAB removed it newer versions. This is what I am referring to:I am trying to use a battery with measurement outport but I cant find it. I dont know if MATLAB removed it newer versions. This is what I am referring to: I am trying to use a battery with measurement outport but I cant find it. I dont know if MATLAB removed it newer versions. This is what I am referring to: battery_system_management, simulink MATLAB Answers — New Questions
How can I use the data of a set of matrices labelled in order
Hi, I managed to open all files in a folder which leaves me with the matrices data_1, data_2, data_3 …..data_n.
Now I want to add one of the row from each of the n matrices into one single set of data but I don’t know how i can address the matrix in a for loop.
for i=1:1:n
ag((((i-1)*n)+1):i*ni)=data’i’;
endHi, I managed to open all files in a folder which leaves me with the matrices data_1, data_2, data_3 …..data_n.
Now I want to add one of the row from each of the n matrices into one single set of data but I don’t know how i can address the matrix in a for loop.
for i=1:1:n
ag((((i-1)*n)+1):i*ni)=data’i’;
end Hi, I managed to open all files in a folder which leaves me with the matrices data_1, data_2, data_3 …..data_n.
Now I want to add one of the row from each of the n matrices into one single set of data but I don’t know how i can address the matrix in a for loop.
for i=1:1:n
ag((((i-1)*n)+1):i*ni)=data’i’;
end data set, variables MATLAB Answers — New Questions
Comparing difference in values between values in an array – Using For Loop
Hello,
I have a question about comparing values between elements of an array. I keep getting the error that says
Index exceeds the number of array elements. Index must not exceed 1.
I attached my code but I also put the section of the code I’m having an issue with.
See MATLAB code attached:
E_Plane.m
theta = 0:0.01:pi/2
% The size of theta is 1 x 315
% E_Plane_norm_dB is an array that is also 1 x 315 with numbers
%{
Essentially, I am trying to see which number in the E_Plane_norm_dB array is the closest to -3.
Whichever number is closest to -3, I would need to output the "theta" value
that corresponds to that number in E_Plane_norm_dB
The way I’m doing this is by finding the "distance" from that element to -3
I keep comparing the "distances" to -3 between each element, until I find
the "smallest distance". Whichever element in E_Plane_norm_dB has the
smallest "distance", I would like to output that "theta" value.
%}
% Solving for the theta angle.
for j = 1:length(theta)
loop_theta = theta(j);
distance(j) = E_Plane_norm_dB(j) – (-3);
if (distance(j) < distance(j+1:length(theta)))
theta_angle = loop_theta;
end
endHello,
I have a question about comparing values between elements of an array. I keep getting the error that says
Index exceeds the number of array elements. Index must not exceed 1.
I attached my code but I also put the section of the code I’m having an issue with.
See MATLAB code attached:
E_Plane.m
theta = 0:0.01:pi/2
% The size of theta is 1 x 315
% E_Plane_norm_dB is an array that is also 1 x 315 with numbers
%{
Essentially, I am trying to see which number in the E_Plane_norm_dB array is the closest to -3.
Whichever number is closest to -3, I would need to output the "theta" value
that corresponds to that number in E_Plane_norm_dB
The way I’m doing this is by finding the "distance" from that element to -3
I keep comparing the "distances" to -3 between each element, until I find
the "smallest distance". Whichever element in E_Plane_norm_dB has the
smallest "distance", I would like to output that "theta" value.
%}
% Solving for the theta angle.
for j = 1:length(theta)
loop_theta = theta(j);
distance(j) = E_Plane_norm_dB(j) – (-3);
if (distance(j) < distance(j+1:length(theta)))
theta_angle = loop_theta;
end
end Hello,
I have a question about comparing values between elements of an array. I keep getting the error that says
Index exceeds the number of array elements. Index must not exceed 1.
I attached my code but I also put the section of the code I’m having an issue with.
See MATLAB code attached:
E_Plane.m
theta = 0:0.01:pi/2
% The size of theta is 1 x 315
% E_Plane_norm_dB is an array that is also 1 x 315 with numbers
%{
Essentially, I am trying to see which number in the E_Plane_norm_dB array is the closest to -3.
Whichever number is closest to -3, I would need to output the "theta" value
that corresponds to that number in E_Plane_norm_dB
The way I’m doing this is by finding the "distance" from that element to -3
I keep comparing the "distances" to -3 between each element, until I find
the "smallest distance". Whichever element in E_Plane_norm_dB has the
smallest "distance", I would like to output that "theta" value.
%}
% Solving for the theta angle.
for j = 1:length(theta)
loop_theta = theta(j);
distance(j) = E_Plane_norm_dB(j) – (-3);
if (distance(j) < distance(j+1:length(theta)))
theta_angle = loop_theta;
end
end comparing values, arrays, for loops MATLAB Answers — New Questions
Trouble simulating an RC low and high pass filter with trapoziodal aproximation
Hi,
I have been working to recreate the example code found in Andrew Simper’s 2020 lecture at Cytomic but have run into a roadblock. I can’t seem to get a reasonable capacitor approximation and am not sure why. You can see the relevant code on page 45 of the PDF here (lecture). I’ve attached my code below as well.
If you have any suggestions, please let me know. Thank you for your time.
%% circuit variables
Is=1e-12; % Saturation current (in Amperes)
n = 2; % Ideality factor (typically between 1 and 2)
temp = 300; % Temperature in Kelvin
k = 1.380649e-23; % Boltzmann constant (J/K)
q = 1.602176634e-19; % Electron charge (C)
% Calculate thermal voltage
vt=(k*temp)/q; % Thermal voltage (in Volts)
R1=2.2e3;
R2=6.8e3;
C1=0.47e-6;
C2=0.01e-6;
%% simulation loop
fs=48e3; %sample rate
Fd=1000; %input frequnecy
T=(1/1000)*10;
time=0:1/fs:T; %create time vector
vs=2.*sawtooth(Fd*2*pi*time); %create sawtooth input
%figure,plot(time,vs), title(‘input wavefrom (voltage v time’)
gr1=1/R1;%deinfe gr1 as the reciprocal of r1 for easier eq formation
gr2=1/R2;
m=1/2; %define division integral aproximation
h=1/fs; %define hight of the traps
gc1=C1/(h*m);
gc2=C2/(h*m);
ic1eq=0;
ic2eq=0;
%initalize vectors
v1=zeros(1,length(vs));
v2=zeros(1,length(vs));
v3=zeros(1,length(vs));
va1=0;
va2=0;
va3=0;
for k=1:length(vs)
va1=vs(k);
v1(k)=va1;
va2=(gr1*va1+gc1*va3-ic1eq)/(gr1+gc1);
v2(k)=va2;
va3=(gc1*va2+ic1eq+ic2eq)/(gc2+gc1+gr2);
%va3=(gc1*ic2eq+gr1*(ic1eq+ic2eq+gc1*va1))/(gr1*(gc2+gr2)+gc1*(gc2+gr1+gr2));
v3(k)=va3;
ic1eq = ic1eq + (1/m)*(gc1*(va3-va2)-ic1eq);
ic2eq = ic2eq + (1/m)*(gc2*(va3)-ic2eq);
end
figure, plot(time,v3)
title(‘input wave form vs output’), xlabel(‘time’), ylabel(‘voltage’)
hold on
plot(time,v1), legend(‘v3′,’v1’)Hi,
I have been working to recreate the example code found in Andrew Simper’s 2020 lecture at Cytomic but have run into a roadblock. I can’t seem to get a reasonable capacitor approximation and am not sure why. You can see the relevant code on page 45 of the PDF here (lecture). I’ve attached my code below as well.
If you have any suggestions, please let me know. Thank you for your time.
%% circuit variables
Is=1e-12; % Saturation current (in Amperes)
n = 2; % Ideality factor (typically between 1 and 2)
temp = 300; % Temperature in Kelvin
k = 1.380649e-23; % Boltzmann constant (J/K)
q = 1.602176634e-19; % Electron charge (C)
% Calculate thermal voltage
vt=(k*temp)/q; % Thermal voltage (in Volts)
R1=2.2e3;
R2=6.8e3;
C1=0.47e-6;
C2=0.01e-6;
%% simulation loop
fs=48e3; %sample rate
Fd=1000; %input frequnecy
T=(1/1000)*10;
time=0:1/fs:T; %create time vector
vs=2.*sawtooth(Fd*2*pi*time); %create sawtooth input
%figure,plot(time,vs), title(‘input wavefrom (voltage v time’)
gr1=1/R1;%deinfe gr1 as the reciprocal of r1 for easier eq formation
gr2=1/R2;
m=1/2; %define division integral aproximation
h=1/fs; %define hight of the traps
gc1=C1/(h*m);
gc2=C2/(h*m);
ic1eq=0;
ic2eq=0;
%initalize vectors
v1=zeros(1,length(vs));
v2=zeros(1,length(vs));
v3=zeros(1,length(vs));
va1=0;
va2=0;
va3=0;
for k=1:length(vs)
va1=vs(k);
v1(k)=va1;
va2=(gr1*va1+gc1*va3-ic1eq)/(gr1+gc1);
v2(k)=va2;
va3=(gc1*va2+ic1eq+ic2eq)/(gc2+gc1+gr2);
%va3=(gc1*ic2eq+gr1*(ic1eq+ic2eq+gc1*va1))/(gr1*(gc2+gr2)+gc1*(gc2+gr1+gr2));
v3(k)=va3;
ic1eq = ic1eq + (1/m)*(gc1*(va3-va2)-ic1eq);
ic2eq = ic2eq + (1/m)*(gc2*(va3)-ic2eq);
end
figure, plot(time,v3)
title(‘input wave form vs output’), xlabel(‘time’), ylabel(‘voltage’)
hold on
plot(time,v1), legend(‘v3′,’v1’) Hi,
I have been working to recreate the example code found in Andrew Simper’s 2020 lecture at Cytomic but have run into a roadblock. I can’t seem to get a reasonable capacitor approximation and am not sure why. You can see the relevant code on page 45 of the PDF here (lecture). I’ve attached my code below as well.
If you have any suggestions, please let me know. Thank you for your time.
%% circuit variables
Is=1e-12; % Saturation current (in Amperes)
n = 2; % Ideality factor (typically between 1 and 2)
temp = 300; % Temperature in Kelvin
k = 1.380649e-23; % Boltzmann constant (J/K)
q = 1.602176634e-19; % Electron charge (C)
% Calculate thermal voltage
vt=(k*temp)/q; % Thermal voltage (in Volts)
R1=2.2e3;
R2=6.8e3;
C1=0.47e-6;
C2=0.01e-6;
%% simulation loop
fs=48e3; %sample rate
Fd=1000; %input frequnecy
T=(1/1000)*10;
time=0:1/fs:T; %create time vector
vs=2.*sawtooth(Fd*2*pi*time); %create sawtooth input
%figure,plot(time,vs), title(‘input wavefrom (voltage v time’)
gr1=1/R1;%deinfe gr1 as the reciprocal of r1 for easier eq formation
gr2=1/R2;
m=1/2; %define division integral aproximation
h=1/fs; %define hight of the traps
gc1=C1/(h*m);
gc2=C2/(h*m);
ic1eq=0;
ic2eq=0;
%initalize vectors
v1=zeros(1,length(vs));
v2=zeros(1,length(vs));
v3=zeros(1,length(vs));
va1=0;
va2=0;
va3=0;
for k=1:length(vs)
va1=vs(k);
v1(k)=va1;
va2=(gr1*va1+gc1*va3-ic1eq)/(gr1+gc1);
v2(k)=va2;
va3=(gc1*va2+ic1eq+ic2eq)/(gc2+gc1+gr2);
%va3=(gc1*ic2eq+gr1*(ic1eq+ic2eq+gc1*va1))/(gr1*(gc2+gr2)+gc1*(gc2+gr1+gr2));
v3(k)=va3;
ic1eq = ic1eq + (1/m)*(gc1*(va3-va2)-ic1eq);
ic2eq = ic2eq + (1/m)*(gc2*(va3)-ic2eq);
end
figure, plot(time,v3)
title(‘input wave form vs output’), xlabel(‘time’), ylabel(‘voltage’)
hold on
plot(time,v1), legend(‘v3′,’v1’) signal processing, filters MATLAB Answers — New Questions
How can we read CAN message through Kvaser’s CAN Device by Packet Input block in Simulink Desktop Real-Time?
I’m trying to read IMU output, 8byte, though a Kvaser Leaf Light HS V2. I’ve installed Kvaser’s drivers and i can read data by software supplied with the IMU.
Now, I’d like to read the output data in MATLAB. I’ve installed Simulink Desktop Real-Time and use the Packet Input block.
Although we can choose a Kvaser’s CAN Device in the Packet block’s parameter, "Install new board", do we need the Vehicle Network Toolbox?
I noticed that the similar problem is posted in the link bellow, but the posted date is 2015. Is this situation still the same today?
https://jp.mathworks.com/matlabcentral/answers/194604-is-the-kvaser-leaf-light-hs-supported-by-both-vehicle-network-toolbox-and-real-time-windows-targetI’m trying to read IMU output, 8byte, though a Kvaser Leaf Light HS V2. I’ve installed Kvaser’s drivers and i can read data by software supplied with the IMU.
Now, I’d like to read the output data in MATLAB. I’ve installed Simulink Desktop Real-Time and use the Packet Input block.
Although we can choose a Kvaser’s CAN Device in the Packet block’s parameter, "Install new board", do we need the Vehicle Network Toolbox?
I noticed that the similar problem is posted in the link bellow, but the posted date is 2015. Is this situation still the same today?
https://jp.mathworks.com/matlabcentral/answers/194604-is-the-kvaser-leaf-light-hs-supported-by-both-vehicle-network-toolbox-and-real-time-windows-target I’m trying to read IMU output, 8byte, though a Kvaser Leaf Light HS V2. I’ve installed Kvaser’s drivers and i can read data by software supplied with the IMU.
Now, I’d like to read the output data in MATLAB. I’ve installed Simulink Desktop Real-Time and use the Packet Input block.
Although we can choose a Kvaser’s CAN Device in the Packet block’s parameter, "Install new board", do we need the Vehicle Network Toolbox?
I noticed that the similar problem is posted in the link bellow, but the posted date is 2015. Is this situation still the same today?
https://jp.mathworks.com/matlabcentral/answers/194604-is-the-kvaser-leaf-light-hs-supported-by-both-vehicle-network-toolbox-and-real-time-windows-target simulink desktop real-time, can, kvaser leaf light hs v2 MATLAB Answers — New Questions