Category: Matlab
Category Archives: Matlab
csv to fft matlab
Hello everybody,
I’m trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
ThanksHello everybody,
I’m trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
Thanks Hello everybody,
I’m trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
Thanks fft, csv MATLAB Answers — New Questions
eval function in for-loop and change of numbers bigger through NaN
I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn’t work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat(‘Temperatur_’,num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution.I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn’t work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat(‘Temperatur_’,num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution. I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn’t work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat(‘Temperatur_’,num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution. eval, dynamic variable MATLAB Answers — New Questions
How to use FFT in matlab using imported data in time domain excel file
I have used a multimeter to measure my phototransistor
and I got one excel file with time versus Magnitude.
But I got some noise, so I want to use Matlab to do FFT
from time domain to frequency domain(frequency versus magnitude) called Photorespone.
I attach my file as below.
I wanna make this kind of figure, freq versus amplitude.
<</matlabcentral/answers/uploaded_files/71667/17160838_1646141328735588_1887025192_n.png>>I have used a multimeter to measure my phototransistor
and I got one excel file with time versus Magnitude.
But I got some noise, so I want to use Matlab to do FFT
from time domain to frequency domain(frequency versus magnitude) called Photorespone.
I attach my file as below.
I wanna make this kind of figure, freq versus amplitude.
<</matlabcentral/answers/uploaded_files/71667/17160838_1646141328735588_1887025192_n.png>> I have used a multimeter to measure my phototransistor
and I got one excel file with time versus Magnitude.
But I got some noise, so I want to use Matlab to do FFT
from time domain to frequency domain(frequency versus magnitude) called Photorespone.
I attach my file as below.
I wanna make this kind of figure, freq versus amplitude.
<</matlabcentral/answers/uploaded_files/71667/17160838_1646141328735588_1887025192_n.png>> fft MATLAB Answers — New Questions
Even & Odd Discrete time Signals
I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so ‘x(-n)’ is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Original Signal’);
subplot(312);stem(n,xe);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Even Signal’);
subplot(313);stem(n,xo);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Odd Signal’);I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so ‘x(-n)’ is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Original Signal’);
subplot(312);stem(n,xe);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Even Signal’);
subplot(313);stem(n,xo);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Odd Signal’); I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so ‘x(-n)’ is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Original Signal’);
subplot(312);stem(n,xe);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Even Signal’);
subplot(313);stem(n,xo);grid on; xlabel(‘n’);ylabel(‘Amplitude’);title(‘Odd Signal’); dicrete_time_signal MATLAB Answers — New Questions
Proving one function is greater than other?
I want to see where is this inequality true
[
frac{log(log(x))}{21.233 log(x)} > frac{1}{53.989 (log(x)^{2/3})(log(log(x))^{1/3})}
]
where x in (e^e,∞).I want to see where is this inequality true
[
frac{log(log(x))}{21.233 log(x)} > frac{1}{53.989 (log(x)^{2/3})(log(log(x))^{1/3})}
]
where x in (e^e,∞). I want to see where is this inequality true
[
frac{log(log(x))}{21.233 log(x)} > frac{1}{53.989 (log(x)^{2/3})(log(log(x))^{1/3})}
]
where x in (e^e,∞). staff MATLAB Answers — New Questions
How to remove fluctuations caused by transfer function?
As most of the sensor have some or other kind of time delay, in my model I have used a temperature sensor the signal provided by the sensor is going through a transfer function just to replicate its true nature (i.e thermal inertia). As the sensor data is being used in a feed back loop. The senor with a transfer function is causing eratic behaviour of my whole model. Because when the setpoint is high enough the sensor reading are all over the place. What should I do?As most of the sensor have some or other kind of time delay, in my model I have used a temperature sensor the signal provided by the sensor is going through a transfer function just to replicate its true nature (i.e thermal inertia). As the sensor data is being used in a feed back loop. The senor with a transfer function is causing eratic behaviour of my whole model. Because when the setpoint is high enough the sensor reading are all over the place. What should I do? As most of the sensor have some or other kind of time delay, in my model I have used a temperature sensor the signal provided by the sensor is going through a transfer function just to replicate its true nature (i.e thermal inertia). As the sensor data is being used in a feed back loop. The senor with a transfer function is causing eratic behaviour of my whole model. Because when the setpoint is high enough the sensor reading are all over the place. What should I do? transfer function, steady state error MATLAB Answers — New Questions
GARCH(1,1): Matrix from standardized residuals do not have exact 1’s on the diagonal
Hello,
I am trying to estimate a GARCH(1,1), get the standardized residuals and form a matrix from them. My R_bar does not have exact 1’s on the diagonal even though they are very close to 1 (for example, 0.9983, 0.9997, 1.023…). Specifically I trying to do this:
data = parquetread(‘/datacommons/dfe/cov/close_to_close_2010-2014.parquet’);
returns = data{:, 2:end};
numAssets = size(returns, 2);
%returns look like this:
%header stock_1 stock_2 …
%date1 return_1 of stock 1 return_1 of stock 2
%date2 return_2 of stock 1 return_2 of stock 2
%…
%returns are not demeaned
mdl = cell(numAssets, 1);
estMdl = cell(numAssets, 1);
condVar = cell(numAssets, 1);
standardizedResiduals = cell(numAssets, 1);
residuals = cell(numAssets, 1);
for i = 1:numAssets
mdl{i} = garch(‘Offset’, NaN, ‘GARCHLags’, 1, ‘ARCHLags’, 1); %I did not demean the returns so I let the model estimate the "offset" parameter
estMdl{i} = estimate(mdl{i}, returns(:, i), ‘Display’, ‘off’);
condVar{i} = infer(estMdl{i}, returns(:, i));
residuals{i} = (returns(:, i) – estMdl{i}.Offset) ;
standardizedResiduals{i} = (returns(:, i) – estMdl{i}.Offset) ./ sqrt(condVar{i}); %Step4 from: https://www.mathworks.com/help/econ/infer-conditional-variances.html
end
% concat into a matrix of TxN where T is the number of time periods and N
% is the number of stocks
standardizedResidualsMat = zeros(T, numAssets);
for i = 1:numAssets
standardizedResidualsMat(:, i) = standardizedResiduals{i};
end
R_bar = zeros(numAssets, numAssets);
for t = 1:T
R_bar = R_bar + (standardizedResidualsMat(t, :)’ * standardizedResidualsMat(t, :));
end
R_bar = R_bar / T;Hello,
I am trying to estimate a GARCH(1,1), get the standardized residuals and form a matrix from them. My R_bar does not have exact 1’s on the diagonal even though they are very close to 1 (for example, 0.9983, 0.9997, 1.023…). Specifically I trying to do this:
data = parquetread(‘/datacommons/dfe/cov/close_to_close_2010-2014.parquet’);
returns = data{:, 2:end};
numAssets = size(returns, 2);
%returns look like this:
%header stock_1 stock_2 …
%date1 return_1 of stock 1 return_1 of stock 2
%date2 return_2 of stock 1 return_2 of stock 2
%…
%returns are not demeaned
mdl = cell(numAssets, 1);
estMdl = cell(numAssets, 1);
condVar = cell(numAssets, 1);
standardizedResiduals = cell(numAssets, 1);
residuals = cell(numAssets, 1);
for i = 1:numAssets
mdl{i} = garch(‘Offset’, NaN, ‘GARCHLags’, 1, ‘ARCHLags’, 1); %I did not demean the returns so I let the model estimate the "offset" parameter
estMdl{i} = estimate(mdl{i}, returns(:, i), ‘Display’, ‘off’);
condVar{i} = infer(estMdl{i}, returns(:, i));
residuals{i} = (returns(:, i) – estMdl{i}.Offset) ;
standardizedResiduals{i} = (returns(:, i) – estMdl{i}.Offset) ./ sqrt(condVar{i}); %Step4 from: https://www.mathworks.com/help/econ/infer-conditional-variances.html
end
% concat into a matrix of TxN where T is the number of time periods and N
% is the number of stocks
standardizedResidualsMat = zeros(T, numAssets);
for i = 1:numAssets
standardizedResidualsMat(:, i) = standardizedResiduals{i};
end
R_bar = zeros(numAssets, numAssets);
for t = 1:T
R_bar = R_bar + (standardizedResidualsMat(t, :)’ * standardizedResidualsMat(t, :));
end
R_bar = R_bar / T; Hello,
I am trying to estimate a GARCH(1,1), get the standardized residuals and form a matrix from them. My R_bar does not have exact 1’s on the diagonal even though they are very close to 1 (for example, 0.9983, 0.9997, 1.023…). Specifically I trying to do this:
data = parquetread(‘/datacommons/dfe/cov/close_to_close_2010-2014.parquet’);
returns = data{:, 2:end};
numAssets = size(returns, 2);
%returns look like this:
%header stock_1 stock_2 …
%date1 return_1 of stock 1 return_1 of stock 2
%date2 return_2 of stock 1 return_2 of stock 2
%…
%returns are not demeaned
mdl = cell(numAssets, 1);
estMdl = cell(numAssets, 1);
condVar = cell(numAssets, 1);
standardizedResiduals = cell(numAssets, 1);
residuals = cell(numAssets, 1);
for i = 1:numAssets
mdl{i} = garch(‘Offset’, NaN, ‘GARCHLags’, 1, ‘ARCHLags’, 1); %I did not demean the returns so I let the model estimate the "offset" parameter
estMdl{i} = estimate(mdl{i}, returns(:, i), ‘Display’, ‘off’);
condVar{i} = infer(estMdl{i}, returns(:, i));
residuals{i} = (returns(:, i) – estMdl{i}.Offset) ;
standardizedResiduals{i} = (returns(:, i) – estMdl{i}.Offset) ./ sqrt(condVar{i}); %Step4 from: https://www.mathworks.com/help/econ/infer-conditional-variances.html
end
% concat into a matrix of TxN where T is the number of time periods and N
% is the number of stocks
standardizedResidualsMat = zeros(T, numAssets);
for i = 1:numAssets
standardizedResidualsMat(:, i) = standardizedResiduals{i};
end
R_bar = zeros(numAssets, numAssets);
for t = 1:T
R_bar = R_bar + (standardizedResidualsMat(t, :)’ * standardizedResidualsMat(t, :));
end
R_bar = R_bar / T; garch, econometrics toolbox MATLAB Answers — New Questions
SENSITIVITY ANALYSIS OF A SYSTEM OF AN ODE USING NORMALIZED SENSITIVITY FUNCTION
I want to perform the sensitivity analysis on the parameters of an ODE SIR model using normalized sensitivity function. I used the following code below. When it was run, I got this error: "undefined functionnor variable ‘p’, error in epidemic1 line8, F=ode45(@epidemic,ic,p)". How can I resolve it to get the plots?
My interest is to get the figure (3) i.e. The plot of nomalized sensitivity functions against time
function epidemic1()
clc
beta=0.4; gamma=0.04;
p1 = [beta gamma];
ic = [995;5;0];
F = ode45(@epidemic,ic,p);
sol1 = solve(F,0,80)
figure(1)
plot(sol1.Time,sol1.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’$beta=0.4$, $gamma=0.04$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
Figure(2)
p2 = [0.2 0.1];
F.Parameters = p2;
F.Sensitivity = odeSensitivity;
sol2 = solve(F,0,80)
plot(sol2.Time,sol2.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
U11 = squeeze(sol2.Sensitivity(1,1,:))’.*(p2(1)./sol2.Solution(1,:));
U12 = squeeze(sol2.Sensitivity(1,2,:))’.*(p2(2)./sol2.Solution(1,:));
U21 = squeeze(sol2.Sensitivity(2,1,:))’.*(p2(1)./sol2.Solution(2,:));
U22 = squeeze(sol2.Sensitivity(2,2,:))’.*(p2(2)./sol2.Solution(2,:));
U31 = squeeze(sol2.Sensitivity(3,1,:))’.*(p2(1)./sol2.Solution(3,:));
U32 = squeeze(sol2.Sensitivity(3,2,:))’.*(p2(2)./sol2.Solution(3,:));
Figure(3)
t = tiledlayout(3,2);
title(t,[‘Parameter Sensitivity by Equation’,’$beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(t,’Time’,’Interpreter’,’latex’)
ylabel(t,’% Change in Eqn’,’Interpreter’,’latex’)
nexttile
plot(sol2.Time,U11)
title(‘$beta$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U12)
title(‘$gamma$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U21)
title(‘$beta$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U22)
title(‘$gamma$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U31)
title(‘$beta$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U32)
title(‘$gamma$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
function dydt = epidemic(t,y,p)
dydt = [0;0;0];
S = y(1);
I = y(2);
R = y(3);
N = S + I + R;
dSdt = -beta*(I*S)/N;
dIdt = beta*(I*S)/N – gamma*I;
dRdt = gamma*I;
end
endI want to perform the sensitivity analysis on the parameters of an ODE SIR model using normalized sensitivity function. I used the following code below. When it was run, I got this error: "undefined functionnor variable ‘p’, error in epidemic1 line8, F=ode45(@epidemic,ic,p)". How can I resolve it to get the plots?
My interest is to get the figure (3) i.e. The plot of nomalized sensitivity functions against time
function epidemic1()
clc
beta=0.4; gamma=0.04;
p1 = [beta gamma];
ic = [995;5;0];
F = ode45(@epidemic,ic,p);
sol1 = solve(F,0,80)
figure(1)
plot(sol1.Time,sol1.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’$beta=0.4$, $gamma=0.04$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
Figure(2)
p2 = [0.2 0.1];
F.Parameters = p2;
F.Sensitivity = odeSensitivity;
sol2 = solve(F,0,80)
plot(sol2.Time,sol2.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
U11 = squeeze(sol2.Sensitivity(1,1,:))’.*(p2(1)./sol2.Solution(1,:));
U12 = squeeze(sol2.Sensitivity(1,2,:))’.*(p2(2)./sol2.Solution(1,:));
U21 = squeeze(sol2.Sensitivity(2,1,:))’.*(p2(1)./sol2.Solution(2,:));
U22 = squeeze(sol2.Sensitivity(2,2,:))’.*(p2(2)./sol2.Solution(2,:));
U31 = squeeze(sol2.Sensitivity(3,1,:))’.*(p2(1)./sol2.Solution(3,:));
U32 = squeeze(sol2.Sensitivity(3,2,:))’.*(p2(2)./sol2.Solution(3,:));
Figure(3)
t = tiledlayout(3,2);
title(t,[‘Parameter Sensitivity by Equation’,’$beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(t,’Time’,’Interpreter’,’latex’)
ylabel(t,’% Change in Eqn’,’Interpreter’,’latex’)
nexttile
plot(sol2.Time,U11)
title(‘$beta$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U12)
title(‘$gamma$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U21)
title(‘$beta$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U22)
title(‘$gamma$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U31)
title(‘$beta$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U32)
title(‘$gamma$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
function dydt = epidemic(t,y,p)
dydt = [0;0;0];
S = y(1);
I = y(2);
R = y(3);
N = S + I + R;
dSdt = -beta*(I*S)/N;
dIdt = beta*(I*S)/N – gamma*I;
dRdt = gamma*I;
end
end I want to perform the sensitivity analysis on the parameters of an ODE SIR model using normalized sensitivity function. I used the following code below. When it was run, I got this error: "undefined functionnor variable ‘p’, error in epidemic1 line8, F=ode45(@epidemic,ic,p)". How can I resolve it to get the plots?
My interest is to get the figure (3) i.e. The plot of nomalized sensitivity functions against time
function epidemic1()
clc
beta=0.4; gamma=0.04;
p1 = [beta gamma];
ic = [995;5;0];
F = ode45(@epidemic,ic,p);
sol1 = solve(F,0,80)
figure(1)
plot(sol1.Time,sol1.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’$beta=0.4$, $gamma=0.04$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
Figure(2)
p2 = [0.2 0.1];
F.Parameters = p2;
F.Sensitivity = odeSensitivity;
sol2 = solve(F,0,80)
plot(sol2.Time,sol2.Solution,’-o’)
legend(‘S’,’I’,’R’)
title([‘SIR Populations over Time’,’beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(‘Time’,’Interpreter’,’latex’)
ylabel(‘Population’,’Interpreter’,’latex’)
U11 = squeeze(sol2.Sensitivity(1,1,:))’.*(p2(1)./sol2.Solution(1,:));
U12 = squeeze(sol2.Sensitivity(1,2,:))’.*(p2(2)./sol2.Solution(1,:));
U21 = squeeze(sol2.Sensitivity(2,1,:))’.*(p2(1)./sol2.Solution(2,:));
U22 = squeeze(sol2.Sensitivity(2,2,:))’.*(p2(2)./sol2.Solution(2,:));
U31 = squeeze(sol2.Sensitivity(3,1,:))’.*(p2(1)./sol2.Solution(3,:));
U32 = squeeze(sol2.Sensitivity(3,2,:))’.*(p2(2)./sol2.Solution(3,:));
Figure(3)
t = tiledlayout(3,2);
title(t,[‘Parameter Sensitivity by Equation’,’$beta=0.2$, $gamma=0.1$’],’Interpreter’,’latex’)
xlabel(t,’Time’,’Interpreter’,’latex’)
ylabel(t,’% Change in Eqn’,’Interpreter’,’latex’)
nexttile
plot(sol2.Time,U11)
title(‘$beta$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U12)
title(‘$gamma$, Eqn. 1′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U21)
title(‘$beta$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U22)
title(‘$gamma$, Eqn. 2′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U31)
title(‘$beta$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
nexttile
plot(sol2.Time,U32)
title(‘$gamma$, Eqn. 3′,’Interpreter’,’latex’)
ylim([-5 5])
function dydt = epidemic(t,y,p)
dydt = [0;0;0];
S = y(1);
I = y(2);
R = y(3);
N = S + I + R;
dSdt = -beta*(I*S)/N;
dIdt = beta*(I*S)/N – gamma*I;
dRdt = gamma*I;
end
end sensisitivity analysis, ode, normalized sensitivity MATLAB Answers — New Questions
design and model hybrid renewable energy sources of wind,solar & battery using fuzzy lojic
to do hybrid power sytem based on renewable ernergy sources for rural areas/offgrid communityto do hybrid power sytem based on renewable ernergy sources for rural areas/offgrid community to do hybrid power sytem based on renewable ernergy sources for rural areas/offgrid community fuzzy lojic MATLAB Answers — New Questions
How do I find the index of a datapointon a MATLAB plot?
With a very large dataset – assume 1 million [x,y] pairs or more – how do I find the *index of an individual datapoint* on a MATLAB plot?
Example: I use plot(x,y) and the plot appears. The plot is complicated but there are artifacts I can locate by eye much easier than writing a detection script. I zoom into the plot and locate the desired data artifact. I need to know the exact location (index) of the artifact. I zoom that individual datapoints are apparent, place a cursor on the datapoint of interest, but the cursor does not report the exact x(index) of the datapoint. Other than manually scrubbing through the data to find the index, how do I find the index by using the plot?With a very large dataset – assume 1 million [x,y] pairs or more – how do I find the *index of an individual datapoint* on a MATLAB plot?
Example: I use plot(x,y) and the plot appears. The plot is complicated but there are artifacts I can locate by eye much easier than writing a detection script. I zoom into the plot and locate the desired data artifact. I need to know the exact location (index) of the artifact. I zoom that individual datapoints are apparent, place a cursor on the datapoint of interest, but the cursor does not report the exact x(index) of the datapoint. Other than manually scrubbing through the data to find the index, how do I find the index by using the plot? With a very large dataset – assume 1 million [x,y] pairs or more – how do I find the *index of an individual datapoint* on a MATLAB plot?
Example: I use plot(x,y) and the plot appears. The plot is complicated but there are artifacts I can locate by eye much easier than writing a detection script. I zoom into the plot and locate the desired data artifact. I need to know the exact location (index) of the artifact. I zoom that individual datapoints are apparent, place a cursor on the datapoint of interest, but the cursor does not report the exact x(index) of the datapoint. Other than manually scrubbing through the data to find the index, how do I find the index by using the plot? plot MATLAB Answers — New Questions
How does ANSYS convert the strain of nodes at the element level to the strains of nodes for the entire model (especially for the middle points)?
Dear forum members,
I am currently working on developing finite element analysis (FEA) code in MATLAB, where I’m utilizing quadratic tetrahedral elements. For this purpose, I have exported the necessary values and matrices from ANSYS. After calculating the strain for each element, I proceeded to average the values for overlapping nodes at the element level. This approach seems to work well for the corner nodes of each element; however, I encounter inconsistencies when it comes to middle points. In some cases, even when the nodes are not duplicated, the values vary.
Could anyone provide insight into why such discrepancies may occur? Your expertise and advice would be greatly appreciated as I navigate through this issue.
Thank you for your time and assistance.Dear forum members,
I am currently working on developing finite element analysis (FEA) code in MATLAB, where I’m utilizing quadratic tetrahedral elements. For this purpose, I have exported the necessary values and matrices from ANSYS. After calculating the strain for each element, I proceeded to average the values for overlapping nodes at the element level. This approach seems to work well for the corner nodes of each element; however, I encounter inconsistencies when it comes to middle points. In some cases, even when the nodes are not duplicated, the values vary.
Could anyone provide insight into why such discrepancies may occur? Your expertise and advice would be greatly appreciated as I navigate through this issue.
Thank you for your time and assistance. Dear forum members,
I am currently working on developing finite element analysis (FEA) code in MATLAB, where I’m utilizing quadratic tetrahedral elements. For this purpose, I have exported the necessary values and matrices from ANSYS. After calculating the strain for each element, I proceeded to average the values for overlapping nodes at the element level. This approach seems to work well for the corner nodes of each element; however, I encounter inconsistencies when it comes to middle points. In some cases, even when the nodes are not duplicated, the values vary.
Could anyone provide insight into why such discrepancies may occur? Your expertise and advice would be greatly appreciated as I navigate through this issue.
Thank you for your time and assistance. fea, finiteelementmethod, strain, element MATLAB Answers — New Questions
Sum of a signal in simulink
In my Simulink model, current value of a signal should be added to all previous value of the same signal. I’ve used integrator with initial value of zero to find it; however the result is different from what I find in Matlab through "sum" or "trapz" function.
The solver is continuous with fixed step size.
Any thought to resolve this issue. or any other block to use for this purpose instead of integrator?In my Simulink model, current value of a signal should be added to all previous value of the same signal. I’ve used integrator with initial value of zero to find it; however the result is different from what I find in Matlab through "sum" or "trapz" function.
The solver is continuous with fixed step size.
Any thought to resolve this issue. or any other block to use for this purpose instead of integrator? In my Simulink model, current value of a signal should be added to all previous value of the same signal. I’ve used integrator with initial value of zero to find it; however the result is different from what I find in Matlab through "sum" or "trapz" function.
The solver is continuous with fixed step size.
Any thought to resolve this issue. or any other block to use for this purpose instead of integrator? sum simulink MATLAB Answers — New Questions
Wait until object is rendered in App Designer
Hello together,
I’m using the loading screen as desribed here, while my data is loaded.
The loading screen is closed, when the last function has finished. But no objects are rendered at this moment.
I’m creating a lot of buttons and edit fields programatically. But they are rendered very late, after the functions are already finished.
How to wait with closing the loading screen, until everything is rendered (or nearly at least)?
Thanks in advance!
ChristofHello together,
I’m using the loading screen as desribed here, while my data is loaded.
The loading screen is closed, when the last function has finished. But no objects are rendered at this moment.
I’m creating a lot of buttons and edit fields programatically. But they are rendered very late, after the functions are already finished.
How to wait with closing the loading screen, until everything is rendered (or nearly at least)?
Thanks in advance!
Christof Hello together,
I’m using the loading screen as desribed here, while my data is loaded.
The loading screen is closed, when the last function has finished. But no objects are rendered at this moment.
I’m creating a lot of buttons and edit fields programatically. But they are rendered very late, after the functions are already finished.
How to wait with closing the loading screen, until everything is rendered (or nearly at least)?
Thanks in advance!
Christof rendering, app designer, wait for MATLAB Answers — New Questions
How to obtain additional test result in neural network fitting app by using code?
Hi,
I am using the neural network fitting app in MATLAB 2024a version.
I used the code to develop the neural network by adding a hidden layer.
When I use this code, it shows the results for training, but I can’t get the results for the additional test set as shown in the neural network fitting app.
How can I get it? (e.g. the name of additional test input is "inputtest" and that of additional test output(target) is "outputtes")
I wrote my code below.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 09-Jun-2024 21:04:21
%
% This script assumes these variables are defined:
%
% bodyfatInputs – input data.
% bodyfatTargets – target data.
x = bodyfatInputs;
t = bodyfatTargets;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayer1Size = 10;
hiddenLayer2Size = 10;
net = fitnet([hiddenLayer1Size, hiddenLayer2Size],trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)Hi,
I am using the neural network fitting app in MATLAB 2024a version.
I used the code to develop the neural network by adding a hidden layer.
When I use this code, it shows the results for training, but I can’t get the results for the additional test set as shown in the neural network fitting app.
How can I get it? (e.g. the name of additional test input is "inputtest" and that of additional test output(target) is "outputtes")
I wrote my code below.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 09-Jun-2024 21:04:21
%
% This script assumes these variables are defined:
%
% bodyfatInputs – input data.
% bodyfatTargets – target data.
x = bodyfatInputs;
t = bodyfatTargets;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayer1Size = 10;
hiddenLayer2Size = 10;
net = fitnet([hiddenLayer1Size, hiddenLayer2Size],trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t) Hi,
I am using the neural network fitting app in MATLAB 2024a version.
I used the code to develop the neural network by adding a hidden layer.
When I use this code, it shows the results for training, but I can’t get the results for the additional test set as shown in the neural network fitting app.
How can I get it? (e.g. the name of additional test input is "inputtest" and that of additional test output(target) is "outputtes")
I wrote my code below.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 09-Jun-2024 21:04:21
%
% This script assumes these variables are defined:
%
% bodyfatInputs – input data.
% bodyfatTargets – target data.
x = bodyfatInputs;
t = bodyfatTargets;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayer1Size = 10;
hiddenLayer2Size = 10;
net = fitnet([hiddenLayer1Size, hiddenLayer2Size],trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t) neural network, neural networks fitting MATLAB Answers — New Questions
MATLAB editor configuration text extremely small
The font size of my editor is extremely small so I increased it to 48, but then the find bar remains at 13,
I have also tried to keep the font at its regular 13 and scroll to zoom in but since the right-hand limit is half the page, every time I use the find bar the page jumps to the extreme right where there is no text.
This is 2023 b. I have used MATLAB for more than ten years and this has never happened before.The font size of my editor is extremely small so I increased it to 48, but then the find bar remains at 13,
I have also tried to keep the font at its regular 13 and scroll to zoom in but since the right-hand limit is half the page, every time I use the find bar the page jumps to the extreme right where there is no text.
This is 2023 b. I have used MATLAB for more than ten years and this has never happened before. The font size of my editor is extremely small so I increased it to 48, but then the find bar remains at 13,
I have also tried to keep the font at its regular 13 and scroll to zoom in but since the right-hand limit is half the page, every time I use the find bar the page jumps to the extreme right where there is no text.
This is 2023 b. I have used MATLAB for more than ten years and this has never happened before. display MATLAB Answers — New Questions
Segment Anything Model without foreground points or bounding box
Hi,
I’m using the new R2024a "Segment Anything" model with good results.
However, it seems like the original Segment Anything Model by Meta has also the ‘everything’ option, where it somehow segments all the objects in the image with no user input.
Is there a way to use the Matlab version for a similar result? Just specifying a grid of ‘foreground points’ does not help, as the Matlab function considers them all to belong to the same object.
thanks in advanceHi,
I’m using the new R2024a "Segment Anything" model with good results.
However, it seems like the original Segment Anything Model by Meta has also the ‘everything’ option, where it somehow segments all the objects in the image with no user input.
Is there a way to use the Matlab version for a similar result? Just specifying a grid of ‘foreground points’ does not help, as the Matlab function considers them all to belong to the same object.
thanks in advance Hi,
I’m using the new R2024a "Segment Anything" model with good results.
However, it seems like the original Segment Anything Model by Meta has also the ‘everything’ option, where it somehow segments all the objects in the image with no user input.
Is there a way to use the Matlab version for a similar result? Just specifying a grid of ‘foreground points’ does not help, as the Matlab function considers them all to belong to the same object.
thanks in advance image segmentation, deep learning, r2024a MATLAB Answers — New Questions
How to split/segment csv file into multiple sections?
I have a file (called test_file.csv on my PC) that I want to split into several sections (I attached it as a .mat file here).
For this, I want to use the information in the second to last column "IsTransitioning". There are several instances where the cells in "IsTransitioning" equal "TRUE" in multiple consecutive rows. After those rows, there are multiple consecutive rows with "FALSE". I would like to save all the sections (the entire rows with all other columns) of consecutive rows with "FALSE" in a cell array where each cell contains the one section of consecutive rows.
Ideally, I wouldnt load the csv as a table and refer to the column numbers rather than the column names if that makes sense.
How could I do this if I dont know the number of times these sections occur?I have a file (called test_file.csv on my PC) that I want to split into several sections (I attached it as a .mat file here).
For this, I want to use the information in the second to last column "IsTransitioning". There are several instances where the cells in "IsTransitioning" equal "TRUE" in multiple consecutive rows. After those rows, there are multiple consecutive rows with "FALSE". I would like to save all the sections (the entire rows with all other columns) of consecutive rows with "FALSE" in a cell array where each cell contains the one section of consecutive rows.
Ideally, I wouldnt load the csv as a table and refer to the column numbers rather than the column names if that makes sense.
How could I do this if I dont know the number of times these sections occur? I have a file (called test_file.csv on my PC) that I want to split into several sections (I attached it as a .mat file here).
For this, I want to use the information in the second to last column "IsTransitioning". There are several instances where the cells in "IsTransitioning" equal "TRUE" in multiple consecutive rows. After those rows, there are multiple consecutive rows with "FALSE". I would like to save all the sections (the entire rows with all other columns) of consecutive rows with "FALSE" in a cell array where each cell contains the one section of consecutive rows.
Ideally, I wouldnt load the csv as a table and refer to the column numbers rather than the column names if that makes sense.
How could I do this if I dont know the number of times these sections occur? segment, section, split, save rows, split along rows MATLAB Answers — New Questions
Using the Potential Field algorithm in an occupancy map environment
Hello everyone,
So far I have dealt with the RRT* algorithm that received a map (a binary matrix that I turned into a map) and the initial and final position of the robot.
Now I want to use the Potential Field algorithm and put in it a start and end position and in addition the robot’s environment (the map)
How can i do it? does not succeed.
This is the code for the RRT*
clc; clear;close
% Load the original 25×25 matrix
original_matrix = dlmread("C:UsersuserDesktopmap.txt", ‘t’);
% Scale and increase dimensions to 50×50
scaled_matrix = imresize(original_matrix, [50, 50], ‘nearest’);
a=occupancyMap(scaled_matrix);
inflatedmap=copy(a);
inflate(inflatedmap,10^-1)
startPose = getRandomPose(inflatedmap);
goalPose = getRandomPose(inflatedmap);
[path,treeData] = codegenRRTStar1(inflatedmap,startPose,goalPose);
I want all the black positions the positions where there is a 1 in the matrix to be the obstacles
Attached is a link to the implementation of the desired algorithm in Matlab
https://www.mathworks.com/matlabcentral/fileexchange/126455-artificial-potential-field-path-planning-algorithm
Many thanks to all the helpers
*The positions are absolute in space and do not specify a row/column in the matrix.Hello everyone,
So far I have dealt with the RRT* algorithm that received a map (a binary matrix that I turned into a map) and the initial and final position of the robot.
Now I want to use the Potential Field algorithm and put in it a start and end position and in addition the robot’s environment (the map)
How can i do it? does not succeed.
This is the code for the RRT*
clc; clear;close
% Load the original 25×25 matrix
original_matrix = dlmread("C:UsersuserDesktopmap.txt", ‘t’);
% Scale and increase dimensions to 50×50
scaled_matrix = imresize(original_matrix, [50, 50], ‘nearest’);
a=occupancyMap(scaled_matrix);
inflatedmap=copy(a);
inflate(inflatedmap,10^-1)
startPose = getRandomPose(inflatedmap);
goalPose = getRandomPose(inflatedmap);
[path,treeData] = codegenRRTStar1(inflatedmap,startPose,goalPose);
I want all the black positions the positions where there is a 1 in the matrix to be the obstacles
Attached is a link to the implementation of the desired algorithm in Matlab
https://www.mathworks.com/matlabcentral/fileexchange/126455-artificial-potential-field-path-planning-algorithm
Many thanks to all the helpers
*The positions are absolute in space and do not specify a row/column in the matrix. Hello everyone,
So far I have dealt with the RRT* algorithm that received a map (a binary matrix that I turned into a map) and the initial and final position of the robot.
Now I want to use the Potential Field algorithm and put in it a start and end position and in addition the robot’s environment (the map)
How can i do it? does not succeed.
This is the code for the RRT*
clc; clear;close
% Load the original 25×25 matrix
original_matrix = dlmread("C:UsersuserDesktopmap.txt", ‘t’);
% Scale and increase dimensions to 50×50
scaled_matrix = imresize(original_matrix, [50, 50], ‘nearest’);
a=occupancyMap(scaled_matrix);
inflatedmap=copy(a);
inflate(inflatedmap,10^-1)
startPose = getRandomPose(inflatedmap);
goalPose = getRandomPose(inflatedmap);
[path,treeData] = codegenRRTStar1(inflatedmap,startPose,goalPose);
I want all the black positions the positions where there is a 1 in the matrix to be the obstacles
Attached is a link to the implementation of the desired algorithm in Matlab
https://www.mathworks.com/matlabcentral/fileexchange/126455-artificial-potential-field-path-planning-algorithm
Many thanks to all the helpers
*The positions are absolute in space and do not specify a row/column in the matrix. maze, map, occupancymap, potential field algorithm MATLAB Answers — New Questions
search text of matlab scripts in MATLAB mobile
I’m using matlab mobile on ipad and l would like to know if it’s possible to search the text of long matlab scripts. Also it would be helpful for variables to be highlighted when the cursor is in the name of the variable. Makes it a lot easier to troubleshoot. I don’t see these features in MATLAB mobile currently.I’m using matlab mobile on ipad and l would like to know if it’s possible to search the text of long matlab scripts. Also it would be helpful for variables to be highlighted when the cursor is in the name of the variable. Makes it a lot easier to troubleshoot. I don’t see these features in MATLAB mobile currently. I’m using matlab mobile on ipad and l would like to know if it’s possible to search the text of long matlab scripts. Also it would be helpful for variables to be highlighted when the cursor is in the name of the variable. Makes it a lot easier to troubleshoot. I don’t see these features in MATLAB mobile currently. mobile, ipad, search text, highlight variables MATLAB Answers — New Questions
Error: Function definitions are not supported in this context. Functions can only be created as local or nested functions in code files.
function t_a = SecOrdReaction (t0,tf,y,N)
%Решение обыкновенных дифференциальных уравнений для мономолекулярных реакций второго порядка
% t – время, сек; у – количество вещества А, М
% t_a = [0 600]- интервал времени; y = 0,25 – начальное условие;
% k = 0.5 – константа скорости реакции.
% N-число точек для отображения на графике
% Для запуска функции необходимо в командном окне набрать: >> t_a = SecOrdReaction (0,600,0.25,5)
close all %закрыть все ранее построенные графические окна
t = [t0, tf];
[t, y] = ode45(‘ODEfirst’, t0, y);
plot(t, y)
xlabel(‘Время, c’);
ylabel(‘Концентрация вещества A, M’)
title( ‘Решение кинетического уравнения для мономолекулярной реакции второго порядка’)
grid on
t_n = linpack(t0, tf, n);% при решении будет использовано точек интервала времени [ts, tf]
y_n = interp1 (t, y, t_n, ‘spline’);% n значений y точек для отображения
t_A = [t_n’, y_n’];
hold on
plot(t_n,y_n,’*r’)
function dy = ODEfirst(t, y)
dy=-0.5*y2;
[t, y] = ode45 (‘ODEfirst’, [0: 100: 600], 0.25) % t= 0 … 600 сек, шаг=100; y = 0.25
t_a = SecOrdReaction (0,600,0.25,5)function t_a = SecOrdReaction (t0,tf,y,N)
%Решение обыкновенных дифференциальных уравнений для мономолекулярных реакций второго порядка
% t – время, сек; у – количество вещества А, М
% t_a = [0 600]- интервал времени; y = 0,25 – начальное условие;
% k = 0.5 – константа скорости реакции.
% N-число точек для отображения на графике
% Для запуска функции необходимо в командном окне набрать: >> t_a = SecOrdReaction (0,600,0.25,5)
close all %закрыть все ранее построенные графические окна
t = [t0, tf];
[t, y] = ode45(‘ODEfirst’, t0, y);
plot(t, y)
xlabel(‘Время, c’);
ylabel(‘Концентрация вещества A, M’)
title( ‘Решение кинетического уравнения для мономолекулярной реакции второго порядка’)
grid on
t_n = linpack(t0, tf, n);% при решении будет использовано точек интервала времени [ts, tf]
y_n = interp1 (t, y, t_n, ‘spline’);% n значений y точек для отображения
t_A = [t_n’, y_n’];
hold on
plot(t_n,y_n,’*r’)
function dy = ODEfirst(t, y)
dy=-0.5*y2;
[t, y] = ode45 (‘ODEfirst’, [0: 100: 600], 0.25) % t= 0 … 600 сек, шаг=100; y = 0.25
t_a = SecOrdReaction (0,600,0.25,5) function t_a = SecOrdReaction (t0,tf,y,N)
%Решение обыкновенных дифференциальных уравнений для мономолекулярных реакций второго порядка
% t – время, сек; у – количество вещества А, М
% t_a = [0 600]- интервал времени; y = 0,25 – начальное условие;
% k = 0.5 – константа скорости реакции.
% N-число точек для отображения на графике
% Для запуска функции необходимо в командном окне набрать: >> t_a = SecOrdReaction (0,600,0.25,5)
close all %закрыть все ранее построенные графические окна
t = [t0, tf];
[t, y] = ode45(‘ODEfirst’, t0, y);
plot(t, y)
xlabel(‘Время, c’);
ylabel(‘Концентрация вещества A, M’)
title( ‘Решение кинетического уравнения для мономолекулярной реакции второго порядка’)
grid on
t_n = linpack(t0, tf, n);% при решении будет использовано точек интервала времени [ts, tf]
y_n = interp1 (t, y, t_n, ‘spline’);% n значений y точек для отображения
t_A = [t_n’, y_n’];
hold on
plot(t_n,y_n,’*r’)
function dy = ODEfirst(t, y)
dy=-0.5*y2;
[t, y] = ode45 (‘ODEfirst’, [0: 100: 600], 0.25) % t= 0 … 600 сек, шаг=100; y = 0.25
t_a = SecOrdReaction (0,600,0.25,5) matlab MATLAB Answers — New Questions