Category: Matlab
Category Archives: Matlab
How to pass username and password to network location
Hi all,
I am trying to programatically access the network share under MATLAB dir command. It is working perfectly till the network is not password protected.
I am trying to pass the credentials as follows
dir(‘\servershare /user:test testpassword’)
but it gives me the "not found. Check the path or file permissions." error. I appreciate any hints.Hi all,
I am trying to programatically access the network share under MATLAB dir command. It is working perfectly till the network is not password protected.
I am trying to pass the credentials as follows
dir(‘\servershare /user:test testpassword’)
but it gives me the "not found. Check the path or file permissions." error. I appreciate any hints. Hi all,
I am trying to programatically access the network share under MATLAB dir command. It is working perfectly till the network is not password protected.
I am trying to pass the credentials as follows
dir(‘\servershare /user:test testpassword’)
but it gives me the "not found. Check the path or file permissions." error. I appreciate any hints. matlab, dir MATLAB Answers — New Questions
How to reset a stateflow state machine on external event?
Is it possible to re-initialize a state machine on an event generated by an other state machine?Is it possible to re-initialize a state machine on an event generated by an other state machine? Is it possible to re-initialize a state machine on an event generated by an other state machine? state machine MATLAB Answers — New Questions
Mathematical Equations to MATLAB
I am trying to implement a method for a reliability problem based on the following article main.pdf (sciencedirectassets.com). I am facing some problems while expressing the mathematical equations to MATLAB.
All required parameters are given as shown bellow.
lambda_i is given so that’s why I am expressing it bellow right after ‘%Equations’
Could you help me express the series of sum from (1 to N+1) of MTBFi from denominator, and the series of sum (from i to N) of the integral f(i)*(tau_i)*dtau_i from 0 to Xi?
Also, I don’t get when the lambda_i_plus_one is used on the CTM equation, any ideas?
%Parameters
beta = 2;alpha = 200;Ccl = 2000;Cpm = 2500;Rl = 1100;Cren = 50000;delta = 0.223;P = 12;N = 8; Clog = 1600;
%Equations
lambda_i = @(t) (beta / alpha) * (t / alpha).^(beta – 1); %It is given
lambda_i_plus_1 = @(t) exp(delta) * lambda_i(t);
f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i(t), 0, t));
integral_MTBF = @(tau_i) tau_i .* f_i(tau_i); % This doesn’t work right
MTBF_i = integral(integral_MTBF, 0, Inf); % This doesn’t work right
Xi = MTBF + P; % MTBF should be a vector so that Xi will take values from 1 to N as article says.
%CTM
numerator=Rl*P*(sum_of_integrals)+(N*(Cpm+Ccl+Clog))+((Rl*P)+Ccl+Cren+Clog);
denominator=((N+1)*P)+(series_of_sum);
CTM=num/denI am trying to implement a method for a reliability problem based on the following article main.pdf (sciencedirectassets.com). I am facing some problems while expressing the mathematical equations to MATLAB.
All required parameters are given as shown bellow.
lambda_i is given so that’s why I am expressing it bellow right after ‘%Equations’
Could you help me express the series of sum from (1 to N+1) of MTBFi from denominator, and the series of sum (from i to N) of the integral f(i)*(tau_i)*dtau_i from 0 to Xi?
Also, I don’t get when the lambda_i_plus_one is used on the CTM equation, any ideas?
%Parameters
beta = 2;alpha = 200;Ccl = 2000;Cpm = 2500;Rl = 1100;Cren = 50000;delta = 0.223;P = 12;N = 8; Clog = 1600;
%Equations
lambda_i = @(t) (beta / alpha) * (t / alpha).^(beta – 1); %It is given
lambda_i_plus_1 = @(t) exp(delta) * lambda_i(t);
f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i(t), 0, t));
integral_MTBF = @(tau_i) tau_i .* f_i(tau_i); % This doesn’t work right
MTBF_i = integral(integral_MTBF, 0, Inf); % This doesn’t work right
Xi = MTBF + P; % MTBF should be a vector so that Xi will take values from 1 to N as article says.
%CTM
numerator=Rl*P*(sum_of_integrals)+(N*(Cpm+Ccl+Clog))+((Rl*P)+Ccl+Cren+Clog);
denominator=((N+1)*P)+(series_of_sum);
CTM=num/den I am trying to implement a method for a reliability problem based on the following article main.pdf (sciencedirectassets.com). I am facing some problems while expressing the mathematical equations to MATLAB.
All required parameters are given as shown bellow.
lambda_i is given so that’s why I am expressing it bellow right after ‘%Equations’
Could you help me express the series of sum from (1 to N+1) of MTBFi from denominator, and the series of sum (from i to N) of the integral f(i)*(tau_i)*dtau_i from 0 to Xi?
Also, I don’t get when the lambda_i_plus_one is used on the CTM equation, any ideas?
%Parameters
beta = 2;alpha = 200;Ccl = 2000;Cpm = 2500;Rl = 1100;Cren = 50000;delta = 0.223;P = 12;N = 8; Clog = 1600;
%Equations
lambda_i = @(t) (beta / alpha) * (t / alpha).^(beta – 1); %It is given
lambda_i_plus_1 = @(t) exp(delta) * lambda_i(t);
f_i = @(t) lambda_i(t) .* exp(-integral(lambda_i(t), 0, t));
integral_MTBF = @(tau_i) tau_i .* f_i(tau_i); % This doesn’t work right
MTBF_i = integral(integral_MTBF, 0, Inf); % This doesn’t work right
Xi = MTBF + P; % MTBF should be a vector so that Xi will take values from 1 to N as article says.
%CTM
numerator=Rl*P*(sum_of_integrals)+(N*(Cpm+Ccl+Clog))+((Rl*P)+Ccl+Cren+Clog);
denominator=((N+1)*P)+(series_of_sum);
CTM=num/den mathematics, statistics, matlab function MATLAB Answers — New Questions
logspace with a different base
As far as I understood y = logspace(a,b,n) works for logarithms of base 10. For example we can have:
format longG
y = logspace(-2,3,6)
Is there a similar function or a simple way to perform the same calculation, but with a custom base B (for example a base B=3.5)?
I mean something like this:
a = -2;
b = 3;
n = 6;
B = 3.5;
y = …?As far as I understood y = logspace(a,b,n) works for logarithms of base 10. For example we can have:
format longG
y = logspace(-2,3,6)
Is there a similar function or a simple way to perform the same calculation, but with a custom base B (for example a base B=3.5)?
I mean something like this:
a = -2;
b = 3;
n = 6;
B = 3.5;
y = …? As far as I understood y = logspace(a,b,n) works for logarithms of base 10. For example we can have:
format longG
y = logspace(-2,3,6)
Is there a similar function or a simple way to perform the same calculation, but with a custom base B (for example a base B=3.5)?
I mean something like this:
a = -2;
b = 3;
n = 6;
B = 3.5;
y = …? logspace, logarithm, base MATLAB Answers — New Questions
Duplicate instances of methods executed while using parfeval and backgroundpool
I have the following function that sends regular updates
function countUp(q)
%countUp Counts up 1 every second
for i = 1:5
disp(i);
pause(1);
send(q, i);
end
end
The above function is called by the mlapp
properties (Access = private)
q = parallel.pool.DataQueue; % Description
L;
f;
end
methods (Access = private)
function myDisp(app, data)
log = [‘Recvd data update: ‘, num2str(data)];
disp(log);
app.Label.Text = num2str(data);
if(data == 5)
cancel(app.f);
app.StartButton.Enable = true;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
disp(‘Start button clicked’);
app.StartButton.Enable = false;
app.L = afterEach(app.q, @(data) myDisp(app, data));
app.f = parfeval(backgroundPool,@countUp,0,app.q);
disp(‘Start button cb complete’);
end
% Button pushed function: StopButton
function StopButtonPushed(app, event)
delete(app.L);
cancel(app.f);
app.StartButton.Enable = true;
end
First run returns
Start button clicked
Start button cb complete
Recvd data update: 1
Recvd data update: 2
Recvd data update: 3
Recvd data update: 4
Recvd data update: 5
Each time I start it it looks like duplicate instances of the function is executed
Start button clicked
Start button cb complete
Recvd data update: 1
Recvd data update: 1
Recvd data update: 2
Recvd data update: 2
Recvd data update: 3
Recvd data update: 3
Recvd data update: 4
Recvd data update: 4
Recvd data update: 5
Recvd data update: 5
It never looks like cancel(Future) is working as intended. What am I doing wrong?I have the following function that sends regular updates
function countUp(q)
%countUp Counts up 1 every second
for i = 1:5
disp(i);
pause(1);
send(q, i);
end
end
The above function is called by the mlapp
properties (Access = private)
q = parallel.pool.DataQueue; % Description
L;
f;
end
methods (Access = private)
function myDisp(app, data)
log = [‘Recvd data update: ‘, num2str(data)];
disp(log);
app.Label.Text = num2str(data);
if(data == 5)
cancel(app.f);
app.StartButton.Enable = true;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
disp(‘Start button clicked’);
app.StartButton.Enable = false;
app.L = afterEach(app.q, @(data) myDisp(app, data));
app.f = parfeval(backgroundPool,@countUp,0,app.q);
disp(‘Start button cb complete’);
end
% Button pushed function: StopButton
function StopButtonPushed(app, event)
delete(app.L);
cancel(app.f);
app.StartButton.Enable = true;
end
First run returns
Start button clicked
Start button cb complete
Recvd data update: 1
Recvd data update: 2
Recvd data update: 3
Recvd data update: 4
Recvd data update: 5
Each time I start it it looks like duplicate instances of the function is executed
Start button clicked
Start button cb complete
Recvd data update: 1
Recvd data update: 1
Recvd data update: 2
Recvd data update: 2
Recvd data update: 3
Recvd data update: 3
Recvd data update: 4
Recvd data update: 4
Recvd data update: 5
Recvd data update: 5
It never looks like cancel(Future) is working as intended. What am I doing wrong? I have the following function that sends regular updates
function countUp(q)
%countUp Counts up 1 every second
for i = 1:5
disp(i);
pause(1);
send(q, i);
end
end
The above function is called by the mlapp
properties (Access = private)
q = parallel.pool.DataQueue; % Description
L;
f;
end
methods (Access = private)
function myDisp(app, data)
log = [‘Recvd data update: ‘, num2str(data)];
disp(log);
app.Label.Text = num2str(data);
if(data == 5)
cancel(app.f);
app.StartButton.Enable = true;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
disp(‘Start button clicked’);
app.StartButton.Enable = false;
app.L = afterEach(app.q, @(data) myDisp(app, data));
app.f = parfeval(backgroundPool,@countUp,0,app.q);
disp(‘Start button cb complete’);
end
% Button pushed function: StopButton
function StopButtonPushed(app, event)
delete(app.L);
cancel(app.f);
app.StartButton.Enable = true;
end
First run returns
Start button clicked
Start button cb complete
Recvd data update: 1
Recvd data update: 2
Recvd data update: 3
Recvd data update: 4
Recvd data update: 5
Each time I start it it looks like duplicate instances of the function is executed
Start button clicked
Start button cb complete
Recvd data update: 1
Recvd data update: 1
Recvd data update: 2
Recvd data update: 2
Recvd data update: 3
Recvd data update: 3
Recvd data update: 4
Recvd data update: 4
Recvd data update: 5
Recvd data update: 5
It never looks like cancel(Future) is working as intended. What am I doing wrong? parfeval, backgroundpool MATLAB Answers — New Questions
Deep learning numerical regression, no images, custom loss function
I want to define a neural network or deep learning. Firstly, I have [500 * 4] data with a sample size of 500, each with 4 features (x1, x2, x3, x4).
The output variables are y1 and y2 ([500 * 2]), but I don’t have any output data, I only have their range of values (such as y1 in range (0-1)).
I have the variable z, which is the measured data, z=5 * e ^ (y1)+7 * sin (y2)
The loss function will be defined as : z(measure) – z (y1, y2)
The purpose of this neural network is to estimate y1 and y2 based on x1, x2, x3, x4.
For instance:
I know information about 500 cats, which are: x1 (height), x2 (weight), x3 (food intake), x4 (excretion).
I also know the age of these 500 cats: z
Now, I want to estimate y1 (cancer probability) and y2 (hair loss). The range of y1 is 0-1, and the range of y2 is -10 to 10
Do you know how to establish such deep learning or neural networks? Is there a simple example?I want to define a neural network or deep learning. Firstly, I have [500 * 4] data with a sample size of 500, each with 4 features (x1, x2, x3, x4).
The output variables are y1 and y2 ([500 * 2]), but I don’t have any output data, I only have their range of values (such as y1 in range (0-1)).
I have the variable z, which is the measured data, z=5 * e ^ (y1)+7 * sin (y2)
The loss function will be defined as : z(measure) – z (y1, y2)
The purpose of this neural network is to estimate y1 and y2 based on x1, x2, x3, x4.
For instance:
I know information about 500 cats, which are: x1 (height), x2 (weight), x3 (food intake), x4 (excretion).
I also know the age of these 500 cats: z
Now, I want to estimate y1 (cancer probability) and y2 (hair loss). The range of y1 is 0-1, and the range of y2 is -10 to 10
Do you know how to establish such deep learning or neural networks? Is there a simple example? I want to define a neural network or deep learning. Firstly, I have [500 * 4] data with a sample size of 500, each with 4 features (x1, x2, x3, x4).
The output variables are y1 and y2 ([500 * 2]), but I don’t have any output data, I only have their range of values (such as y1 in range (0-1)).
I have the variable z, which is the measured data, z=5 * e ^ (y1)+7 * sin (y2)
The loss function will be defined as : z(measure) – z (y1, y2)
The purpose of this neural network is to estimate y1 and y2 based on x1, x2, x3, x4.
For instance:
I know information about 500 cats, which are: x1 (height), x2 (weight), x3 (food intake), x4 (excretion).
I also know the age of these 500 cats: z
Now, I want to estimate y1 (cancer probability) and y2 (hair loss). The range of y1 is 0-1, and the range of y2 is -10 to 10
Do you know how to establish such deep learning or neural networks? Is there a simple example? deep learning, loss function, regression MATLAB Answers — New Questions
Why is Dead Logic detected on my Switch block when using Design Verifier?
I believe that I am experiencing a false positive when running the mathworks.sldv.deadlogic check in the Model Advisor on Simulink. The model consists of a simple Switch block with an inport, outport, and two different Constant blocks input into the data ports.
The model:
The warning reads:
"RelationalOperator: input1 ~= input2 false"I believe that I am experiencing a false positive when running the mathworks.sldv.deadlogic check in the Model Advisor on Simulink. The model consists of a simple Switch block with an inport, outport, and two different Constant blocks input into the data ports.
The model:
The warning reads:
"RelationalOperator: input1 ~= input2 false" I believe that I am experiencing a false positive when running the mathworks.sldv.deadlogic check in the Model Advisor on Simulink. The model consists of a simple Switch block with an inport, outport, and two different Constant blocks input into the data ports.
The model:
The warning reads:
"RelationalOperator: input1 ~= input2 false" dead, logic, detection, switch, block, replacement MATLAB Answers — New Questions
How do I convert a Finite Integer to Hexadecimal in Simulink with Support for Code Generation?
There is no "dec2hex" block in Simulink, so how do you go about converting finite integers to hexadecimal representation in Simulink, with support for code generation?There is no "dec2hex" block in Simulink, so how do you go about converting finite integers to hexadecimal representation in Simulink, with support for code generation? There is no "dec2hex" block in Simulink, so how do you go about converting finite integers to hexadecimal representation in Simulink, with support for code generation? hexadecimal, dec2hex, simulink MATLAB Answers — New Questions
How do I prioritize Model Advisor check failures?
I want to resolve some Model Advisor checks first if they were to fail. How would I do that?I want to resolve some Model Advisor checks first if they were to fail. How would I do that? I want to resolve some Model Advisor checks first if they were to fail. How would I do that? model advisor MATLAB Answers — New Questions
Discrepancy between simscape and analytical solution
I am trying to simulate the behaviour of an electromechanical actuator, to model the BLDC I am using the block "Permanent Magnet
Synchronous Machine" with "Mechanical input" set into Mechanical rotational port.
The output of the block comprehends the rotor velocity in rad/s between the various informations.
I also connected the Mechanical rotational port to a set of gears modeled through simscape blocks (i’ll provide an image to clarify).
When I compute the actuation speed through a direct conversion of the motor velocity from rad/s to mm/s i obtain a value which is different from the one coming from the set of simscape gears.
In the picture the green line is the mechanical rotational port of the aforementioned block, while the series of gain is the simple conversion of the motor velocity from rad/s to mm/s
Am I using some of these blocks in the wrong way? It actually would seem to me a pretty straightforward application but apparently I’m missing something.
The gear ratio are all correct and so are the units of measure of the conversion blocks of the simscape section of the image.
At the moment I was using for the feedback control the velocity computed directly with the gains (black line) while I was using the green one only to apply the load to the motor, since otherwise I don’t see a way to model an external load, could this be a correct approach to the problem?
Thank you in advance, i will be extremly greatful to the ones who will answer, if you need more details feel free to ask me anything that could make the problem more clear to understand.I am trying to simulate the behaviour of an electromechanical actuator, to model the BLDC I am using the block "Permanent Magnet
Synchronous Machine" with "Mechanical input" set into Mechanical rotational port.
The output of the block comprehends the rotor velocity in rad/s between the various informations.
I also connected the Mechanical rotational port to a set of gears modeled through simscape blocks (i’ll provide an image to clarify).
When I compute the actuation speed through a direct conversion of the motor velocity from rad/s to mm/s i obtain a value which is different from the one coming from the set of simscape gears.
In the picture the green line is the mechanical rotational port of the aforementioned block, while the series of gain is the simple conversion of the motor velocity from rad/s to mm/s
Am I using some of these blocks in the wrong way? It actually would seem to me a pretty straightforward application but apparently I’m missing something.
The gear ratio are all correct and so are the units of measure of the conversion blocks of the simscape section of the image.
At the moment I was using for the feedback control the velocity computed directly with the gains (black line) while I was using the green one only to apply the load to the motor, since otherwise I don’t see a way to model an external load, could this be a correct approach to the problem?
Thank you in advance, i will be extremly greatful to the ones who will answer, if you need more details feel free to ask me anything that could make the problem more clear to understand. I am trying to simulate the behaviour of an electromechanical actuator, to model the BLDC I am using the block "Permanent Magnet
Synchronous Machine" with "Mechanical input" set into Mechanical rotational port.
The output of the block comprehends the rotor velocity in rad/s between the various informations.
I also connected the Mechanical rotational port to a set of gears modeled through simscape blocks (i’ll provide an image to clarify).
When I compute the actuation speed through a direct conversion of the motor velocity from rad/s to mm/s i obtain a value which is different from the one coming from the set of simscape gears.
In the picture the green line is the mechanical rotational port of the aforementioned block, while the series of gain is the simple conversion of the motor velocity from rad/s to mm/s
Am I using some of these blocks in the wrong way? It actually would seem to me a pretty straightforward application but apparently I’m missing something.
The gear ratio are all correct and so are the units of measure of the conversion blocks of the simscape section of the image.
At the moment I was using for the feedback control the velocity computed directly with the gains (black line) while I was using the green one only to apply the load to the motor, since otherwise I don’t see a way to model an external load, could this be a correct approach to the problem?
Thank you in advance, i will be extremly greatful to the ones who will answer, if you need more details feel free to ask me anything that could make the problem more clear to understand. simscape, simulink, synchronous machine MATLAB Answers — New Questions
rcsSignature RCS pattern change for radarTransceiver data generation
Hi!
I’m working with radarTransceiver object and I came across an issue, when I want to change the RCS of my target to achieve weaker signal nothing happens. I’ve tried different configurations of rcsSignature patterns, but nothing works, the signal is always with the same SNR.
Am I missing something?
Example code is in attachement with my RCS pattern modifications.
I want to achieve the smaller ampitude of the received signal reflected from taget 1.
Thank you for you help!Hi!
I’m working with radarTransceiver object and I came across an issue, when I want to change the RCS of my target to achieve weaker signal nothing happens. I’ve tried different configurations of rcsSignature patterns, but nothing works, the signal is always with the same SNR.
Am I missing something?
Example code is in attachement with my RCS pattern modifications.
I want to achieve the smaller ampitude of the received signal reflected from taget 1.
Thank you for you help! Hi!
I’m working with radarTransceiver object and I came across an issue, when I want to change the RCS of my target to achieve weaker signal nothing happens. I’ve tried different configurations of rcsSignature patterns, but nothing works, the signal is always with the same SNR.
Am I missing something?
Example code is in attachement with my RCS pattern modifications.
I want to achieve the smaller ampitude of the received signal reflected from taget 1.
Thank you for you help! radar, rcs, radartransceiver, rcssignature MATLAB Answers — New Questions
Output of irf() for VAR models when estimation data is in a matrix or a timetable
Hello,
I’m estimating a K-dimensional VAR model and looking at IRFs for structural (orthogonalized shocks) using the Econometrics toolbox, specifically varm(), estimate() and irf(). For orthogonalized shocks, the order of the model variables matters, as does the decomposition method. irf() uses the lower Cholesky decomposition (which is standard in econometrics), meaning that an orthogonalized shock to variable k will only have a contemporaneous effect on variables k, …, K, but not variables 1, …, k-1.
When estimating the model, I can use an array or a (time)table for my observed data, and the output of irf() will then also be an array or (time)table respectively. My question concerns the interpretation of the entries of either return value, specifically which IRFs are found where in the data structures returned. I am finding difficult to make sense of the documentation, and I’m now thinking that the documentation for irf() (alternatively, its code) is wrong for the timetable case.
Here’s a code snippet, based on the Danish data example in the documentation, that will illustrate what I mean. The order of variables in this model is M2, Y, IB, ID, meaning that (say) a shock to Y should influence IB and ID contemporaneously but not M2.
load Data_JDanish
Mdl = varm(4, 2);
Mdl.SeriesNames = DataTable.Properties.VariableNames;
EstMdlMat = estimate(Mdl, Data);
rng(1);
ResponseMat = irf(EstMdlMat);
% "Display the IRF of the bond rate (variable 3, IB) when the log of real
% income (variable 2, Y) is shocked at time 0."
ResponseMat(:, 2, 3).’
EstMdlTab = estimate(Mdl, DataTimeTable);
rng(1);
ResponseTab = irf(EstMdlTab);
% "For example, Tbl.M2_IRF(:,2) is the IRF of M2 resulting from a
% one-standard-deviation shock on 01-Jul-1974 (period 0) to
% Mdl.SeriesNames(2), which is the variable Y."
ResponseTab.IB_IRF(:, 2).’
Here, ReponseMat(:, 2, 3) is (as indicated by the quote in the comment, which is copied verbatim from the documentation page) the IRF of IB after an orthogonalized shock to Y. When estimating the model using data in a timetable, then (as indicated by the second quote, which is also from the documentation), ResponseTab.IB_IRF(:, 2) should be the IRF of IB after an orthogonalized shock to Y, and hence be identical to ResponseMat(:, 2, 3) (possibly up to round-off error).
Except it isn’t. In fact, the first element of ResponseTab.IB_IRF(:, 2) is zero. This suggests to me that when using irf() with data in a timetable, the economic ordering of the variables should be the opposite. This would result if irf() was using the upper Cholesky decomposition in this case.
But there’s no good reason why it should do that. In fact, there is no good reason why the two methods should give different results at all. The easiest explanation (excluding silly mistakes on my part) is that the documentation for the timetable case is wrong, and ResponseTab.IB_IRF(:, 2) should be read as the IRF of variable 2 (Y) after a shock to IB.
Would be nice if someone could shed some light on this.
For the record: I’m using MATLAB R2024a Update 4, the latest version.Hello,
I’m estimating a K-dimensional VAR model and looking at IRFs for structural (orthogonalized shocks) using the Econometrics toolbox, specifically varm(), estimate() and irf(). For orthogonalized shocks, the order of the model variables matters, as does the decomposition method. irf() uses the lower Cholesky decomposition (which is standard in econometrics), meaning that an orthogonalized shock to variable k will only have a contemporaneous effect on variables k, …, K, but not variables 1, …, k-1.
When estimating the model, I can use an array or a (time)table for my observed data, and the output of irf() will then also be an array or (time)table respectively. My question concerns the interpretation of the entries of either return value, specifically which IRFs are found where in the data structures returned. I am finding difficult to make sense of the documentation, and I’m now thinking that the documentation for irf() (alternatively, its code) is wrong for the timetable case.
Here’s a code snippet, based on the Danish data example in the documentation, that will illustrate what I mean. The order of variables in this model is M2, Y, IB, ID, meaning that (say) a shock to Y should influence IB and ID contemporaneously but not M2.
load Data_JDanish
Mdl = varm(4, 2);
Mdl.SeriesNames = DataTable.Properties.VariableNames;
EstMdlMat = estimate(Mdl, Data);
rng(1);
ResponseMat = irf(EstMdlMat);
% "Display the IRF of the bond rate (variable 3, IB) when the log of real
% income (variable 2, Y) is shocked at time 0."
ResponseMat(:, 2, 3).’
EstMdlTab = estimate(Mdl, DataTimeTable);
rng(1);
ResponseTab = irf(EstMdlTab);
% "For example, Tbl.M2_IRF(:,2) is the IRF of M2 resulting from a
% one-standard-deviation shock on 01-Jul-1974 (period 0) to
% Mdl.SeriesNames(2), which is the variable Y."
ResponseTab.IB_IRF(:, 2).’
Here, ReponseMat(:, 2, 3) is (as indicated by the quote in the comment, which is copied verbatim from the documentation page) the IRF of IB after an orthogonalized shock to Y. When estimating the model using data in a timetable, then (as indicated by the second quote, which is also from the documentation), ResponseTab.IB_IRF(:, 2) should be the IRF of IB after an orthogonalized shock to Y, and hence be identical to ResponseMat(:, 2, 3) (possibly up to round-off error).
Except it isn’t. In fact, the first element of ResponseTab.IB_IRF(:, 2) is zero. This suggests to me that when using irf() with data in a timetable, the economic ordering of the variables should be the opposite. This would result if irf() was using the upper Cholesky decomposition in this case.
But there’s no good reason why it should do that. In fact, there is no good reason why the two methods should give different results at all. The easiest explanation (excluding silly mistakes on my part) is that the documentation for the timetable case is wrong, and ResponseTab.IB_IRF(:, 2) should be read as the IRF of variable 2 (Y) after a shock to IB.
Would be nice if someone could shed some light on this.
For the record: I’m using MATLAB R2024a Update 4, the latest version. Hello,
I’m estimating a K-dimensional VAR model and looking at IRFs for structural (orthogonalized shocks) using the Econometrics toolbox, specifically varm(), estimate() and irf(). For orthogonalized shocks, the order of the model variables matters, as does the decomposition method. irf() uses the lower Cholesky decomposition (which is standard in econometrics), meaning that an orthogonalized shock to variable k will only have a contemporaneous effect on variables k, …, K, but not variables 1, …, k-1.
When estimating the model, I can use an array or a (time)table for my observed data, and the output of irf() will then also be an array or (time)table respectively. My question concerns the interpretation of the entries of either return value, specifically which IRFs are found where in the data structures returned. I am finding difficult to make sense of the documentation, and I’m now thinking that the documentation for irf() (alternatively, its code) is wrong for the timetable case.
Here’s a code snippet, based on the Danish data example in the documentation, that will illustrate what I mean. The order of variables in this model is M2, Y, IB, ID, meaning that (say) a shock to Y should influence IB and ID contemporaneously but not M2.
load Data_JDanish
Mdl = varm(4, 2);
Mdl.SeriesNames = DataTable.Properties.VariableNames;
EstMdlMat = estimate(Mdl, Data);
rng(1);
ResponseMat = irf(EstMdlMat);
% "Display the IRF of the bond rate (variable 3, IB) when the log of real
% income (variable 2, Y) is shocked at time 0."
ResponseMat(:, 2, 3).’
EstMdlTab = estimate(Mdl, DataTimeTable);
rng(1);
ResponseTab = irf(EstMdlTab);
% "For example, Tbl.M2_IRF(:,2) is the IRF of M2 resulting from a
% one-standard-deviation shock on 01-Jul-1974 (period 0) to
% Mdl.SeriesNames(2), which is the variable Y."
ResponseTab.IB_IRF(:, 2).’
Here, ReponseMat(:, 2, 3) is (as indicated by the quote in the comment, which is copied verbatim from the documentation page) the IRF of IB after an orthogonalized shock to Y. When estimating the model using data in a timetable, then (as indicated by the second quote, which is also from the documentation), ResponseTab.IB_IRF(:, 2) should be the IRF of IB after an orthogonalized shock to Y, and hence be identical to ResponseMat(:, 2, 3) (possibly up to round-off error).
Except it isn’t. In fact, the first element of ResponseTab.IB_IRF(:, 2) is zero. This suggests to me that when using irf() with data in a timetable, the economic ordering of the variables should be the opposite. This would result if irf() was using the upper Cholesky decomposition in this case.
But there’s no good reason why it should do that. In fact, there is no good reason why the two methods should give different results at all. The easiest explanation (excluding silly mistakes on my part) is that the documentation for the timetable case is wrong, and ResponseTab.IB_IRF(:, 2) should be read as the IRF of variable 2 (Y) after a shock to IB.
Would be nice if someone could shed some light on this.
For the record: I’m using MATLAB R2024a Update 4, the latest version. irf, econometrics, var model, varm, econometrics toolbox, cholesky decomposition, variable ordering, irfs MATLAB Answers — New Questions
What is the meaning of the variables in the C generated code of a Linear Discriminant Analysis model trained in MATLAB?
I have trained a Linear Discriminant Analysis model in MATLAB, and I have generated the corresponding C code:
void myLDApredic(const double X[8], cell_wrap_0 label[1],double score[5])
{
static const double dv[8] = {22.242777113313874, 10091.972043688236,
18.120065167575063, 1.6703515441084688E+6,
24.467860977243351, 10578.886659888578,
19.515843697095619, 1.9037831242647208E+6};
static const double dv1[5] = {0.19444444444444445, 0.19791666666666666,
0.20254629629629631, 0.18865740740740741,
0.21643518518518517};
// rest of function body…
}
void DiagonalDiscriminant(const double X[8], double mah[5])
{
static const double dv[40] = {
92.058756510416757, 428.55436769005888, 99.445223214285761,
121.16319976993877, 28.000396891711258, 12736.000000000013,
81355.60233918138, 19612.525714285723, 16993.374233128856,
3436.1497326203244, 143.11044456845252, 72.791255482456208,
144.52926339285719, 196.37662960122714, 29.916151403743349,
5.2292266666666726E+6, 3.3097596257309979E+6, 7.8175085714285746E+6,
7.0232076564417249E+6, 894724.10695187247, 480.39411272321479,
26.045367324561425, 53.19522321428574, 239.98229006901863,
20.971883355614992, 80371.8095238096, 2976.1871345029267,
8478.720000000003, 52414.036809816, 2602.4385026737991,
325.64160156250028, 34.383543494152079, 84.338125000000034,
72.35264091257676, 33.127548462566885, 1.6916089904761918E+7,
1.5491024093567266E+6, 3.7583959771428583E+6, 4.3856852024539923E+6,
1.6065081497326223E+6};
static const double dv1[8] = {0.044958414810596169, 9.9088661331104676E-5,
0.0551874394905295, 5.9867637056829179E-7,
0.040869939588510124, 9.4527905643572937E-5,
0.051240418580971815, 5.2526991507303129E-7};
// rest of function body…
}
What is the meaning of the variables "dv", "dv1" of files "myLDApredict" and "DiagonalDiscriminant"?I have trained a Linear Discriminant Analysis model in MATLAB, and I have generated the corresponding C code:
void myLDApredic(const double X[8], cell_wrap_0 label[1],double score[5])
{
static const double dv[8] = {22.242777113313874, 10091.972043688236,
18.120065167575063, 1.6703515441084688E+6,
24.467860977243351, 10578.886659888578,
19.515843697095619, 1.9037831242647208E+6};
static const double dv1[5] = {0.19444444444444445, 0.19791666666666666,
0.20254629629629631, 0.18865740740740741,
0.21643518518518517};
// rest of function body…
}
void DiagonalDiscriminant(const double X[8], double mah[5])
{
static const double dv[40] = {
92.058756510416757, 428.55436769005888, 99.445223214285761,
121.16319976993877, 28.000396891711258, 12736.000000000013,
81355.60233918138, 19612.525714285723, 16993.374233128856,
3436.1497326203244, 143.11044456845252, 72.791255482456208,
144.52926339285719, 196.37662960122714, 29.916151403743349,
5.2292266666666726E+6, 3.3097596257309979E+6, 7.8175085714285746E+6,
7.0232076564417249E+6, 894724.10695187247, 480.39411272321479,
26.045367324561425, 53.19522321428574, 239.98229006901863,
20.971883355614992, 80371.8095238096, 2976.1871345029267,
8478.720000000003, 52414.036809816, 2602.4385026737991,
325.64160156250028, 34.383543494152079, 84.338125000000034,
72.35264091257676, 33.127548462566885, 1.6916089904761918E+7,
1.5491024093567266E+6, 3.7583959771428583E+6, 4.3856852024539923E+6,
1.6065081497326223E+6};
static const double dv1[8] = {0.044958414810596169, 9.9088661331104676E-5,
0.0551874394905295, 5.9867637056829179E-7,
0.040869939588510124, 9.4527905643572937E-5,
0.051240418580971815, 5.2526991507303129E-7};
// rest of function body…
}
What is the meaning of the variables "dv", "dv1" of files "myLDApredict" and "DiagonalDiscriminant"? I have trained a Linear Discriminant Analysis model in MATLAB, and I have generated the corresponding C code:
void myLDApredic(const double X[8], cell_wrap_0 label[1],double score[5])
{
static const double dv[8] = {22.242777113313874, 10091.972043688236,
18.120065167575063, 1.6703515441084688E+6,
24.467860977243351, 10578.886659888578,
19.515843697095619, 1.9037831242647208E+6};
static const double dv1[5] = {0.19444444444444445, 0.19791666666666666,
0.20254629629629631, 0.18865740740740741,
0.21643518518518517};
// rest of function body…
}
void DiagonalDiscriminant(const double X[8], double mah[5])
{
static const double dv[40] = {
92.058756510416757, 428.55436769005888, 99.445223214285761,
121.16319976993877, 28.000396891711258, 12736.000000000013,
81355.60233918138, 19612.525714285723, 16993.374233128856,
3436.1497326203244, 143.11044456845252, 72.791255482456208,
144.52926339285719, 196.37662960122714, 29.916151403743349,
5.2292266666666726E+6, 3.3097596257309979E+6, 7.8175085714285746E+6,
7.0232076564417249E+6, 894724.10695187247, 480.39411272321479,
26.045367324561425, 53.19522321428574, 239.98229006901863,
20.971883355614992, 80371.8095238096, 2976.1871345029267,
8478.720000000003, 52414.036809816, 2602.4385026737991,
325.64160156250028, 34.383543494152079, 84.338125000000034,
72.35264091257676, 33.127548462566885, 1.6916089904761918E+7,
1.5491024093567266E+6, 3.7583959771428583E+6, 4.3856852024539923E+6,
1.6065081497326223E+6};
static const double dv1[8] = {0.044958414810596169, 9.9088661331104676E-5,
0.0551874394905295, 5.9867637056829179E-7,
0.040869939588510124, 9.4527905643572937E-5,
0.051240418580971815, 5.2526991507303129E-7};
// rest of function body…
}
What is the meaning of the variables "dv", "dv1" of files "myLDApredict" and "DiagonalDiscriminant"? c, code, lineardiscriminantanalysis, variables, meaning MATLAB Answers — New Questions
Why do I receive a “not enough information to determine output sizes” error while compiling a model with a MATLAB Function block in R2024a?
I am getting error messages like the following when compiling a model with a MATLAB Function block:
Simulink does not have enough information to determine output sizes for this block.
Chart expects data ‘y’ to have size ‘[1 65536]’, but the propagated size is ‘[1 16]’. Fully specify all inherited properties of your inputs and outputs.
Why am I receiving this error and how can I fix this?I am getting error messages like the following when compiling a model with a MATLAB Function block:
Simulink does not have enough information to determine output sizes for this block.
Chart expects data ‘y’ to have size ‘[1 65536]’, but the propagated size is ‘[1 16]’. Fully specify all inherited properties of your inputs and outputs.
Why am I receiving this error and how can I fix this? I am getting error messages like the following when compiling a model with a MATLAB Function block:
Simulink does not have enough information to determine output sizes for this block.
Chart expects data ‘y’ to have size ‘[1 65536]’, but the propagated size is ‘[1 16]’. Fully specify all inherited properties of your inputs and outputs.
Why am I receiving this error and how can I fix this? dimensions, output, matlabfunctionblock MATLAB Answers — New Questions
Deleting Breakpoint Table in Simulink
When I hover over breakpoint table in Simulink, I’m simply unable to get rid of the table. Secondly, the values shown in the screenshot no longer represent the new breakpoint values that I’ve updated within the 2-D lookup table block. Thank you in advance for any tips or help.When I hover over breakpoint table in Simulink, I’m simply unable to get rid of the table. Secondly, the values shown in the screenshot no longer represent the new breakpoint values that I’ve updated within the 2-D lookup table block. Thank you in advance for any tips or help. When I hover over breakpoint table in Simulink, I’m simply unable to get rid of the table. Secondly, the values shown in the screenshot no longer represent the new breakpoint values that I’ve updated within the 2-D lookup table block. Thank you in advance for any tips or help. simulink, 2-d lookup table block, breakpoint MATLAB Answers — New Questions
Running a loop of inputting tables into MatLab
Hi, I have this code:
[data]=loadScopeData(‘/Volumes/usb/table_5.csv’,[1,inf]);
max_col2_5=max(data.pvdf_v)
max_col3_5=max(data.cell_v)
and I have tables for each trial 5-40 and I was wondering if there was a way that I could run this in a loop so import each table (table_5, table_6, table_7…), and to find the max of each of the second two columns labeled (max_col2_5, max_col2_6, max_col2_7…) matching the number of the table, so that I can later make a table out of these values. I have bolded the numbers that would need to increase by one each time, the rest of teh script would stay the same. I am thinking that a while loop could work for this, but I’m not sure how I can integrate that into the file name when loading the data. Turning this into a loop would be a lot faster and easier to run that having this script for each trail, especially as I start doing more. Thanks.Hi, I have this code:
[data]=loadScopeData(‘/Volumes/usb/table_5.csv’,[1,inf]);
max_col2_5=max(data.pvdf_v)
max_col3_5=max(data.cell_v)
and I have tables for each trial 5-40 and I was wondering if there was a way that I could run this in a loop so import each table (table_5, table_6, table_7…), and to find the max of each of the second two columns labeled (max_col2_5, max_col2_6, max_col2_7…) matching the number of the table, so that I can later make a table out of these values. I have bolded the numbers that would need to increase by one each time, the rest of teh script would stay the same. I am thinking that a while loop could work for this, but I’m not sure how I can integrate that into the file name when loading the data. Turning this into a loop would be a lot faster and easier to run that having this script for each trail, especially as I start doing more. Thanks. Hi, I have this code:
[data]=loadScopeData(‘/Volumes/usb/table_5.csv’,[1,inf]);
max_col2_5=max(data.pvdf_v)
max_col3_5=max(data.cell_v)
and I have tables for each trial 5-40 and I was wondering if there was a way that I could run this in a loop so import each table (table_5, table_6, table_7…), and to find the max of each of the second two columns labeled (max_col2_5, max_col2_6, max_col2_7…) matching the number of the table, so that I can later make a table out of these values. I have bolded the numbers that would need to increase by one each time, the rest of teh script would stay the same. I am thinking that a while loop could work for this, but I’m not sure how I can integrate that into the file name when loading the data. Turning this into a loop would be a lot faster and easier to run that having this script for each trail, especially as I start doing more. Thanks. loop, data import MATLAB Answers — New Questions
Build HDF5 Filter Plugins on Linux Using MATLAB HDF5 Shared Library or GNU Export Map
How do I build HDF5 Filter Plugins on Linux Using MATLAB HDF5 Shared Library or GNU Export Map?How do I build HDF5 Filter Plugins on Linux Using MATLAB HDF5 Shared Library or GNU Export Map? How do I build HDF5 Filter Plugins on Linux Using MATLAB HDF5 Shared Library or GNU Export Map? MATLAB Answers — New Questions
why my course is showing no resources available
why my course is showing no resources availablewhy my course is showing no resources available why my course is showing no resources available why my course is showing no resources available MATLAB Answers — New Questions
Plotting error bars on curve
Hello,
I have code that compares two devices and I am plotting the error on y-axis throughout a gait cycle % (on the x axis).
I am trying to get the error bars to plot the standard error but I am having an unexpected result when plotting the curve.
This is the code I am working with.
Initially x, ave_diff and SE are 1X1000 and I would like to plot it over a gait cycle from 0-100% hence why I have resampled the signals.
However, when I run this code I have extra values at the end of the plot, yet the resmapled variables are all 101X1?
I cannot spot my error and was wondering if someone my point me in the correct direction or suggest where my fault lies.
I have attached the curve and the area where the issue lies, you can see the standard error bars also become strange.
Thanks in advance
figure()
x = smooth(resample((gc),101,length(gc),’Dimension’,1));
ave_diff_resample = smooth(resample((ave_diff),101,length(ave_diff),’Dimension’,1));
SE_resampled = smooth(resample((SE),101,length(SE),’Dimension’,1));
set(gcf,’Color’,’w’);
%standard error plot
plot(x, ave_diff_resample,’-‘,’Color’,[0 0 0],’linewidth’,0.5)
hold on
% Adding error bars
errorbar(x, ave_diff_resample, SE_resampled, ‘vertical’);
hold on
hline = refline(0, 0);
hline.Color = ‘k’;
xlim([0 100]);
ylim([-15 15]);
legend(‘Signed Difference’, ‘Standard error bar’)
xlabel(‘Gait cycle %’)
ylabel(‘Difference (deg)’)Hello,
I have code that compares two devices and I am plotting the error on y-axis throughout a gait cycle % (on the x axis).
I am trying to get the error bars to plot the standard error but I am having an unexpected result when plotting the curve.
This is the code I am working with.
Initially x, ave_diff and SE are 1X1000 and I would like to plot it over a gait cycle from 0-100% hence why I have resampled the signals.
However, when I run this code I have extra values at the end of the plot, yet the resmapled variables are all 101X1?
I cannot spot my error and was wondering if someone my point me in the correct direction or suggest where my fault lies.
I have attached the curve and the area where the issue lies, you can see the standard error bars also become strange.
Thanks in advance
figure()
x = smooth(resample((gc),101,length(gc),’Dimension’,1));
ave_diff_resample = smooth(resample((ave_diff),101,length(ave_diff),’Dimension’,1));
SE_resampled = smooth(resample((SE),101,length(SE),’Dimension’,1));
set(gcf,’Color’,’w’);
%standard error plot
plot(x, ave_diff_resample,’-‘,’Color’,[0 0 0],’linewidth’,0.5)
hold on
% Adding error bars
errorbar(x, ave_diff_resample, SE_resampled, ‘vertical’);
hold on
hline = refline(0, 0);
hline.Color = ‘k’;
xlim([0 100]);
ylim([-15 15]);
legend(‘Signed Difference’, ‘Standard error bar’)
xlabel(‘Gait cycle %’)
ylabel(‘Difference (deg)’) Hello,
I have code that compares two devices and I am plotting the error on y-axis throughout a gait cycle % (on the x axis).
I am trying to get the error bars to plot the standard error but I am having an unexpected result when plotting the curve.
This is the code I am working with.
Initially x, ave_diff and SE are 1X1000 and I would like to plot it over a gait cycle from 0-100% hence why I have resampled the signals.
However, when I run this code I have extra values at the end of the plot, yet the resmapled variables are all 101X1?
I cannot spot my error and was wondering if someone my point me in the correct direction or suggest where my fault lies.
I have attached the curve and the area where the issue lies, you can see the standard error bars also become strange.
Thanks in advance
figure()
x = smooth(resample((gc),101,length(gc),’Dimension’,1));
ave_diff_resample = smooth(resample((ave_diff),101,length(ave_diff),’Dimension’,1));
SE_resampled = smooth(resample((SE),101,length(SE),’Dimension’,1));
set(gcf,’Color’,’w’);
%standard error plot
plot(x, ave_diff_resample,’-‘,’Color’,[0 0 0],’linewidth’,0.5)
hold on
% Adding error bars
errorbar(x, ave_diff_resample, SE_resampled, ‘vertical’);
hold on
hline = refline(0, 0);
hline.Color = ‘k’;
xlim([0 100]);
ylim([-15 15]);
legend(‘Signed Difference’, ‘Standard error bar’)
xlabel(‘Gait cycle %’)
ylabel(‘Difference (deg)’) error bars, curve plotting, resample data, plot MATLAB Answers — New Questions
CUSOLVER_STATUS_INTERNAL_ERROR with RTX 4080 Super in MATLAB 2022a C MEX Function
Hello,
I’m encountering a problem when running a CUDA-based C MEX function in MATLAB 2022a on a machine equipped with an RTX 4080 Super GPU. The specific error occurs when executing the line:
cusolverStatus_t status = cusolverDnCreate(&handle);
Here are the details:
The MEX function compiles successfully using the mexcuda command.
The same code operates correctly on this machine when using an RTX 2080Ti GPU with exactly the same software setup.
When the RTX 4080 Super is used, this error appears, even though the function runs without issues in Visual Studio, indicating that CUDA (Version 12.5) is properly configured on my system.
Upgrading to MATLAB 2024a resolves the issue, suggesting a compatibility problem with MATLAB 2022a. However, I am restricted to using MATLAB 2022a due to dependencies on other external software.
Additional context:
NVIDIA Driver Version: 555.99
CUDA Toolkit Version: 12.5
Has anyone else experienced similar issues with newer NVIDIA GPUs in MATLAB 2022a? Any insights or suggestions on how to resolve or circumvent this error with the RTX 4080 Super would be greatly appreciated.
Thank you!Hello,
I’m encountering a problem when running a CUDA-based C MEX function in MATLAB 2022a on a machine equipped with an RTX 4080 Super GPU. The specific error occurs when executing the line:
cusolverStatus_t status = cusolverDnCreate(&handle);
Here are the details:
The MEX function compiles successfully using the mexcuda command.
The same code operates correctly on this machine when using an RTX 2080Ti GPU with exactly the same software setup.
When the RTX 4080 Super is used, this error appears, even though the function runs without issues in Visual Studio, indicating that CUDA (Version 12.5) is properly configured on my system.
Upgrading to MATLAB 2024a resolves the issue, suggesting a compatibility problem with MATLAB 2022a. However, I am restricted to using MATLAB 2022a due to dependencies on other external software.
Additional context:
NVIDIA Driver Version: 555.99
CUDA Toolkit Version: 12.5
Has anyone else experienced similar issues with newer NVIDIA GPUs in MATLAB 2022a? Any insights or suggestions on how to resolve or circumvent this error with the RTX 4080 Super would be greatly appreciated.
Thank you! Hello,
I’m encountering a problem when running a CUDA-based C MEX function in MATLAB 2022a on a machine equipped with an RTX 4080 Super GPU. The specific error occurs when executing the line:
cusolverStatus_t status = cusolverDnCreate(&handle);
Here are the details:
The MEX function compiles successfully using the mexcuda command.
The same code operates correctly on this machine when using an RTX 2080Ti GPU with exactly the same software setup.
When the RTX 4080 Super is used, this error appears, even though the function runs without issues in Visual Studio, indicating that CUDA (Version 12.5) is properly configured on my system.
Upgrading to MATLAB 2024a resolves the issue, suggesting a compatibility problem with MATLAB 2022a. However, I am restricted to using MATLAB 2022a due to dependencies on other external software.
Additional context:
NVIDIA Driver Version: 555.99
CUDA Toolkit Version: 12.5
Has anyone else experienced similar issues with newer NVIDIA GPUs in MATLAB 2022a? Any insights or suggestions on how to resolve or circumvent this error with the RTX 4080 Super would be greatly appreciated.
Thank you! mex, mexcuda, cuda, cusolver MATLAB Answers — New Questions