Category: Matlab
Category Archives: Matlab
Error using newly added wavelet to wavemngr
I am working with a tool in matlab that matches an orthogonal wavelet to a given prototype signal. The attatched image depicts the information stored within the waveletFilter structure generated by the tool.
I would like to add the f/g filters to wavemngr(). I begin by saving f and calling the .mat file by the wavelet short name I plan to use. I then run the following script:
wsname = ‘L1F’;
wname = ‘L1OptimizedFilter’;
eval([wsname ‘=waveletFilterL1.f/sqrt(2);’]);
save(wsname, wsname);
wavemngr(‘add’, wname, wsname, 1, ”, [wsname ‘.mat’]);
When I use wavemngr(‘read’) to validate the addition of my filter, it is there.
However, when I then proceed to access any information regarding the properties, or use the filter with a given transform, I get an error message saying my filter has not been found.I am working with a tool in matlab that matches an orthogonal wavelet to a given prototype signal. The attatched image depicts the information stored within the waveletFilter structure generated by the tool.
I would like to add the f/g filters to wavemngr(). I begin by saving f and calling the .mat file by the wavelet short name I plan to use. I then run the following script:
wsname = ‘L1F’;
wname = ‘L1OptimizedFilter’;
eval([wsname ‘=waveletFilterL1.f/sqrt(2);’]);
save(wsname, wsname);
wavemngr(‘add’, wname, wsname, 1, ”, [wsname ‘.mat’]);
When I use wavemngr(‘read’) to validate the addition of my filter, it is there.
However, when I then proceed to access any information regarding the properties, or use the filter with a given transform, I get an error message saying my filter has not been found. I am working with a tool in matlab that matches an orthogonal wavelet to a given prototype signal. The attatched image depicts the information stored within the waveletFilter structure generated by the tool.
I would like to add the f/g filters to wavemngr(). I begin by saving f and calling the .mat file by the wavelet short name I plan to use. I then run the following script:
wsname = ‘L1F’;
wname = ‘L1OptimizedFilter’;
eval([wsname ‘=waveletFilterL1.f/sqrt(2);’]);
save(wsname, wsname);
wavemngr(‘add’, wname, wsname, 1, ”, [wsname ‘.mat’]);
When I use wavemngr(‘read’) to validate the addition of my filter, it is there.
However, when I then proceed to access any information regarding the properties, or use the filter with a given transform, I get an error message saying my filter has not been found. wavelet, wavemngr, wpdec MATLAB Answers — New Questions
Error using feval Function to evaluate must be represented as a string scalar, character vector, or function_handle object.
% Example5_5.m
% Solution to Example 5.5. This program calculates and plots
% the concentration of cell mass, concentration of penicillin,
% optimal temperature profile, and adjoint variable of a batch
% penicillin fermentor. It uses the function COLLOCATION to
% solve the set of system and adjoint equations.
clear
clc
clf
% Input data
w = input(‘ Enter w”s as a vector : ‘);
y0 = input(‘ Vector of known initial conditions = ‘);
yf = input(‘ Vector of final conditions = ‘);
guess = input(‘ Vector of guessed initial conditions = ‘);
fname = input(‘n M-file containing the set of differential equations : ‘);
fth = input(‘ M-file containing the necessary condition function : ‘);
n = input(‘ Number of internal collocation points = ‘);
rho = input(‘ Relaxation factor = ‘);
% Solution of the set of differential equations
[t,y] = collocation(fname,0,1,y0,yf,guess,n,rho,[],w,fth);
% Temperature changes
for k = 1:n+2
options=optimset;
theta(k) = fzero(fth,30,options,y(:,k),w);
end
% Plotting the results
subplot(2,2,1), plot(t,y(1,:))
xlabel(‘Time’)
ylabel(‘Cell’)
title(‘(a)’)
subplot(2,2,2), plot(t,y(2,:))
xlabel(‘Time’)
ylabel(‘Penicillin’)
title(‘(b)’)
subplot(2,2,3), plot(t,y(3,:))
xlabel(‘Time’)
ylabel(‘First Adjoint’)
title(‘(c)’)
subplot(2,2,4), plot(t,theta)
xlabel(‘Time’)
ylabel(‘Temperature (deg C)’)
title(‘(d)’)
function f = Ex5_5_func(t,y,w,fth)
% Function Ex5_5_func.M
% This function introduces the set of ordinary differential
% equations used in Example 5.5.
% Temperature
options=optimset;
theta = fzero(fth,30,options,y,w);
% Calculating the b’s
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
if b1<0, b1=0; end
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
if b2<0, b2=1e-6; end
b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-w(2)*(25-w(6))^2);
if b3<0, b3=0; end
% Evaluating the function values
f(1) = b1*y(1) – b1/b2*y(1)^2;
f(2) = b3*y(1);
f(3) = -b1*y(3) + 2*b1/b2*y(1)*y(3) – b3;
f = f’; % Make it a column vector
function ftheta = Ex5_5_theta(theta,y,w)
% Function Ex5_5_theta.M
% This function calculates the value of the necessary condition
% as a function of the temperature (theta). It is used in solving
% Example 5.5.
% Calculating the b’s
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
db1 = w(1)*(-w(2))*2*(theta-w(3)) / (1-w(2)*(25-w(3))^2);
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
db2 = w(4)*(-w(2))*2*(theta-w(3)) / (1-w(2)*(25-w(3))^2);
b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-w(2)*(25-w(6))^2);
db3 = w(5)*(-w(2))*2*(theta-w(6)) / (1-w(2)*(25-w(6))^2);
% The function
ftheta = y(3)*(y(1)*db1-y(1)^2*(db1*b2-db2*b1)/b2^2)+y(1)*db3;
function [x,y] = collocation(ODEfile,x0,xf,y0,yf,guess,n,rho,tol,varargin)
%COLLOCATION Solves a boundary value set of ordinary differential
% equations by the orthogonal collocation method.
%
% [X,Y]=COLLOCATION(‘F’,X0,XF,Y0,YF,GAMMA,N) integrates the set of
% ordinary differential equations from X0 to XF by the Nth-degree
% orthogonal collocation method. The equations are contained in
% the M-file F.M. Y0, YF, and GAMMA are the vectors of initial
% conditions, final conditions, and starting guesses respectively.
% The function returns the independent variable in the vector X
% and the set of dependent variables in the matrix Y.
%
% [X,Y]=COLLOCATION(‘F’,X0,XF,Y0,YF,GAMMA,N,RHO,TOL,P1,P2,…)
% uses relaxation factor RHO and tolerance TOL for convergence
% test. Additional parameters P1, P2, … are passed directly to
% the function F. Pass an empty matrix for RHO or TOL to use the
% default value.
%
% See also SHOOTING
% (c) N. Mostoufi & A. Constantinides
% January 1, 1999
% Initialization
if nargin < 7 | isempty(n)
n = 1;
end
if nargin < 8 | isempty(rho)
rho = 1;
end
if nargin < 9 | isempty(tol)
tol = 1e-6;
end
y0 = (y0(:).’)’; % Make sure it’s a column vector
yf = (yf(:).’)’; % Make sure it’s a column vector
guess = (guess(:).’)’; % Make sure it’s a column vector
% Checking the number of guesses
if length(yf) ~= length(guess)
error(‘ The number of guessed conditions is not equal to the number of final conditions.’)
end
r = length(y0); % Number of initial conditions
m = r + length(yf); % Number of boundary conditions
% Checking the number of equations
ftest = feval(ODEfile,x0,[y0 ; guess],varargin{:});
if length(ftest) ~= m
error(‘ The number of equations is not equal to the number of boundary conditions.’)
end
fprintf(‘n Integrating. Please wait.nn’)
% Coefficients of the Legendre polynomial
for k = 0 : n/2
cl(2*k+1) = (-1)^k * gamma(2*n-2*k+1) / …
(2^n * gamma(k+1) * gamma(n-k+1) * gamma(n-2*k+1));
if k < n/2
cl(2*k+2) = 0;
end
end
zl = roots(cl); % Roots of the Legendre polynomial
z = [-1; sort(zl); 1]; % Collocation points (z)
x = (xf-x0)*z/2+(xf+x0)/2; % Collocation points (x)
% Bulding the vector of starting values of the dependent variables
[p,q] = RK(ODEfile,x0,xf,(xf-x0)/20,[y0 ; guess],2,varargin{:});
for k = 1:m
y(k,:) = spline(p,q(k,:),x’);
end
y(r+1:m,end) = yf(1:m-r);
% Building the matrix A
Q(:,1) = ones(n+2,1);
C(:,1) = zeros(n+2,1);
for i = 1:n+1
Q(:,i+1) = x.^i;
C(:,i+1) = i*x.^(i-1);
end
A = C*inv(Q);
for k = 1:m
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
Am(k1:k2,k1:k2) = A; % Building the matrix Am
Y(k1:k2) = y(k,:); % Building the vector Y
end
Y = Y’; % Make it a column vector
Y1 = Y * 1.1;
iter = 0;
maxiter = 100;
F = zeros(m*(n+2),1);
Fa = zeros(m*(n+2),1);
dY = zeros(m*(n+2),1);
position = []; % Collocation points excluding boundary conditions
for k = 1:m
if k <= r
position = [position, (k-1)*(n+2)+[2:n+2] ];
else
position = [position, (k-1)*(n+2)+[1:n+1] ];
end
end
% Newton’s method
while max(abs(Y1 – Y)) > tol & iter < maxiter
iter = iter + 1;
fprintf(‘ Iteration %3dn’,iter)
Y1 = Y;
% Building the vector F
for k = 1:n+2
F(k : n+2 : (m-1)*(n+2)+k) = …
feval(ODEfile,x(k),Y(k : n+2 : (m-1)*(n+2)+k),varargin{:});
end
fnk = Am * Y – F;
% Set dY for derivation
for k = 1:m*(n+1)
if Y(position(k)) ~= 0
dY(position(k)) = Y(position(k)) / 100;
else
dY(position(k)) = 0.01;
end
end
% Calculation of the Jacobian matrix
for k = 1:m
for kk = 1:n+1
a = Y;
nc = (k-1)*(n+1)+kk;
a(position(nc)) = Y(position(nc)) + dY(position(nc));
for kkk = 1:n+2
Fa(kkk : n+2 : (m-1)*(n+2)+kkk) = …
feval(ODEfile,x(kkk),a(kkk:n+2:(m-1)*(n+2)+kkk),varargin{:});
end
fnka = Am * a – Fa;
jacob(:,nc) = (fnka(position) – fnk(position))…
/ dY(position(nc));
end
end
% Next approximation of the roots
if det(jacob) == 0
Y(position) = Y(position) + max([abs(dY(position)); 1.1*tol]);
else
Y(position) = Y(position) – rho * inv(jacob) * fnk(position);
end
end
% Rearranging the y’s
for k = 1:m
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
y(k,:) = Y(k1:k2)’;
end
x = x’;
if iter >= maxiter
disp(‘Warning : Maximum iterations reached.’)
end% Example5_5.m
% Solution to Example 5.5. This program calculates and plots
% the concentration of cell mass, concentration of penicillin,
% optimal temperature profile, and adjoint variable of a batch
% penicillin fermentor. It uses the function COLLOCATION to
% solve the set of system and adjoint equations.
clear
clc
clf
% Input data
w = input(‘ Enter w”s as a vector : ‘);
y0 = input(‘ Vector of known initial conditions = ‘);
yf = input(‘ Vector of final conditions = ‘);
guess = input(‘ Vector of guessed initial conditions = ‘);
fname = input(‘n M-file containing the set of differential equations : ‘);
fth = input(‘ M-file containing the necessary condition function : ‘);
n = input(‘ Number of internal collocation points = ‘);
rho = input(‘ Relaxation factor = ‘);
% Solution of the set of differential equations
[t,y] = collocation(fname,0,1,y0,yf,guess,n,rho,[],w,fth);
% Temperature changes
for k = 1:n+2
options=optimset;
theta(k) = fzero(fth,30,options,y(:,k),w);
end
% Plotting the results
subplot(2,2,1), plot(t,y(1,:))
xlabel(‘Time’)
ylabel(‘Cell’)
title(‘(a)’)
subplot(2,2,2), plot(t,y(2,:))
xlabel(‘Time’)
ylabel(‘Penicillin’)
title(‘(b)’)
subplot(2,2,3), plot(t,y(3,:))
xlabel(‘Time’)
ylabel(‘First Adjoint’)
title(‘(c)’)
subplot(2,2,4), plot(t,theta)
xlabel(‘Time’)
ylabel(‘Temperature (deg C)’)
title(‘(d)’)
function f = Ex5_5_func(t,y,w,fth)
% Function Ex5_5_func.M
% This function introduces the set of ordinary differential
% equations used in Example 5.5.
% Temperature
options=optimset;
theta = fzero(fth,30,options,y,w);
% Calculating the b’s
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
if b1<0, b1=0; end
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
if b2<0, b2=1e-6; end
b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-w(2)*(25-w(6))^2);
if b3<0, b3=0; end
% Evaluating the function values
f(1) = b1*y(1) – b1/b2*y(1)^2;
f(2) = b3*y(1);
f(3) = -b1*y(3) + 2*b1/b2*y(1)*y(3) – b3;
f = f’; % Make it a column vector
function ftheta = Ex5_5_theta(theta,y,w)
% Function Ex5_5_theta.M
% This function calculates the value of the necessary condition
% as a function of the temperature (theta). It is used in solving
% Example 5.5.
% Calculating the b’s
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
db1 = w(1)*(-w(2))*2*(theta-w(3)) / (1-w(2)*(25-w(3))^2);
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
db2 = w(4)*(-w(2))*2*(theta-w(3)) / (1-w(2)*(25-w(3))^2);
b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-w(2)*(25-w(6))^2);
db3 = w(5)*(-w(2))*2*(theta-w(6)) / (1-w(2)*(25-w(6))^2);
% The function
ftheta = y(3)*(y(1)*db1-y(1)^2*(db1*b2-db2*b1)/b2^2)+y(1)*db3;
function [x,y] = collocation(ODEfile,x0,xf,y0,yf,guess,n,rho,tol,varargin)
%COLLOCATION Solves a boundary value set of ordinary differential
% equations by the orthogonal collocation method.
%
% [X,Y]=COLLOCATION(‘F’,X0,XF,Y0,YF,GAMMA,N) integrates the set of
% ordinary differential equations from X0 to XF by the Nth-degree
% orthogonal collocation method. The equations are contained in
% the M-file F.M. Y0, YF, and GAMMA are the vectors of initial
% conditions, final conditions, and starting guesses respectively.
% The function returns the independent variable in the vector X
% and the set of dependent variables in the matrix Y.
%
% [X,Y]=COLLOCATION(‘F’,X0,XF,Y0,YF,GAMMA,N,RHO,TOL,P1,P2,…)
% uses relaxation factor RHO and tolerance TOL for convergence
% test. Additional parameters P1, P2, … are passed directly to
% the function F. Pass an empty matrix for RHO or TOL to use the
% default value.
%
% See also SHOOTING
% (c) N. Mostoufi & A. Constantinides
% January 1, 1999
% Initialization
if nargin < 7 | isempty(n)
n = 1;
end
if nargin < 8 | isempty(rho)
rho = 1;
end
if nargin < 9 | isempty(tol)
tol = 1e-6;
end
y0 = (y0(:).’)’; % Make sure it’s a column vector
yf = (yf(:).’)’; % Make sure it’s a column vector
guess = (guess(:).’)’; % Make sure it’s a column vector
% Checking the number of guesses
if length(yf) ~= length(guess)
error(‘ The number of guessed conditions is not equal to the number of final conditions.’)
end
r = length(y0); % Number of initial conditions
m = r + length(yf); % Number of boundary conditions
% Checking the number of equations
ftest = feval(ODEfile,x0,[y0 ; guess],varargin{:});
if length(ftest) ~= m
error(‘ The number of equations is not equal to the number of boundary conditions.’)
end
fprintf(‘n Integrating. Please wait.nn’)
% Coefficients of the Legendre polynomial
for k = 0 : n/2
cl(2*k+1) = (-1)^k * gamma(2*n-2*k+1) / …
(2^n * gamma(k+1) * gamma(n-k+1) * gamma(n-2*k+1));
if k < n/2
cl(2*k+2) = 0;
end
end
zl = roots(cl); % Roots of the Legendre polynomial
z = [-1; sort(zl); 1]; % Collocation points (z)
x = (xf-x0)*z/2+(xf+x0)/2; % Collocation points (x)
% Bulding the vector of starting values of the dependent variables
[p,q] = RK(ODEfile,x0,xf,(xf-x0)/20,[y0 ; guess],2,varargin{:});
for k = 1:m
y(k,:) = spline(p,q(k,:),x’);
end
y(r+1:m,end) = yf(1:m-r);
% Building the matrix A
Q(:,1) = ones(n+2,1);
C(:,1) = zeros(n+2,1);
for i = 1:n+1
Q(:,i+1) = x.^i;
C(:,i+1) = i*x.^(i-1);
end
A = C*inv(Q);
for k = 1:m
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
Am(k1:k2,k1:k2) = A; % Building the matrix Am
Y(k1:k2) = y(k,:); % Building the vector Y
end
Y = Y’; % Make it a column vector
Y1 = Y * 1.1;
iter = 0;
maxiter = 100;
F = zeros(m*(n+2),1);
Fa = zeros(m*(n+2),1);
dY = zeros(m*(n+2),1);
position = []; % Collocation points excluding boundary conditions
for k = 1:m
if k <= r
position = [position, (k-1)*(n+2)+[2:n+2] ];
else
position = [position, (k-1)*(n+2)+[1:n+1] ];
end
end
% Newton’s method
while max(abs(Y1 – Y)) > tol & iter < maxiter
iter = iter + 1;
fprintf(‘ Iteration %3dn’,iter)
Y1 = Y;
% Building the vector F
for k = 1:n+2
F(k : n+2 : (m-1)*(n+2)+k) = …
feval(ODEfile,x(k),Y(k : n+2 : (m-1)*(n+2)+k),varargin{:});
end
fnk = Am * Y – F;
% Set dY for derivation
for k = 1:m*(n+1)
if Y(position(k)) ~= 0
dY(position(k)) = Y(position(k)) / 100;
else
dY(position(k)) = 0.01;
end
end
% Calculation of the Jacobian matrix
for k = 1:m
for kk = 1:n+1
a = Y;
nc = (k-1)*(n+1)+kk;
a(position(nc)) = Y(position(nc)) + dY(position(nc));
for kkk = 1:n+2
Fa(kkk : n+2 : (m-1)*(n+2)+kkk) = …
feval(ODEfile,x(kkk),a(kkk:n+2:(m-1)*(n+2)+kkk),varargin{:});
end
fnka = Am * a – Fa;
jacob(:,nc) = (fnka(position) – fnk(position))…
/ dY(position(nc));
end
end
% Next approximation of the roots
if det(jacob) == 0
Y(position) = Y(position) + max([abs(dY(position)); 1.1*tol]);
else
Y(position) = Y(position) – rho * inv(jacob) * fnk(position);
end
end
% Rearranging the y’s
for k = 1:m
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
y(k,:) = Y(k1:k2)’;
end
x = x’;
if iter >= maxiter
disp(‘Warning : Maximum iterations reached.’)
end % Example5_5.m
% Solution to Example 5.5. This program calculates and plots
% the concentration of cell mass, concentration of penicillin,
% optimal temperature profile, and adjoint variable of a batch
% penicillin fermentor. It uses the function COLLOCATION to
% solve the set of system and adjoint equations.
clear
clc
clf
% Input data
w = input(‘ Enter w”s as a vector : ‘);
y0 = input(‘ Vector of known initial conditions = ‘);
yf = input(‘ Vector of final conditions = ‘);
guess = input(‘ Vector of guessed initial conditions = ‘);
fname = input(‘n M-file containing the set of differential equations : ‘);
fth = input(‘ M-file containing the necessary condition function : ‘);
n = input(‘ Number of internal collocation points = ‘);
rho = input(‘ Relaxation factor = ‘);
% Solution of the set of differential equations
[t,y] = collocation(fname,0,1,y0,yf,guess,n,rho,[],w,fth);
% Temperature changes
for k = 1:n+2
options=optimset;
theta(k) = fzero(fth,30,options,y(:,k),w);
end
% Plotting the results
subplot(2,2,1), plot(t,y(1,:))
xlabel(‘Time’)
ylabel(‘Cell’)
title(‘(a)’)
subplot(2,2,2), plot(t,y(2,:))
xlabel(‘Time’)
ylabel(‘Penicillin’)
title(‘(b)’)
subplot(2,2,3), plot(t,y(3,:))
xlabel(‘Time’)
ylabel(‘First Adjoint’)
title(‘(c)’)
subplot(2,2,4), plot(t,theta)
xlabel(‘Time’)
ylabel(‘Temperature (deg C)’)
title(‘(d)’)
function f = Ex5_5_func(t,y,w,fth)
% Function Ex5_5_func.M
% This function introduces the set of ordinary differential
% equations used in Example 5.5.
% Temperature
options=optimset;
theta = fzero(fth,30,options,y,w);
% Calculating the b’s
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
if b1<0, b1=0; end
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
if b2<0, b2=1e-6; end
b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-w(2)*(25-w(6))^2);
if b3<0, b3=0; end
% Evaluating the function values
f(1) = b1*y(1) – b1/b2*y(1)^2;
f(2) = b3*y(1);
f(3) = -b1*y(3) + 2*b1/b2*y(1)*y(3) – b3;
f = f’; % Make it a column vector
function ftheta = Ex5_5_theta(theta,y,w)
% Function Ex5_5_theta.M
% This function calculates the value of the necessary condition
% as a function of the temperature (theta). It is used in solving
% Example 5.5.
% Calculating the b’s
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
db1 = w(1)*(-w(2))*2*(theta-w(3)) / (1-w(2)*(25-w(3))^2);
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-w(2)*(25-w(3))^2);
db2 = w(4)*(-w(2))*2*(theta-w(3)) / (1-w(2)*(25-w(3))^2);
b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-w(2)*(25-w(6))^2);
db3 = w(5)*(-w(2))*2*(theta-w(6)) / (1-w(2)*(25-w(6))^2);
% The function
ftheta = y(3)*(y(1)*db1-y(1)^2*(db1*b2-db2*b1)/b2^2)+y(1)*db3;
function [x,y] = collocation(ODEfile,x0,xf,y0,yf,guess,n,rho,tol,varargin)
%COLLOCATION Solves a boundary value set of ordinary differential
% equations by the orthogonal collocation method.
%
% [X,Y]=COLLOCATION(‘F’,X0,XF,Y0,YF,GAMMA,N) integrates the set of
% ordinary differential equations from X0 to XF by the Nth-degree
% orthogonal collocation method. The equations are contained in
% the M-file F.M. Y0, YF, and GAMMA are the vectors of initial
% conditions, final conditions, and starting guesses respectively.
% The function returns the independent variable in the vector X
% and the set of dependent variables in the matrix Y.
%
% [X,Y]=COLLOCATION(‘F’,X0,XF,Y0,YF,GAMMA,N,RHO,TOL,P1,P2,…)
% uses relaxation factor RHO and tolerance TOL for convergence
% test. Additional parameters P1, P2, … are passed directly to
% the function F. Pass an empty matrix for RHO or TOL to use the
% default value.
%
% See also SHOOTING
% (c) N. Mostoufi & A. Constantinides
% January 1, 1999
% Initialization
if nargin < 7 | isempty(n)
n = 1;
end
if nargin < 8 | isempty(rho)
rho = 1;
end
if nargin < 9 | isempty(tol)
tol = 1e-6;
end
y0 = (y0(:).’)’; % Make sure it’s a column vector
yf = (yf(:).’)’; % Make sure it’s a column vector
guess = (guess(:).’)’; % Make sure it’s a column vector
% Checking the number of guesses
if length(yf) ~= length(guess)
error(‘ The number of guessed conditions is not equal to the number of final conditions.’)
end
r = length(y0); % Number of initial conditions
m = r + length(yf); % Number of boundary conditions
% Checking the number of equations
ftest = feval(ODEfile,x0,[y0 ; guess],varargin{:});
if length(ftest) ~= m
error(‘ The number of equations is not equal to the number of boundary conditions.’)
end
fprintf(‘n Integrating. Please wait.nn’)
% Coefficients of the Legendre polynomial
for k = 0 : n/2
cl(2*k+1) = (-1)^k * gamma(2*n-2*k+1) / …
(2^n * gamma(k+1) * gamma(n-k+1) * gamma(n-2*k+1));
if k < n/2
cl(2*k+2) = 0;
end
end
zl = roots(cl); % Roots of the Legendre polynomial
z = [-1; sort(zl); 1]; % Collocation points (z)
x = (xf-x0)*z/2+(xf+x0)/2; % Collocation points (x)
% Bulding the vector of starting values of the dependent variables
[p,q] = RK(ODEfile,x0,xf,(xf-x0)/20,[y0 ; guess],2,varargin{:});
for k = 1:m
y(k,:) = spline(p,q(k,:),x’);
end
y(r+1:m,end) = yf(1:m-r);
% Building the matrix A
Q(:,1) = ones(n+2,1);
C(:,1) = zeros(n+2,1);
for i = 1:n+1
Q(:,i+1) = x.^i;
C(:,i+1) = i*x.^(i-1);
end
A = C*inv(Q);
for k = 1:m
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
Am(k1:k2,k1:k2) = A; % Building the matrix Am
Y(k1:k2) = y(k,:); % Building the vector Y
end
Y = Y’; % Make it a column vector
Y1 = Y * 1.1;
iter = 0;
maxiter = 100;
F = zeros(m*(n+2),1);
Fa = zeros(m*(n+2),1);
dY = zeros(m*(n+2),1);
position = []; % Collocation points excluding boundary conditions
for k = 1:m
if k <= r
position = [position, (k-1)*(n+2)+[2:n+2] ];
else
position = [position, (k-1)*(n+2)+[1:n+1] ];
end
end
% Newton’s method
while max(abs(Y1 – Y)) > tol & iter < maxiter
iter = iter + 1;
fprintf(‘ Iteration %3dn’,iter)
Y1 = Y;
% Building the vector F
for k = 1:n+2
F(k : n+2 : (m-1)*(n+2)+k) = …
feval(ODEfile,x(k),Y(k : n+2 : (m-1)*(n+2)+k),varargin{:});
end
fnk = Am * Y – F;
% Set dY for derivation
for k = 1:m*(n+1)
if Y(position(k)) ~= 0
dY(position(k)) = Y(position(k)) / 100;
else
dY(position(k)) = 0.01;
end
end
% Calculation of the Jacobian matrix
for k = 1:m
for kk = 1:n+1
a = Y;
nc = (k-1)*(n+1)+kk;
a(position(nc)) = Y(position(nc)) + dY(position(nc));
for kkk = 1:n+2
Fa(kkk : n+2 : (m-1)*(n+2)+kkk) = …
feval(ODEfile,x(kkk),a(kkk:n+2:(m-1)*(n+2)+kkk),varargin{:});
end
fnka = Am * a – Fa;
jacob(:,nc) = (fnka(position) – fnk(position))…
/ dY(position(nc));
end
end
% Next approximation of the roots
if det(jacob) == 0
Y(position) = Y(position) + max([abs(dY(position)); 1.1*tol]);
else
Y(position) = Y(position) – rho * inv(jacob) * fnk(position);
end
end
% Rearranging the y’s
for k = 1:m
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
y(k,:) = Y(k1:k2)’;
end
x = x’;
if iter >= maxiter
disp(‘Warning : Maximum iterations reached.’)
end collocation MATLAB Answers — New Questions
THD analysis of mathematical simulink model
I have done mathematical modelling of my system in simulink then how to perform the THD analysisI have done mathematical modelling of my system in simulink then how to perform the THD analysis I have done mathematical modelling of my system in simulink then how to perform the THD analysis thd, mathematical model MATLAB Answers — New Questions
How to plot RGB histogram of an image into a single 3D slice plot?
Hello. Im working on color image encryption and need to plot the histogram for each color channels. I can plot the individual color channel histogram in three 2D plot with this code.
close all;
image = imread(‘peppers.png’);
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
[Width,Length] = size(image);
subplot(2,2,1); imshow(image);
title(‘Plain Image’)
subplot(2,2,2);
imhist(R);
myHist1 = findobj(gca, ‘Type’, ‘Stem’);
myHist1.Color = [1 0 0];
title(‘Red Channel Plain Histogram’)
subplot(2,2,3);
imhist(G);
myHist2 = findobj(gca, ‘Type’, ‘Stem’);
myHist2.Color = [0 1 0];
title(‘Green Channel Plain Histogram’)
subplot(2,2,4);
imhist(B);
myHist3 = findobj(gca, ‘Type’, ‘Stem’);
myHist3.Color = [0 0 1];
xlim([0 256]);
title(‘Blue Channel Plain Histogram’)
But, i tried to plot them together in a 3D plot like this below (picture from an article i found), but i cant. I tried to find any forum that talks about this, but i can only found slice plots of meshgrid, not from histogram.
If anyone could help, I would appreciate it so much.
Thank you!Hello. Im working on color image encryption and need to plot the histogram for each color channels. I can plot the individual color channel histogram in three 2D plot with this code.
close all;
image = imread(‘peppers.png’);
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
[Width,Length] = size(image);
subplot(2,2,1); imshow(image);
title(‘Plain Image’)
subplot(2,2,2);
imhist(R);
myHist1 = findobj(gca, ‘Type’, ‘Stem’);
myHist1.Color = [1 0 0];
title(‘Red Channel Plain Histogram’)
subplot(2,2,3);
imhist(G);
myHist2 = findobj(gca, ‘Type’, ‘Stem’);
myHist2.Color = [0 1 0];
title(‘Green Channel Plain Histogram’)
subplot(2,2,4);
imhist(B);
myHist3 = findobj(gca, ‘Type’, ‘Stem’);
myHist3.Color = [0 0 1];
xlim([0 256]);
title(‘Blue Channel Plain Histogram’)
But, i tried to plot them together in a 3D plot like this below (picture from an article i found), but i cant. I tried to find any forum that talks about this, but i can only found slice plots of meshgrid, not from histogram.
If anyone could help, I would appreciate it so much.
Thank you! Hello. Im working on color image encryption and need to plot the histogram for each color channels. I can plot the individual color channel histogram in three 2D plot with this code.
close all;
image = imread(‘peppers.png’);
R = image(:,:,1);
G = image(:,:,2);
B = image(:,:,3);
[Width,Length] = size(image);
subplot(2,2,1); imshow(image);
title(‘Plain Image’)
subplot(2,2,2);
imhist(R);
myHist1 = findobj(gca, ‘Type’, ‘Stem’);
myHist1.Color = [1 0 0];
title(‘Red Channel Plain Histogram’)
subplot(2,2,3);
imhist(G);
myHist2 = findobj(gca, ‘Type’, ‘Stem’);
myHist2.Color = [0 1 0];
title(‘Green Channel Plain Histogram’)
subplot(2,2,4);
imhist(B);
myHist3 = findobj(gca, ‘Type’, ‘Stem’);
myHist3.Color = [0 0 1];
xlim([0 256]);
title(‘Blue Channel Plain Histogram’)
But, i tried to plot them together in a 3D plot like this below (picture from an article i found), but i cant. I tried to find any forum that talks about this, but i can only found slice plots of meshgrid, not from histogram.
If anyone could help, I would appreciate it so much.
Thank you! image processing, histogram, 3d plots MATLAB Answers — New Questions
Plot histogram of a series of images and extract cracks
Dear all,
I’m trying to plot histogram of a series of tomography images to assess the threshold for extracting cracks. I don’t understand why the histogram is not displayed. I would like to select at least the first and the last images to determine the threshold. Here is the code:
Thanks a lot for any help
clear all
close all
clc
a= load(‘tomo_carota_8bit.mat’)
x=a.x_8;
x=double(x);
% clear a
%%
figure,
for ii = 1:size(x, 3)
ii
I = squeeze(x(:,:,ii));
imshow(I, []);
pause(0.1)
end
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(I);
[counts, grayLevels] = imhist(I);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(I(:))]);
%xlim([0 100])
title(‘Histogram of original image zoomed’);
subplot(3,2,4);
thresholdValue = 85;
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = I > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 85’);
f.InvertHardcopy = ‘off’;
binaryImage = I > thresholdValue;
subplot(3,2,5);
imshow(binaryImage, []);
title(‘Binary Image threshold 60’);
figure (1)Dear all,
I’m trying to plot histogram of a series of tomography images to assess the threshold for extracting cracks. I don’t understand why the histogram is not displayed. I would like to select at least the first and the last images to determine the threshold. Here is the code:
Thanks a lot for any help
clear all
close all
clc
a= load(‘tomo_carota_8bit.mat’)
x=a.x_8;
x=double(x);
% clear a
%%
figure,
for ii = 1:size(x, 3)
ii
I = squeeze(x(:,:,ii));
imshow(I, []);
pause(0.1)
end
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(I);
[counts, grayLevels] = imhist(I);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(I(:))]);
%xlim([0 100])
title(‘Histogram of original image zoomed’);
subplot(3,2,4);
thresholdValue = 85;
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = I > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 85’);
f.InvertHardcopy = ‘off’;
binaryImage = I > thresholdValue;
subplot(3,2,5);
imshow(binaryImage, []);
title(‘Binary Image threshold 60’);
figure (1) Dear all,
I’m trying to plot histogram of a series of tomography images to assess the threshold for extracting cracks. I don’t understand why the histogram is not displayed. I would like to select at least the first and the last images to determine the threshold. Here is the code:
Thanks a lot for any help
clear all
close all
clc
a= load(‘tomo_carota_8bit.mat’)
x=a.x_8;
x=double(x);
% clear a
%%
figure,
for ii = 1:size(x, 3)
ii
I = squeeze(x(:,:,ii));
imshow(I, []);
pause(0.1)
end
subplot(3,2,1);
imshow(I,[]);
title(‘Original Grayscale Image’, ‘FontSize’, 15);
subplot(3,2,2);
imhist(I);
title(‘Histogram of original image’);
subplot(3,2,3);
imhist(I);
[counts, grayLevels] = imhist(I);
bar(grayLevels, counts, ‘EdgeColor’, ‘r’, ‘FaceColor’, ‘b’, ‘BarWidth’, 1);
xlim([0, max(I(:))]);
%xlim([0 100])
title(‘Histogram of original image zoomed’);
subplot(3,2,4);
thresholdValue = 85;
thresholdValue1 = 60;
f.InvertHardcopy = ‘off’;
binaryImage1 = I > thresholdValue1;
imshow(binaryImage1, []);
title(‘Binary Image threshold 85’);
f.InvertHardcopy = ‘off’;
binaryImage = I > thresholdValue;
subplot(3,2,5);
imshow(binaryImage, []);
title(‘Binary Image threshold 60’);
figure (1) threshold, imhist, imshow MATLAB Answers — New Questions
How does the Spacecraft Dynamics block work?
In Simulink (Aerospace Blockset) there is a Spacecraft Dynamics block. How does he work? I can’t look inside it (Look Under Mask option is inactive). The description page shows the equations that are used in the block, but the numbers given are clearly not given in full (it seems to me). https://www.mathworks.com/help/aeroblks/getting-started-with-the-spacecraft-dynamics-block.html
In addition, the equations themselves raise some questions, for example, the PDEs are given. Simulink can now solve PDEs in real time?
I want to understand how this block works in order to learn how to write my own to suit my own needs.In Simulink (Aerospace Blockset) there is a Spacecraft Dynamics block. How does he work? I can’t look inside it (Look Under Mask option is inactive). The description page shows the equations that are used in the block, but the numbers given are clearly not given in full (it seems to me). https://www.mathworks.com/help/aeroblks/getting-started-with-the-spacecraft-dynamics-block.html
In addition, the equations themselves raise some questions, for example, the PDEs are given. Simulink can now solve PDEs in real time?
I want to understand how this block works in order to learn how to write my own to suit my own needs. In Simulink (Aerospace Blockset) there is a Spacecraft Dynamics block. How does he work? I can’t look inside it (Look Under Mask option is inactive). The description page shows the equations that are used in the block, but the numbers given are clearly not given in full (it seems to me). https://www.mathworks.com/help/aeroblks/getting-started-with-the-spacecraft-dynamics-block.html
In addition, the equations themselves raise some questions, for example, the PDEs are given. Simulink can now solve PDEs in real time?
I want to understand how this block works in order to learn how to write my own to suit my own needs. aerospace blockset, spacecraft dynamics, simulink MATLAB Answers — New Questions
question about how the function pca() calculates the covariance matrix internally
I was puzzled by the output of pca() when using mean centering or not. I am using Matlab 2024a.
pca.m uses the internal function c = ncnancov(x,Rows,centered) which seems to provide the covariance matrix of x
however,
1) it uses the formula for the population covariance, i.e. it calculates x’*x/n not x’*x/(n-1) – what is the rationale behind that?
2) it does not mean center x. This is surprising because without mean centering x the formula x’*x/n (or x’*x/(n-1) for that matter) does NOT provide the covariance matrix
The second point causes the call [coeff,score,latent]=pca(D, ‘Algorithm’,’eig’,’Centered’,’off’) to produce different coeff, and latent from the call [coeff,score,latent]=pca(D, ‘Algorithm’,’eig’). The scores will obviosuly be different but coeff and latent should not be affected by mean centering as can be shown by comparing the output of:
load(‘Data_Table8p1.mat’);
Dm = D-mean(D);
[coeff,eigValues] = eig(cov(D));
[eigValues, idx] = sort(diag(eigValues), ‘descend’); % sort
coeff = coeff(:, idx);
score = D/coeff’; % get scores of mean centered data
with:
[coeff_m,eigValues_m] = eig(cov(Dm));
[eigValues_m, idx] = sort(diag(eigValues_m), ‘descend’); % sort
coeff_m = coeff_m(:, idx);
score_m = Dm/coeff_m’; % get scores of mean centered data
Probably I am missing something, but the internal function ncnancov() as used in pca is unclear to me. Any explanation is much appreciated!I was puzzled by the output of pca() when using mean centering or not. I am using Matlab 2024a.
pca.m uses the internal function c = ncnancov(x,Rows,centered) which seems to provide the covariance matrix of x
however,
1) it uses the formula for the population covariance, i.e. it calculates x’*x/n not x’*x/(n-1) – what is the rationale behind that?
2) it does not mean center x. This is surprising because without mean centering x the formula x’*x/n (or x’*x/(n-1) for that matter) does NOT provide the covariance matrix
The second point causes the call [coeff,score,latent]=pca(D, ‘Algorithm’,’eig’,’Centered’,’off’) to produce different coeff, and latent from the call [coeff,score,latent]=pca(D, ‘Algorithm’,’eig’). The scores will obviosuly be different but coeff and latent should not be affected by mean centering as can be shown by comparing the output of:
load(‘Data_Table8p1.mat’);
Dm = D-mean(D);
[coeff,eigValues] = eig(cov(D));
[eigValues, idx] = sort(diag(eigValues), ‘descend’); % sort
coeff = coeff(:, idx);
score = D/coeff’; % get scores of mean centered data
with:
[coeff_m,eigValues_m] = eig(cov(Dm));
[eigValues_m, idx] = sort(diag(eigValues_m), ‘descend’); % sort
coeff_m = coeff_m(:, idx);
score_m = Dm/coeff_m’; % get scores of mean centered data
Probably I am missing something, but the internal function ncnancov() as used in pca is unclear to me. Any explanation is much appreciated! I was puzzled by the output of pca() when using mean centering or not. I am using Matlab 2024a.
pca.m uses the internal function c = ncnancov(x,Rows,centered) which seems to provide the covariance matrix of x
however,
1) it uses the formula for the population covariance, i.e. it calculates x’*x/n not x’*x/(n-1) – what is the rationale behind that?
2) it does not mean center x. This is surprising because without mean centering x the formula x’*x/n (or x’*x/(n-1) for that matter) does NOT provide the covariance matrix
The second point causes the call [coeff,score,latent]=pca(D, ‘Algorithm’,’eig’,’Centered’,’off’) to produce different coeff, and latent from the call [coeff,score,latent]=pca(D, ‘Algorithm’,’eig’). The scores will obviosuly be different but coeff and latent should not be affected by mean centering as can be shown by comparing the output of:
load(‘Data_Table8p1.mat’);
Dm = D-mean(D);
[coeff,eigValues] = eig(cov(D));
[eigValues, idx] = sort(diag(eigValues), ‘descend’); % sort
coeff = coeff(:, idx);
score = D/coeff’; % get scores of mean centered data
with:
[coeff_m,eigValues_m] = eig(cov(Dm));
[eigValues_m, idx] = sort(diag(eigValues_m), ‘descend’); % sort
coeff_m = coeff_m(:, idx);
score_m = Dm/coeff_m’; % get scores of mean centered data
Probably I am missing something, but the internal function ncnancov() as used in pca is unclear to me. Any explanation is much appreciated! pca, cov, matlab MATLAB Answers — New Questions
Copy and Paste Table into Word
Hello,
I’m trying to copy and paste into MS Word a table from my code and i couldn’t find a way to do it so. I’d like to paste and show in the same way Matlab shows the results on MS word.
I need ur help
Below the code i’ve been working.
% % % Display names
load_system(gcs);
Blockpaths= find_system(gcs,’Type’,’Block’);
NOM =[];
for i = 1:length(Blockpaths)
b =strsplit(char(Blockpaths(i)),’/’);
NOM =[NOM;b(end)];
end
% % % Display Types
open_system(gcs);
blks = find_system(gcs,’Type’,’block’);
TYPE = get_param(blks, ‘BlockType’);
j = 1;
k = 1;
for i = 1:length(TYPE)
if ( strcmp(TYPE{i},’Inport’))
In{j} = blks{i};
In{j} = strrep(In{j},gcs,”);
j = j + 1;
elseif ( strcmp(TYPE{i}, ‘Outport’))
Out{k} = blks{i};
Out{k} = strrep(Out{k},gcs,”);
k = k + 1;
end
end
% % % Create table
CONTENU=cell(length(Blockpaths),1);
t=table(NOM,TYPE,CONTENU);
SRCBLOCK=cell(length(Blockpaths),1);
t=table(NOM,TYPE,CONTENU,SRCBLOCK)
word = actxserver(‘Word.Application’);
word.Visible = true;
wdoc = word.Documents.Add;
Selection = word.Selection;
table = Selection.Tables.Add(Selection.Range,size(t,1),4);
table.Columns.Borders.Enable = 1;Hello,
I’m trying to copy and paste into MS Word a table from my code and i couldn’t find a way to do it so. I’d like to paste and show in the same way Matlab shows the results on MS word.
I need ur help
Below the code i’ve been working.
% % % Display names
load_system(gcs);
Blockpaths= find_system(gcs,’Type’,’Block’);
NOM =[];
for i = 1:length(Blockpaths)
b =strsplit(char(Blockpaths(i)),’/’);
NOM =[NOM;b(end)];
end
% % % Display Types
open_system(gcs);
blks = find_system(gcs,’Type’,’block’);
TYPE = get_param(blks, ‘BlockType’);
j = 1;
k = 1;
for i = 1:length(TYPE)
if ( strcmp(TYPE{i},’Inport’))
In{j} = blks{i};
In{j} = strrep(In{j},gcs,”);
j = j + 1;
elseif ( strcmp(TYPE{i}, ‘Outport’))
Out{k} = blks{i};
Out{k} = strrep(Out{k},gcs,”);
k = k + 1;
end
end
% % % Create table
CONTENU=cell(length(Blockpaths),1);
t=table(NOM,TYPE,CONTENU);
SRCBLOCK=cell(length(Blockpaths),1);
t=table(NOM,TYPE,CONTENU,SRCBLOCK)
word = actxserver(‘Word.Application’);
word.Visible = true;
wdoc = word.Documents.Add;
Selection = word.Selection;
table = Selection.Tables.Add(Selection.Range,size(t,1),4);
table.Columns.Borders.Enable = 1; Hello,
I’m trying to copy and paste into MS Word a table from my code and i couldn’t find a way to do it so. I’d like to paste and show in the same way Matlab shows the results on MS word.
I need ur help
Below the code i’ve been working.
% % % Display names
load_system(gcs);
Blockpaths= find_system(gcs,’Type’,’Block’);
NOM =[];
for i = 1:length(Blockpaths)
b =strsplit(char(Blockpaths(i)),’/’);
NOM =[NOM;b(end)];
end
% % % Display Types
open_system(gcs);
blks = find_system(gcs,’Type’,’block’);
TYPE = get_param(blks, ‘BlockType’);
j = 1;
k = 1;
for i = 1:length(TYPE)
if ( strcmp(TYPE{i},’Inport’))
In{j} = blks{i};
In{j} = strrep(In{j},gcs,”);
j = j + 1;
elseif ( strcmp(TYPE{i}, ‘Outport’))
Out{k} = blks{i};
Out{k} = strrep(Out{k},gcs,”);
k = k + 1;
end
end
% % % Create table
CONTENU=cell(length(Blockpaths),1);
t=table(NOM,TYPE,CONTENU);
SRCBLOCK=cell(length(Blockpaths),1);
t=table(NOM,TYPE,CONTENU,SRCBLOCK)
word = actxserver(‘Word.Application’);
word.Visible = true;
wdoc = word.Documents.Add;
Selection = word.Selection;
table = Selection.Tables.Add(Selection.Range,size(t,1),4);
table.Columns.Borders.Enable = 1; word table MATLAB Answers — New Questions
How to enable BitMask in EcuDescriptions when using coder.asap2.export
I have created CSC for measurement signals and I am packing my signals as bitfield. My generated code has all signals declared inside a structure with bitwidth. when I use coder.asap2.export to generate a2l file, Measurement has no BitMAsk Information.
With Matlab 2023b, I tried to extract EcuDescriptions using command descObj = coder.asap2.getEcuDescriptions("ModelName") and then I tried to extract measurement properties using command get(descObj,"Measurement","Struct.Signal1"). Measurement object has no information on BitMask.
Can someone guide me how to configure my model so that BitMAsk information is present in my a2l file?I have created CSC for measurement signals and I am packing my signals as bitfield. My generated code has all signals declared inside a structure with bitwidth. when I use coder.asap2.export to generate a2l file, Measurement has no BitMAsk Information.
With Matlab 2023b, I tried to extract EcuDescriptions using command descObj = coder.asap2.getEcuDescriptions("ModelName") and then I tried to extract measurement properties using command get(descObj,"Measurement","Struct.Signal1"). Measurement object has no information on BitMask.
Can someone guide me how to configure my model so that BitMAsk information is present in my a2l file? I have created CSC for measurement signals and I am packing my signals as bitfield. My generated code has all signals declared inside a structure with bitwidth. when I use coder.asap2.export to generate a2l file, Measurement has no BitMAsk Information.
With Matlab 2023b, I tried to extract EcuDescriptions using command descObj = coder.asap2.getEcuDescriptions("ModelName") and then I tried to extract measurement properties using command get(descObj,"Measurement","Struct.Signal1"). Measurement object has no information on BitMask.
Can someone guide me how to configure my model so that BitMAsk information is present in my a2l file? asap2, embedded coder MATLAB Answers — New Questions
how to plot a matrix graph of D(n,m) versus C(n,m) with different colors
I would like to plot a graph of D versus C. For each i have a different colorI would like to plot a graph of D versus C. For each i have a different color I would like to plot a graph of D versus C. For each i have a different color matrix, plot, color MATLAB Answers — New Questions
Optimize the constant by minimizing the error whit no direct relation
I want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let’s name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
ThanksI want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let’s name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
Thanks I want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let’s name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
Thanks optimization MATLAB Answers — New Questions
Help with contour plot
Hello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = [‘r’,’g’,’b’,’c’,’k’];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J – M*a1*a2);
D = k1(q)*k2 – X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = [‘k_1 = ‘, num2str(k1(q))];
contour(X, Y, Z, v, ‘LineWidth’, 1.2, ‘LineColor’, clr(q), ‘DisplayName’, LegendsStrings{q});
hold on
end
legend()
xlabel(‘k_a_1_2’)
ylabel(‘k_a_2_1’)
grid onHello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = [‘r’,’g’,’b’,’c’,’k’];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J – M*a1*a2);
D = k1(q)*k2 – X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = [‘k_1 = ‘, num2str(k1(q))];
contour(X, Y, Z, v, ‘LineWidth’, 1.2, ‘LineColor’, clr(q), ‘DisplayName’, LegendsStrings{q});
hold on
end
legend()
xlabel(‘k_a_1_2’)
ylabel(‘k_a_2_1’)
grid on Hello veryone,
i am trying do a contour plot of the stability of a mechanical system: so given a meshgrid X-Y and for a varying parameter k1, i calculate Z based on two conditions (B and D) and plot for Z=0. As k1 can be one of five different values i would like to have five different curves on the same plot.
but i only get two curves (which are also not right) and in the command windows this warning appears:
"Warning: Contour not rendered for constant ZData"
could anybody help me find the problem? thank you very much
here ist the script i am using
clear; clc; clf;
M = 700; J = 400; a1 = 1.85; a2 = 1.85; L = 3.7;
n = 101;
m = 50000;
k_a12 = linspace(-m, m, n);
k_a21 = linspace(-m, m, n);
[X, Y] = meshgrid(k_a12, k_a21);
v = [0 0];
clr = [‘r’,’g’,’b’,’c’,’k’];
b = 100000;
a = 5;
k1 = linspace(-b, b, a);
k2 = 0;
LegendsStrings = cell(numel(k1),1);
Z = zeros(n, n);
for q = 1:a
for i = 1:n
for j = 1:n
B = k1(q)*(J + M*a1^2) + k2*(J + M*a2^2) + (X + Y)*(J – M*a1*a2);
D = k1(q)*k2 – X.*Y;
if B(i, j) >= 0 && D(i, j) >= 0
Z(i, j) = D(i, j);
else
Z(i, j) = -1;
end
end
end
LegendsStrings{q} = [‘k_1 = ‘, num2str(k1(q))];
contour(X, Y, Z, v, ‘LineWidth’, 1.2, ‘LineColor’, clr(q), ‘DisplayName’, LegendsStrings{q});
hold on
end
legend()
xlabel(‘k_a_1_2’)
ylabel(‘k_a_2_1’)
grid on contour, 2d plot, loops, contour plot MATLAB Answers — New Questions
How to include requirements in Embedded Web View Report
I have searched the forums, Google and the documentation for hours, but i cannot find a way to include the requirements in an Embedded Web View Report. My MATLAB version is R2024a.
While it is easy to include the requirements when generating an standard webview form Simulink (see image below), it does not seem to be possible to do so with code in Embedded Web View Report generation.
The following code belongs to the class that i am using to generate this report (it is worth mentioning that there are no issues here, the report is correctly generated):
function rpt = classReportGeneratorWebview(reportName,modelName)
rpt@slreportgen.webview.EmbeddedWebViewDocument(…
reportName,modelName);
% Suppress Link Warning Messages for Embedded Web View Reports:
rpt.ValidateLinksAndAnchors = false;
% Specify Export Options for Embedded Web View Reports:
rpt.ExportOptions.SearchScope = ‘All’;
rpt.ExportOptions.IncludeReferencedModels = true;
rpt.ExportOptions.IncludeMaskedSubsystems = true;
end
As can be seen, the ExportOptions has properties that allow including multiple aspects. However, in the documentation (https://es.mathworks.com/help/rptgenext/ug/slreportgen.webview.exportoptions-class.html), there is no property related to including the requirements.
Therefore, when the report is generated, the button that allows access to the requirements view is obviously missing.
I would like to know if there is a way to include requirements in an Embedded Web View Report, inside the webview. Help would be much appreciated.I have searched the forums, Google and the documentation for hours, but i cannot find a way to include the requirements in an Embedded Web View Report. My MATLAB version is R2024a.
While it is easy to include the requirements when generating an standard webview form Simulink (see image below), it does not seem to be possible to do so with code in Embedded Web View Report generation.
The following code belongs to the class that i am using to generate this report (it is worth mentioning that there are no issues here, the report is correctly generated):
function rpt = classReportGeneratorWebview(reportName,modelName)
rpt@slreportgen.webview.EmbeddedWebViewDocument(…
reportName,modelName);
% Suppress Link Warning Messages for Embedded Web View Reports:
rpt.ValidateLinksAndAnchors = false;
% Specify Export Options for Embedded Web View Reports:
rpt.ExportOptions.SearchScope = ‘All’;
rpt.ExportOptions.IncludeReferencedModels = true;
rpt.ExportOptions.IncludeMaskedSubsystems = true;
end
As can be seen, the ExportOptions has properties that allow including multiple aspects. However, in the documentation (https://es.mathworks.com/help/rptgenext/ug/slreportgen.webview.exportoptions-class.html), there is no property related to including the requirements.
Therefore, when the report is generated, the button that allows access to the requirements view is obviously missing.
I would like to know if there is a way to include requirements in an Embedded Web View Report, inside the webview. Help would be much appreciated. I have searched the forums, Google and the documentation for hours, but i cannot find a way to include the requirements in an Embedded Web View Report. My MATLAB version is R2024a.
While it is easy to include the requirements when generating an standard webview form Simulink (see image below), it does not seem to be possible to do so with code in Embedded Web View Report generation.
The following code belongs to the class that i am using to generate this report (it is worth mentioning that there are no issues here, the report is correctly generated):
function rpt = classReportGeneratorWebview(reportName,modelName)
rpt@slreportgen.webview.EmbeddedWebViewDocument(…
reportName,modelName);
% Suppress Link Warning Messages for Embedded Web View Reports:
rpt.ValidateLinksAndAnchors = false;
% Specify Export Options for Embedded Web View Reports:
rpt.ExportOptions.SearchScope = ‘All’;
rpt.ExportOptions.IncludeReferencedModels = true;
rpt.ExportOptions.IncludeMaskedSubsystems = true;
end
As can be seen, the ExportOptions has properties that allow including multiple aspects. However, in the documentation (https://es.mathworks.com/help/rptgenext/ug/slreportgen.webview.exportoptions-class.html), there is no property related to including the requirements.
Therefore, when the report is generated, the button that allows access to the requirements view is obviously missing.
I would like to know if there is a way to include requirements in an Embedded Web View Report, inside the webview. Help would be much appreciated. report, webview, simulink, embedded webview report MATLAB Answers — New Questions
how to resolve “At least one value is out of range for rectangle or position” error?
Description: I have my own custom script for creating harness and in that While creating test harness i am facing this error on "create.m" default script at this line. i am using matlab 2018b version
>> Simulink.harness.create(harnessOwner, varargin{:});
and when i am trying to go inside this it is telling it is .p script so unable to debug it. so, after run the script it is giving me this error "At least one value is out of range for rectangle or position. All x values must be within -32786..32767 range, all y values must be within -32786..32767 range"Description: I have my own custom script for creating harness and in that While creating test harness i am facing this error on "create.m" default script at this line. i am using matlab 2018b version
>> Simulink.harness.create(harnessOwner, varargin{:});
and when i am trying to go inside this it is telling it is .p script so unable to debug it. so, after run the script it is giving me this error "At least one value is out of range for rectangle or position. All x values must be within -32786..32767 range, all y values must be within -32786..32767 range" Description: I have my own custom script for creating harness and in that While creating test harness i am facing this error on "create.m" default script at this line. i am using matlab 2018b version
>> Simulink.harness.create(harnessOwner, varargin{:});
and when i am trying to go inside this it is telling it is .p script so unable to debug it. so, after run the script it is giving me this error "At least one value is out of range for rectangle or position. All x values must be within -32786..32767 range, all y values must be within -32786..32767 range" out of range, -32786, matlab, simulink, harness, matlab function, create.m, urgent, matlab coder MATLAB Answers — New Questions
the mechanism of different syntax for realizing the same effect
hi, i wanted to ask is there some logics for remembering the syntax in Matlab, because sometimes i found the syntax have different logics, which confused myself. For example, < box on/off > is a simplified syntax in controlling whether the axis box is on. There are two syntax with different logics on controlling box. One is < box(ax,"off") >, and the other one is < set(ax,"box","off") > . PS. The former is probably the full form of < box off > ?? These two forms have different starting point within it. But when it comes to setting xlabel, it seems we could only use < xlabel("Time") >, and < set(ax,"XLabel","Time") > doesnot work. Why is this so as both box and XLabel are the properties of Axis. The funny thing is that < ax.XLabel.String = "Time" > is also ok. Can someone help explain? Thanks.hi, i wanted to ask is there some logics for remembering the syntax in Matlab, because sometimes i found the syntax have different logics, which confused myself. For example, < box on/off > is a simplified syntax in controlling whether the axis box is on. There are two syntax with different logics on controlling box. One is < box(ax,"off") >, and the other one is < set(ax,"box","off") > . PS. The former is probably the full form of < box off > ?? These two forms have different starting point within it. But when it comes to setting xlabel, it seems we could only use < xlabel("Time") >, and < set(ax,"XLabel","Time") > doesnot work. Why is this so as both box and XLabel are the properties of Axis. The funny thing is that < ax.XLabel.String = "Time" > is also ok. Can someone help explain? Thanks. hi, i wanted to ask is there some logics for remembering the syntax in Matlab, because sometimes i found the syntax have different logics, which confused myself. For example, < box on/off > is a simplified syntax in controlling whether the axis box is on. There are two syntax with different logics on controlling box. One is < box(ax,"off") >, and the other one is < set(ax,"box","off") > . PS. The former is probably the full form of < box off > ?? These two forms have different starting point within it. But when it comes to setting xlabel, it seems we could only use < xlabel("Time") >, and < set(ax,"XLabel","Time") > doesnot work. Why is this so as both box and XLabel are the properties of Axis. The funny thing is that < ax.XLabel.String = "Time" > is also ok. Can someone help explain? Thanks. box, axis, label MATLAB Answers — New Questions
WSL, ROS Humble – Simulink
Hello,
I am using ROS Humbe on WSL2 with Ubuntu 22.04 and I was wondering if I should install MATLAB into my Ubuntu System ? Or MATLAB on my Windows can still communicate with ROS ? Has any one ever tried using it ?Hello,
I am using ROS Humbe on WSL2 with Ubuntu 22.04 and I was wondering if I should install MATLAB into my Ubuntu System ? Or MATLAB on my Windows can still communicate with ROS ? Has any one ever tried using it ? Hello,
I am using ROS Humbe on WSL2 with Ubuntu 22.04 and I was wondering if I should install MATLAB into my Ubuntu System ? Or MATLAB on my Windows can still communicate with ROS ? Has any one ever tried using it ? simulink, matlab MATLAB Answers — New Questions
Scrollable Plot in real time from Arduino to Matlab
Hi,
I meet a problem when plotting data from Arduino to Matlab, where the x axis is increasing continously and cause the compression of plot. I want to let the x axis auto-scroll, something like axis(t,t+dx,y1,y2). I’ve tried two ways plotting the data, shown below. Is there any other methods to make the x axis auto-scrolling? Thank you in advance!
Method 1
%Method 1
clear all
a = arduino(‘COM5′,’ProMini328_5v’);
%interv = 10;
passo = 1;
t=1;
x=0;
%while(t<interv)
while(t)
b=a.readVoltage(‘A3’);
x=[x,b];
plot(x);
%axis([0,interv,0,5]);
ylim(‘auto’);
grid
t=t+passo;
drawnow;
end
Method 2
clear all
clc
%User Defined Properties
a = arduino(‘COM5′,’ProMini328_5v’); % define the Arduino Communication port
plotTitle = ‘Arduino Data Log’; % plot title
xLabel = ‘Elapsed Time (s)’; % x-axis label
yLabel = ‘Voltage’; % y-axis label
legend1 = ‘Optical Channel 1’;
legend2 = ‘Optical Channel 2’;
yMax = 40 %y Maximum Value
yMin = 0 %y minimum Value
plotGrid = ‘on’; % ‘off’ to turn off grid
min = 0; % set y-min
max = 40; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
%plotGraph = plot(time,data,’-r’ ) % every AnalogRead needs to be on its own Plotgraph
plotGraph1 = plot(time,data1,’-b’)
hold on %hold on makes sure all of the channels are plotted
plotGraph2 = plot(time, data2,’-g’ )
title(plotTitle,’FontSize’,15);
xlabel(xLabel,’FontSize’,15);
ylabel(yLabel,’FontSize’,15);
legend(legend1,legend2);
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph1) %Loop when Plot is Active will run until plot is closed
%dat = a.analogRead(0)* 0.48875855327; %Data from the arduino
%dat1 = a.analogRead(2)* 0.48875855327;
%dat2 = a.analogRead(3)* 0.48875855327;
dat1 = readVoltage(a,’A2′);
dat2 = readVoltage(a,’A3′);
count = count + 1;
time(count) = toc;
%data(count) = dat(1);
data1(count) = dat1(1)
data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
%set(plotGraph,’XData’,time,’YData’,data);
set(plotGraph1,’XData’,time,’YData’,data1);
set(plotGraph2,’XData’,time,’YData’,data2);
%x = linspace(0,100,10000);
xlim([0 30]);
%xticks(‘auto’);
ylim(‘auto’);
%axis([time(count) time(count)+10 min max]);
%axis([0 time(count) 1 5]);
%xlim([max(0,time(count)-0.1) max(10,time(count)-0.1)]);
%ylim(min,max);
%Update the graph
pause(delay);
end
delete(a);Hi,
I meet a problem when plotting data from Arduino to Matlab, where the x axis is increasing continously and cause the compression of plot. I want to let the x axis auto-scroll, something like axis(t,t+dx,y1,y2). I’ve tried two ways plotting the data, shown below. Is there any other methods to make the x axis auto-scrolling? Thank you in advance!
Method 1
%Method 1
clear all
a = arduino(‘COM5′,’ProMini328_5v’);
%interv = 10;
passo = 1;
t=1;
x=0;
%while(t<interv)
while(t)
b=a.readVoltage(‘A3’);
x=[x,b];
plot(x);
%axis([0,interv,0,5]);
ylim(‘auto’);
grid
t=t+passo;
drawnow;
end
Method 2
clear all
clc
%User Defined Properties
a = arduino(‘COM5′,’ProMini328_5v’); % define the Arduino Communication port
plotTitle = ‘Arduino Data Log’; % plot title
xLabel = ‘Elapsed Time (s)’; % x-axis label
yLabel = ‘Voltage’; % y-axis label
legend1 = ‘Optical Channel 1’;
legend2 = ‘Optical Channel 2’;
yMax = 40 %y Maximum Value
yMin = 0 %y minimum Value
plotGrid = ‘on’; % ‘off’ to turn off grid
min = 0; % set y-min
max = 40; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
%plotGraph = plot(time,data,’-r’ ) % every AnalogRead needs to be on its own Plotgraph
plotGraph1 = plot(time,data1,’-b’)
hold on %hold on makes sure all of the channels are plotted
plotGraph2 = plot(time, data2,’-g’ )
title(plotTitle,’FontSize’,15);
xlabel(xLabel,’FontSize’,15);
ylabel(yLabel,’FontSize’,15);
legend(legend1,legend2);
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph1) %Loop when Plot is Active will run until plot is closed
%dat = a.analogRead(0)* 0.48875855327; %Data from the arduino
%dat1 = a.analogRead(2)* 0.48875855327;
%dat2 = a.analogRead(3)* 0.48875855327;
dat1 = readVoltage(a,’A2′);
dat2 = readVoltage(a,’A3′);
count = count + 1;
time(count) = toc;
%data(count) = dat(1);
data1(count) = dat1(1)
data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
%set(plotGraph,’XData’,time,’YData’,data);
set(plotGraph1,’XData’,time,’YData’,data1);
set(plotGraph2,’XData’,time,’YData’,data2);
%x = linspace(0,100,10000);
xlim([0 30]);
%xticks(‘auto’);
ylim(‘auto’);
%axis([time(count) time(count)+10 min max]);
%axis([0 time(count) 1 5]);
%xlim([max(0,time(count)-0.1) max(10,time(count)-0.1)]);
%ylim(min,max);
%Update the graph
pause(delay);
end
delete(a); Hi,
I meet a problem when plotting data from Arduino to Matlab, where the x axis is increasing continously and cause the compression of plot. I want to let the x axis auto-scroll, something like axis(t,t+dx,y1,y2). I’ve tried two ways plotting the data, shown below. Is there any other methods to make the x axis auto-scrolling? Thank you in advance!
Method 1
%Method 1
clear all
a = arduino(‘COM5′,’ProMini328_5v’);
%interv = 10;
passo = 1;
t=1;
x=0;
%while(t<interv)
while(t)
b=a.readVoltage(‘A3’);
x=[x,b];
plot(x);
%axis([0,interv,0,5]);
ylim(‘auto’);
grid
t=t+passo;
drawnow;
end
Method 2
clear all
clc
%User Defined Properties
a = arduino(‘COM5′,’ProMini328_5v’); % define the Arduino Communication port
plotTitle = ‘Arduino Data Log’; % plot title
xLabel = ‘Elapsed Time (s)’; % x-axis label
yLabel = ‘Voltage’; % y-axis label
legend1 = ‘Optical Channel 1’;
legend2 = ‘Optical Channel 2’;
yMax = 40 %y Maximum Value
yMin = 0 %y minimum Value
plotGrid = ‘on’; % ‘off’ to turn off grid
min = 0; % set y-min
max = 40; % set y-max
delay = .01; % make sure sample faster than resolution
%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;
%Set up Plot
%plotGraph = plot(time,data,’-r’ ) % every AnalogRead needs to be on its own Plotgraph
plotGraph1 = plot(time,data1,’-b’)
hold on %hold on makes sure all of the channels are plotted
plotGraph2 = plot(time, data2,’-g’ )
title(plotTitle,’FontSize’,15);
xlabel(xLabel,’FontSize’,15);
ylabel(yLabel,’FontSize’,15);
legend(legend1,legend2);
axis([yMin yMax min max]);
grid(plotGrid);
tic
while ishandle(plotGraph1) %Loop when Plot is Active will run until plot is closed
%dat = a.analogRead(0)* 0.48875855327; %Data from the arduino
%dat1 = a.analogRead(2)* 0.48875855327;
%dat2 = a.analogRead(3)* 0.48875855327;
dat1 = readVoltage(a,’A2′);
dat2 = readVoltage(a,’A3′);
count = count + 1;
time(count) = toc;
%data(count) = dat(1);
data1(count) = dat1(1)
data2(count) = dat2(1)
%This is the magic code
%Using plot will slow down the sampling time.. At times to over 20
%seconds per sample!
%set(plotGraph,’XData’,time,’YData’,data);
set(plotGraph1,’XData’,time,’YData’,data1);
set(plotGraph2,’XData’,time,’YData’,data2);
%x = linspace(0,100,10000);
xlim([0 30]);
%xticks(‘auto’);
ylim(‘auto’);
%axis([time(count) time(count)+10 min max]);
%axis([0 time(count) 1 5]);
%xlim([max(0,time(count)-0.1) max(10,time(count)-0.1)]);
%ylim(min,max);
%Update the graph
pause(delay);
end
delete(a); arduino, autoscroll scroll plot live plot MATLAB Answers — New Questions
help with bvp4c error
Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset(‘stats’,’on’,’RelTol’,1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title(‘sigma vs r’)
xlabel(‘r’)
ylabel(‘sigma’)
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title(‘f vs r’)
xlabel(‘r’)
ylabel(‘f’)
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title(‘m vs r’)
xlabel(‘r’)
ylabel(‘m’)
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title(‘g vs r’)
xlabel(‘r’)
ylabel(‘g’)
end
end
% ————————————————————————–
function dfdr = bsode(r, y)
w = 0.817;
N = 1 – 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)];
end
% ————————————————————————–
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) – 0.394
ya(2) – 0.394
ya(3) – 0
ya(4) – 0
yb(1) – 1
yb(2) – 0
yb(3) – 0.745
yb(4) – 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options);Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset(‘stats’,’on’,’RelTol’,1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title(‘sigma vs r’)
xlabel(‘r’)
ylabel(‘sigma’)
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title(‘f vs r’)
xlabel(‘r’)
ylabel(‘f’)
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title(‘m vs r’)
xlabel(‘r’)
ylabel(‘m’)
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title(‘g vs r’)
xlabel(‘r’)
ylabel(‘g’)
end
end
% ————————————————————————–
function dfdr = bsode(r, y)
w = 0.817;
N = 1 – 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)];
end
% ————————————————————————–
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) – 0.394
ya(2) – 0.394
ya(3) – 0
ya(4) – 0
yb(1) – 1
yb(2) – 0
yb(3) – 0.745
yb(4) – 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options); Hello! I am trying to solve a system of four coupled differential equation with two-point boundary conditions. I am getting errors and i am new to this, so i dont understand. Please help me fix it.
function proca_star
clear;
clc;
format long;
infinity = 10;
w=0.817;
x_init=1e-5:0.01:infinity;
global phi_c
for phi_c=[0.394 0.394 0 0]
%solinit = bvpinit(linspace(1e-5,infinity,1000),[1 1 phi_c 0],omega);
solinit = bvpinit(x_init,[1 1 phi_c 0],w);
options = bvpset(‘stats’,’on’,’RelTol’,1e-6);
%condition=true;
%while condition
sol = bvp4c(@bsode,@bsbc,solinit,options);
%condition = sol.stats.maxerr >= 1e-5;
%end
r_data = sol.x;
f = sol.y;
% Plotting the results
figure(1)
plot(r_data, f(1,:));
axis([0 infinity 0 1.5]);
title(‘sigma vs r’)
xlabel(‘r’)
ylabel(‘sigma’)
figure(2)
plot(r_data, f(2,:));
axis([0 infinity -0.5 1]);
title(‘f vs r’)
xlabel(‘r’)
ylabel(‘f’)
figure(3)
plot(r_data, f(3,:));
axis([0 infinity 0 1]);
title(‘m vs r’)
xlabel(‘r’)
ylabel(‘m’)
figure(4)
plot(r_data, f(4,:));
axis([0 infinity -0.5 1.5]);
title(‘g vs r’)
xlabel(‘r’)
ylabel(‘g’)
end
end
% ————————————————————————–
function dfdr = bsode(r, y)
w = 0.817;
N = 1 – 2 * y(3) / r;
dfdr = [4 * pi * r * 0.745 * (y(4)^2 + y(2)^2 / (N^2 * y(1)^2))
w * y(4) – 0.745 * y(1)^2 * N * y(4) / w
4 * pi * r^2 * (((0.745 * y(1)^2 * N^2 * y(4)^2)^2) / (2 * y(1)^2 * w^2) + 0.5 * 0.745 * (y(4)^2 * N + y(2)^2 / (N * y(1)^2)))
r^2 * y(2) * w / (y(1)^2 * N^2) – 2 * y(4)];
end
% ————————————————————————–
function res = bsbc(ya, yb)
global phi_c
res = [ya(1) – 0.394
ya(2) – 0.394
ya(3) – 0
ya(4) – 0
yb(1) – 1
yb(2) – 0
yb(3) – 0.745
yb(4) – 0];
end
Here is the error shown:
Error using proca_star>bsode
Too many input arguments.
Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in proca_star (line 22)
sol = bvp4c(@bsode,@bsbc,solinit,options); bvp4c, boundary value problem, coupled odes, error MATLAB Answers — New Questions
Time series – How to use a loop
Hi, I’m working on a timeseries as you can see. I can canculate my results from 0-2 years and after that from 0-3 years until i reach the 20 years. Do you how to aytomatic this procces only by using a loop ?
The step to go from 0 year to 2 is by default 1 day.
Also i don’t know how i can put my data in a loop so everytime i’m gonna use a loop fow an extra year there will be raised by 365.25 daysHi, I’m working on a timeseries as you can see. I can canculate my results from 0-2 years and after that from 0-3 years until i reach the 20 years. Do you how to aytomatic this procces only by using a loop ?
The step to go from 0 year to 2 is by default 1 day.
Also i don’t know how i can put my data in a loop so everytime i’m gonna use a loop fow an extra year there will be raised by 365.25 days Hi, I’m working on a timeseries as you can see. I can canculate my results from 0-2 years and after that from 0-3 years until i reach the 20 years. Do you how to aytomatic this procces only by using a loop ?
The step to go from 0 year to 2 is by default 1 day.
Also i don’t know how i can put my data in a loop so everytime i’m gonna use a loop fow an extra year there will be raised by 365.25 days loop, time series MATLAB Answers — New Questions
How to use tcpclient instead of tcpip with icdevice
I am using instrfind and tcpip to create interface object. I am pasing this interface object in icdevice to create object of my matlab intrument device driver. As, instrfind and tcpip will be removed in future release, how can I modify my code to use my instrument device driver? If I replace tcpip with tcpclient then I cannot use icdevice to create object of my intrument device driver. Refer below code which I am using.
% Create a TCPIP object.
interfaceObj = instrfind(‘Type’, ‘tcpip’, ‘RemoteHost’, ‘127.0.0.1’, ‘RemotePort’, 1234, ‘Tag’, ”);
% Create the TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = tcpip(‘127.0.0.1’, 1234);
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice(‘my_driver.mdd’, interfaceObj);
% Connect device object to hardware.
connect(deviceObj);I am using instrfind and tcpip to create interface object. I am pasing this interface object in icdevice to create object of my matlab intrument device driver. As, instrfind and tcpip will be removed in future release, how can I modify my code to use my instrument device driver? If I replace tcpip with tcpclient then I cannot use icdevice to create object of my intrument device driver. Refer below code which I am using.
% Create a TCPIP object.
interfaceObj = instrfind(‘Type’, ‘tcpip’, ‘RemoteHost’, ‘127.0.0.1’, ‘RemotePort’, 1234, ‘Tag’, ”);
% Create the TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = tcpip(‘127.0.0.1’, 1234);
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice(‘my_driver.mdd’, interfaceObj);
% Connect device object to hardware.
connect(deviceObj); I am using instrfind and tcpip to create interface object. I am pasing this interface object in icdevice to create object of my matlab intrument device driver. As, instrfind and tcpip will be removed in future release, how can I modify my code to use my instrument device driver? If I replace tcpip with tcpclient then I cannot use icdevice to create object of my intrument device driver. Refer below code which I am using.
% Create a TCPIP object.
interfaceObj = instrfind(‘Type’, ‘tcpip’, ‘RemoteHost’, ‘127.0.0.1’, ‘RemotePort’, 1234, ‘Tag’, ”);
% Create the TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = tcpip(‘127.0.0.1’, 1234);
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice(‘my_driver.mdd’, interfaceObj);
% Connect device object to hardware.
connect(deviceObj); instrfind, tcpip, removed in future release, instrument device driver MATLAB Answers — New Questions