Tag Archives: matlab
Calling multiple functions from inside one
Okay fellow coders, I am assembling a bunch of puzzle pieces to form a picture but I am having difficulty… I have a bunch of functions I’ve created that each do specific tasks. I am now trying to call them from the "final" function to do some calculations. I have a flow chart but I’m just not sure how to call multiple functions and have them perform their designated task in the correct manner. The functions are:
% Function 1
function m_kg=lb2kg_ZLKW(w_lb)
m_kg=1/2.2.*w_lb;
end
% Code used to call function:
% w_lb=0:1:100; m_kg=lb2kg_ZLKW(w_lb);
% Function 2
function x0=getx0_ZLKW(k,F)
x0=F./k;
end
% Code used to call function:
% k=linspace(1,10,100); F=1:100; x0=getx0_ZLKW(k,F);
% Function 3
function wn=natfreq_ZLKW(k,m_kg)
wn=sqrt(k./m_kg); % Natural frequency of the system
end
% Code used to call function:
% k=linspace(1,10,100); m_kg=1:100; wn=natfreq_ZLKW(k,m_kg);
% Function 4
function [zeta,wd]=damp_ZLKW(c,m_kg,wn)
zeta=c./(2.*wn.*m_kg);
wd=wn.*sqrt(1-zeta.^2);
end
% Code used to call function:
% c=rand(1,100)*(1); m_kg=1:100; wn=rand(1,100)*1; [zeta,wd]=damp_ZLKW(c,m_kg,wn)
% Function 5
function xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
s1=-wnN*zetaN-wdN*1i;
s2=-wnN*zetaN+wdN*1i;
C1=-((s2*x0N)/s1-s2);
C2=x0N-C1;
xN=C1*exp(s1*t)+C2*exp(s2*t);
end
% Code used to call function: (All of which are scalars except time, t)
% zetaN=0.25; wnN=0.5; wdN=0.75; x0N=10; t=linspace(1,10,100); xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
All of these functions are in their own seperate .m files in the same folder I am calling them from in the final function. The final function will be something like:
% Final function
function [wn,zeta] = main24S_ZLKW(w,k,c,F)
% Trying to figure out how to start this here based on my flowchart
end
I know it seems like a lot, but I am just trying to get the ball rolling and the brain juices flowing here.Okay fellow coders, I am assembling a bunch of puzzle pieces to form a picture but I am having difficulty… I have a bunch of functions I’ve created that each do specific tasks. I am now trying to call them from the "final" function to do some calculations. I have a flow chart but I’m just not sure how to call multiple functions and have them perform their designated task in the correct manner. The functions are:
% Function 1
function m_kg=lb2kg_ZLKW(w_lb)
m_kg=1/2.2.*w_lb;
end
% Code used to call function:
% w_lb=0:1:100; m_kg=lb2kg_ZLKW(w_lb);
% Function 2
function x0=getx0_ZLKW(k,F)
x0=F./k;
end
% Code used to call function:
% k=linspace(1,10,100); F=1:100; x0=getx0_ZLKW(k,F);
% Function 3
function wn=natfreq_ZLKW(k,m_kg)
wn=sqrt(k./m_kg); % Natural frequency of the system
end
% Code used to call function:
% k=linspace(1,10,100); m_kg=1:100; wn=natfreq_ZLKW(k,m_kg);
% Function 4
function [zeta,wd]=damp_ZLKW(c,m_kg,wn)
zeta=c./(2.*wn.*m_kg);
wd=wn.*sqrt(1-zeta.^2);
end
% Code used to call function:
% c=rand(1,100)*(1); m_kg=1:100; wn=rand(1,100)*1; [zeta,wd]=damp_ZLKW(c,m_kg,wn)
% Function 5
function xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
s1=-wnN*zetaN-wdN*1i;
s2=-wnN*zetaN+wdN*1i;
C1=-((s2*x0N)/s1-s2);
C2=x0N-C1;
xN=C1*exp(s1*t)+C2*exp(s2*t);
end
% Code used to call function: (All of which are scalars except time, t)
% zetaN=0.25; wnN=0.5; wdN=0.75; x0N=10; t=linspace(1,10,100); xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
All of these functions are in their own seperate .m files in the same folder I am calling them from in the final function. The final function will be something like:
% Final function
function [wn,zeta] = main24S_ZLKW(w,k,c,F)
% Trying to figure out how to start this here based on my flowchart
end
I know it seems like a lot, but I am just trying to get the ball rolling and the brain juices flowing here. Okay fellow coders, I am assembling a bunch of puzzle pieces to form a picture but I am having difficulty… I have a bunch of functions I’ve created that each do specific tasks. I am now trying to call them from the "final" function to do some calculations. I have a flow chart but I’m just not sure how to call multiple functions and have them perform their designated task in the correct manner. The functions are:
% Function 1
function m_kg=lb2kg_ZLKW(w_lb)
m_kg=1/2.2.*w_lb;
end
% Code used to call function:
% w_lb=0:1:100; m_kg=lb2kg_ZLKW(w_lb);
% Function 2
function x0=getx0_ZLKW(k,F)
x0=F./k;
end
% Code used to call function:
% k=linspace(1,10,100); F=1:100; x0=getx0_ZLKW(k,F);
% Function 3
function wn=natfreq_ZLKW(k,m_kg)
wn=sqrt(k./m_kg); % Natural frequency of the system
end
% Code used to call function:
% k=linspace(1,10,100); m_kg=1:100; wn=natfreq_ZLKW(k,m_kg);
% Function 4
function [zeta,wd]=damp_ZLKW(c,m_kg,wn)
zeta=c./(2.*wn.*m_kg);
wd=wn.*sqrt(1-zeta.^2);
end
% Code used to call function:
% c=rand(1,100)*(1); m_kg=1:100; wn=rand(1,100)*1; [zeta,wd]=damp_ZLKW(c,m_kg,wn)
% Function 5
function xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
s1=-wnN*zetaN-wdN*1i;
s2=-wnN*zetaN+wdN*1i;
C1=-((s2*x0N)/s1-s2);
C2=x0N-C1;
xN=C1*exp(s1*t)+C2*exp(s2*t);
end
% Code used to call function: (All of which are scalars except time, t)
% zetaN=0.25; wnN=0.5; wdN=0.75; x0N=10; t=linspace(1,10,100); xN=motionN_ZLKW(zetaN,wnN,wdN,x0N,t)
All of these functions are in their own seperate .m files in the same folder I am calling them from in the final function. The final function will be something like:
% Final function
function [wn,zeta] = main24S_ZLKW(w,k,c,F)
% Trying to figure out how to start this here based on my flowchart
end
I know it seems like a lot, but I am just trying to get the ball rolling and the brain juices flowing here. functions MATLAB Answers — New Questions
I’m having an issue defining the initial conditions for solving a system of differential equations
syms x Q M w(x) th(x)
%Givens
l = 10;
E = 100;
G = 40;
I = 0.1;
A = 1;
q = -1;
m = 0;
assume(0 <= x <= l);
assume(x,"real");
%Constituative Equations
Q = G*A*(diff(w,x)-th); %shear force
M = E*I*diff(th,x); %bending moment
%GDE
GDE1 = diff(M,x) + Q + m == 0;
GDE2 = diff(Q,x) + q == 0;
%BC’s (Pinned at both ends)
cond = [M(0)==0,M(l)==0,Q(0)==-q*l/2,Q(l)==-q*l/2, w(0)==0, w(l)==0];
%Set up the differential equations
eqns = [GDE1,GDE2];
[w_sol, th_sol] = dsolve(eqns, cond);
disp("w(x)=");
disp(simplify(w_sol));
disp("theta(x) =");
disp(simplify(th_sol));
I’m having difficulty defining the initial conditions to solve this system of equations. Here is the error I keep getting:
Error using mupadengine/feval_internal
Invalid initial conditions.
Error in dsolve>mupadDsolve (line 334)
T = feval_internal(symengine,’symobj::dsolve’,sys,x,options);
Error in dsolve (line 203)
sol = mupadDsolve(args, options);
Error in Problem_1 (line 36)
[w_sol, th_sol] = dsolve(eqns, cond);
Related documentationsyms x Q M w(x) th(x)
%Givens
l = 10;
E = 100;
G = 40;
I = 0.1;
A = 1;
q = -1;
m = 0;
assume(0 <= x <= l);
assume(x,"real");
%Constituative Equations
Q = G*A*(diff(w,x)-th); %shear force
M = E*I*diff(th,x); %bending moment
%GDE
GDE1 = diff(M,x) + Q + m == 0;
GDE2 = diff(Q,x) + q == 0;
%BC’s (Pinned at both ends)
cond = [M(0)==0,M(l)==0,Q(0)==-q*l/2,Q(l)==-q*l/2, w(0)==0, w(l)==0];
%Set up the differential equations
eqns = [GDE1,GDE2];
[w_sol, th_sol] = dsolve(eqns, cond);
disp("w(x)=");
disp(simplify(w_sol));
disp("theta(x) =");
disp(simplify(th_sol));
I’m having difficulty defining the initial conditions to solve this system of equations. Here is the error I keep getting:
Error using mupadengine/feval_internal
Invalid initial conditions.
Error in dsolve>mupadDsolve (line 334)
T = feval_internal(symengine,’symobj::dsolve’,sys,x,options);
Error in dsolve (line 203)
sol = mupadDsolve(args, options);
Error in Problem_1 (line 36)
[w_sol, th_sol] = dsolve(eqns, cond);
Related documentation syms x Q M w(x) th(x)
%Givens
l = 10;
E = 100;
G = 40;
I = 0.1;
A = 1;
q = -1;
m = 0;
assume(0 <= x <= l);
assume(x,"real");
%Constituative Equations
Q = G*A*(diff(w,x)-th); %shear force
M = E*I*diff(th,x); %bending moment
%GDE
GDE1 = diff(M,x) + Q + m == 0;
GDE2 = diff(Q,x) + q == 0;
%BC’s (Pinned at both ends)
cond = [M(0)==0,M(l)==0,Q(0)==-q*l/2,Q(l)==-q*l/2, w(0)==0, w(l)==0];
%Set up the differential equations
eqns = [GDE1,GDE2];
[w_sol, th_sol] = dsolve(eqns, cond);
disp("w(x)=");
disp(simplify(w_sol));
disp("theta(x) =");
disp(simplify(th_sol));
I’m having difficulty defining the initial conditions to solve this system of equations. Here is the error I keep getting:
Error using mupadengine/feval_internal
Invalid initial conditions.
Error in dsolve>mupadDsolve (line 334)
T = feval_internal(symengine,’symobj::dsolve’,sys,x,options);
Error in dsolve (line 203)
sol = mupadDsolve(args, options);
Error in Problem_1 (line 36)
[w_sol, th_sol] = dsolve(eqns, cond);
Related documentation dsolve, differential equations, initial conditions, system of equations, invalid initial conditions, mupadengine error, feval_internal error MATLAB Answers — New Questions
How to find Laplace of the second order nonlinear time delayed term?
Post Content Post Content laplace, nonlinear delay MATLAB Answers — New Questions
How do I put map_info into customized enviwrite matlab code?
This is my map_info
MapCellsReference with properties:
XWorldLimits: [699960 809760]
YWorldLimits: [3190200 3300000]
RasterSize: [5490 5490]
RasterInterpretation: ‘cells’
ColumnsStartFrom: ‘north’
RowsStartFrom: ‘west’
CellExtentInWorldX: 20
CellExtentInWorldY: 20
RasterExtentInWorldX: 109800
RasterExtentInWorldY: 109800
XIntrinsicLimits: [0.5 5490.5]
YIntrinsicLimits: [0.5 5490.5]
TransformationType: ‘rectilinear’
CoordinateSystemType: ‘planar’
ProjectedCRS: [1×1 projcrs]
I want to put this information into enviwrite code which is as follows
fprintf(fid, ‘ENVIn’);
fprintf(fid, ‘description = {n’);
fprintf(fid, ‘Exported from MATLAB with coordinate and wavelength info}n’);
fprintf(fid, ‘%s %i n’, elements{1}, im_size(2)); % samples
fprintf(fid, ‘%s %i n’, elements{2}, im_size(1)); % lines
fprintf(fid, ‘%s %i n’, elements{3}, im_size(3)); % bands
fprintf(fid, ‘%s %i n’, elements{4}, t); % data type
fprintf(fid, ‘interleave = bsqn’);
fprintf(fid, ‘map info = {%s}n’, coordinate_information.map_info);
fprintf(fid, ‘projection info = {%s}n’, coordinate_information.projection_info);
fprintf(fid, ‘wavelength = {‘);
fprintf(fid, ‘%g, ‘, wavelength_data(1:end-1));
fprintf(fid, ‘%g}n’, wavelength_data(end));
fclose(fid);
I request you to please put above mentioned map_info into this customized enviwrite code. Looking forward for your kind cooperation.
DevendraThis is my map_info
MapCellsReference with properties:
XWorldLimits: [699960 809760]
YWorldLimits: [3190200 3300000]
RasterSize: [5490 5490]
RasterInterpretation: ‘cells’
ColumnsStartFrom: ‘north’
RowsStartFrom: ‘west’
CellExtentInWorldX: 20
CellExtentInWorldY: 20
RasterExtentInWorldX: 109800
RasterExtentInWorldY: 109800
XIntrinsicLimits: [0.5 5490.5]
YIntrinsicLimits: [0.5 5490.5]
TransformationType: ‘rectilinear’
CoordinateSystemType: ‘planar’
ProjectedCRS: [1×1 projcrs]
I want to put this information into enviwrite code which is as follows
fprintf(fid, ‘ENVIn’);
fprintf(fid, ‘description = {n’);
fprintf(fid, ‘Exported from MATLAB with coordinate and wavelength info}n’);
fprintf(fid, ‘%s %i n’, elements{1}, im_size(2)); % samples
fprintf(fid, ‘%s %i n’, elements{2}, im_size(1)); % lines
fprintf(fid, ‘%s %i n’, elements{3}, im_size(3)); % bands
fprintf(fid, ‘%s %i n’, elements{4}, t); % data type
fprintf(fid, ‘interleave = bsqn’);
fprintf(fid, ‘map info = {%s}n’, coordinate_information.map_info);
fprintf(fid, ‘projection info = {%s}n’, coordinate_information.projection_info);
fprintf(fid, ‘wavelength = {‘);
fprintf(fid, ‘%g, ‘, wavelength_data(1:end-1));
fprintf(fid, ‘%g}n’, wavelength_data(end));
fclose(fid);
I request you to please put above mentioned map_info into this customized enviwrite code. Looking forward for your kind cooperation.
Devendra This is my map_info
MapCellsReference with properties:
XWorldLimits: [699960 809760]
YWorldLimits: [3190200 3300000]
RasterSize: [5490 5490]
RasterInterpretation: ‘cells’
ColumnsStartFrom: ‘north’
RowsStartFrom: ‘west’
CellExtentInWorldX: 20
CellExtentInWorldY: 20
RasterExtentInWorldX: 109800
RasterExtentInWorldY: 109800
XIntrinsicLimits: [0.5 5490.5]
YIntrinsicLimits: [0.5 5490.5]
TransformationType: ‘rectilinear’
CoordinateSystemType: ‘planar’
ProjectedCRS: [1×1 projcrs]
I want to put this information into enviwrite code which is as follows
fprintf(fid, ‘ENVIn’);
fprintf(fid, ‘description = {n’);
fprintf(fid, ‘Exported from MATLAB with coordinate and wavelength info}n’);
fprintf(fid, ‘%s %i n’, elements{1}, im_size(2)); % samples
fprintf(fid, ‘%s %i n’, elements{2}, im_size(1)); % lines
fprintf(fid, ‘%s %i n’, elements{3}, im_size(3)); % bands
fprintf(fid, ‘%s %i n’, elements{4}, t); % data type
fprintf(fid, ‘interleave = bsqn’);
fprintf(fid, ‘map info = {%s}n’, coordinate_information.map_info);
fprintf(fid, ‘projection info = {%s}n’, coordinate_information.projection_info);
fprintf(fid, ‘wavelength = {‘);
fprintf(fid, ‘%g, ‘, wavelength_data(1:end-1));
fprintf(fid, ‘%g}n’, wavelength_data(end));
fclose(fid);
I request you to please put above mentioned map_info into this customized enviwrite code. Looking forward for your kind cooperation.
Devendra how do i put map_info into customized enviwrite ? MATLAB Answers — New Questions
Extracting Property Values from Property Functions
I’m encountering an error in MATLAB while attempting to extract `x` and `y` values from property functions. The property functions I’m working with look like this:
– `
@(P) (subs(P, x, 2) == 0)
`
– `
@(P) (subs(P, x, 6) == 0)
`
My goal is to extract the `x` value where the condition is met and then use that value to find the corresponding `y` by substituting into a simple polynomial. However, I’m encountering the following error:
Error using isSubspacePoly>get_property_values (line 208)
No valid x value found for the given property function.
Here’s the code snippet for the `get_property_values` function:
function [x_val, y_val] = get_property_values(propertyFcn)
syms x; % Symbolic variable
P = x; % Simple polynomial to apply the property function
% Get the condition from the property function
eqn = propertyFcn(P);
% Solve for x to meet the property condition
x_val = double(solve(eqn, x));
if isempty(x_val) % Handle cases with no valid solution
error(‘No valid x value found for the given property function.’);
end
% Compute y by substituting x_val into the polynomial
y_val = double(subs(P, x, x_val));
if isempty(y_val) % Ensure valid y_val
error(‘No valid y value obtained from the given property function.’);
end
end
The error occurs when there’s no valid solution for `x_val`. If I can’t get `x`, then I can’t find `y`. What might be causing this? Could it be an issue with the property function or something else? Any suggestions on how to extract `x` and `y` values correctly would be helpful.I’m encountering an error in MATLAB while attempting to extract `x` and `y` values from property functions. The property functions I’m working with look like this:
– `
@(P) (subs(P, x, 2) == 0)
`
– `
@(P) (subs(P, x, 6) == 0)
`
My goal is to extract the `x` value where the condition is met and then use that value to find the corresponding `y` by substituting into a simple polynomial. However, I’m encountering the following error:
Error using isSubspacePoly>get_property_values (line 208)
No valid x value found for the given property function.
Here’s the code snippet for the `get_property_values` function:
function [x_val, y_val] = get_property_values(propertyFcn)
syms x; % Symbolic variable
P = x; % Simple polynomial to apply the property function
% Get the condition from the property function
eqn = propertyFcn(P);
% Solve for x to meet the property condition
x_val = double(solve(eqn, x));
if isempty(x_val) % Handle cases with no valid solution
error(‘No valid x value found for the given property function.’);
end
% Compute y by substituting x_val into the polynomial
y_val = double(subs(P, x, x_val));
if isempty(y_val) % Ensure valid y_val
error(‘No valid y value obtained from the given property function.’);
end
end
The error occurs when there’s no valid solution for `x_val`. If I can’t get `x`, then I can’t find `y`. What might be causing this? Could it be an issue with the property function or something else? Any suggestions on how to extract `x` and `y` values correctly would be helpful. I’m encountering an error in MATLAB while attempting to extract `x` and `y` values from property functions. The property functions I’m working with look like this:
– `
@(P) (subs(P, x, 2) == 0)
`
– `
@(P) (subs(P, x, 6) == 0)
`
My goal is to extract the `x` value where the condition is met and then use that value to find the corresponding `y` by substituting into a simple polynomial. However, I’m encountering the following error:
Error using isSubspacePoly>get_property_values (line 208)
No valid x value found for the given property function.
Here’s the code snippet for the `get_property_values` function:
function [x_val, y_val] = get_property_values(propertyFcn)
syms x; % Symbolic variable
P = x; % Simple polynomial to apply the property function
% Get the condition from the property function
eqn = propertyFcn(P);
% Solve for x to meet the property condition
x_val = double(solve(eqn, x));
if isempty(x_val) % Handle cases with no valid solution
error(‘No valid x value found for the given property function.’);
end
% Compute y by substituting x_val into the polynomial
y_val = double(subs(P, x, x_val));
if isempty(y_val) % Ensure valid y_val
error(‘No valid y value obtained from the given property function.’);
end
end
The error occurs when there’s no valid solution for `x_val`. If I can’t get `x`, then I can’t find `y`. What might be causing this? Could it be an issue with the property function or something else? Any suggestions on how to extract `x` and `y` values correctly would be helpful. matlab code, matlab, matlab coder, matlab function MATLAB Answers — New Questions
simmechanics link with inventor2025 does`t appear at add ins
Idid the step by step in https://la.mathworks.com/help/sm/ug/installing-and-linking-simmechanics-link-software.html , to install Mimscape Multibody plugin associate with Inventor 2025, all the steps was sucessfully, but in Inventor add +, the tool not appear, them I can`t export any CAD. It is Inventor 2025 Compatible whit MATLAB r2023a? or any idea to how can fixed that issue?Idid the step by step in https://la.mathworks.com/help/sm/ug/installing-and-linking-simmechanics-link-software.html , to install Mimscape Multibody plugin associate with Inventor 2025, all the steps was sucessfully, but in Inventor add +, the tool not appear, them I can`t export any CAD. It is Inventor 2025 Compatible whit MATLAB r2023a? or any idea to how can fixed that issue? Idid the step by step in https://la.mathworks.com/help/sm/ug/installing-and-linking-simmechanics-link-software.html , to install Mimscape Multibody plugin associate with Inventor 2025, all the steps was sucessfully, but in Inventor add +, the tool not appear, them I can`t export any CAD. It is Inventor 2025 Compatible whit MATLAB r2023a? or any idea to how can fixed that issue? inventor, autodesk, smlink MATLAB Answers — New Questions
Help with updating for loop
Hi all,I have a problem with the following sample code:
M=[1 2 3 4 5 6 7 8 9 10]
for i=1:length(M)
M(i)=[]
end
My code is not complete, but my problem is that when one row is omitted from the matrix, the size reduces to 9, so the code gets stock with an error to find M(10). Actually, I want to update the cell size in for loop. In my code, I must make some rows empty, I can not keep them. ThanksHi all,I have a problem with the following sample code:
M=[1 2 3 4 5 6 7 8 9 10]
for i=1:length(M)
M(i)=[]
end
My code is not complete, but my problem is that when one row is omitted from the matrix, the size reduces to 9, so the code gets stock with an error to find M(10). Actually, I want to update the cell size in for loop. In my code, I must make some rows empty, I can not keep them. Thanks Hi all,I have a problem with the following sample code:
M=[1 2 3 4 5 6 7 8 9 10]
for i=1:length(M)
M(i)=[]
end
My code is not complete, but my problem is that when one row is omitted from the matrix, the size reduces to 9, so the code gets stock with an error to find M(10). Actually, I want to update the cell size in for loop. In my code, I must make some rows empty, I can not keep them. Thanks for loop MATLAB Answers — New Questions
Convert Python list Type to MATLAB double
Hello All,
I would like to convert the python list type to matlab double.
I have tried the following,
First approach
out = func.getValues() %python function gives a list of [1,2,…n]
out = cell(out(1:end-1));
out = cellfun(@double,out); %outputs type double
Second approach
out = func.getValues() %python function gives a list of [1,2,…n]
out = func.convlisttoarray(out) %python function imports numpy and converts list to array using numpy.array()
out_double = double(out); % outputs type double
Although the length of the list is 1×150, in both the approaches, Matlab is taking a lot of computation time and the system hangs for a while. This is wierd to me, as a couple of days earlier everything worked fine and it could solve the problem in milli seconds.
Could anyone of you please help me with a faster approach to convert the python list to matlab double?
I am using Matlab 2019b.
Thank you in advance.
Cheers,
Sai KrishnaHello All,
I would like to convert the python list type to matlab double.
I have tried the following,
First approach
out = func.getValues() %python function gives a list of [1,2,…n]
out = cell(out(1:end-1));
out = cellfun(@double,out); %outputs type double
Second approach
out = func.getValues() %python function gives a list of [1,2,…n]
out = func.convlisttoarray(out) %python function imports numpy and converts list to array using numpy.array()
out_double = double(out); % outputs type double
Although the length of the list is 1×150, in both the approaches, Matlab is taking a lot of computation time and the system hangs for a while. This is wierd to me, as a couple of days earlier everything worked fine and it could solve the problem in milli seconds.
Could anyone of you please help me with a faster approach to convert the python list to matlab double?
I am using Matlab 2019b.
Thank you in advance.
Cheers,
Sai Krishna Hello All,
I would like to convert the python list type to matlab double.
I have tried the following,
First approach
out = func.getValues() %python function gives a list of [1,2,…n]
out = cell(out(1:end-1));
out = cellfun(@double,out); %outputs type double
Second approach
out = func.getValues() %python function gives a list of [1,2,…n]
out = func.convlisttoarray(out) %python function imports numpy and converts list to array using numpy.array()
out_double = double(out); % outputs type double
Although the length of the list is 1×150, in both the approaches, Matlab is taking a lot of computation time and the system hangs for a while. This is wierd to me, as a couple of days earlier everything worked fine and it could solve the problem in milli seconds.
Could anyone of you please help me with a faster approach to convert the python list to matlab double?
I am using Matlab 2019b.
Thank you in advance.
Cheers,
Sai Krishna python list, double, python matlab, pathon list to double, convert python list MATLAB Answers — New Questions
How can I tune 3 axis of spacecraft with 3 axis PID control for attitude determination (ADCS)?
Hello,
I would like to implement the attitude control with GNC (3 axis euler angles instead of quaternion to be simple) with 3 PID controllers since PID is SISO system. However, after putting the attitude dynamic, the 3 axis are interacted between each other, so it is impossible to tune the 3 axis quite well with auto tuning or manual tuning.
For example, if I change some P or I or D gain in x-axis, it affects the result of the y or z- axis, so it is impossible to tune 3 axis.
In this situation, can how can I control the 3 axis angular rate? should I use different control method such as LQR?
Thank you!Hello,
I would like to implement the attitude control with GNC (3 axis euler angles instead of quaternion to be simple) with 3 PID controllers since PID is SISO system. However, after putting the attitude dynamic, the 3 axis are interacted between each other, so it is impossible to tune the 3 axis quite well with auto tuning or manual tuning.
For example, if I change some P or I or D gain in x-axis, it affects the result of the y or z- axis, so it is impossible to tune 3 axis.
In this situation, can how can I control the 3 axis angular rate? should I use different control method such as LQR?
Thank you! Hello,
I would like to implement the attitude control with GNC (3 axis euler angles instead of quaternion to be simple) with 3 PID controllers since PID is SISO system. However, after putting the attitude dynamic, the 3 axis are interacted between each other, so it is impossible to tune the 3 axis quite well with auto tuning or manual tuning.
For example, if I change some P or I or D gain in x-axis, it affects the result of the y or z- axis, so it is impossible to tune 3 axis.
In this situation, can how can I control the 3 axis angular rate? should I use different control method such as LQR?
Thank you! pid, control, attitude, adcs, satellite MATLAB Answers — New Questions
Modifying the search path is not supported by Matlab Compiler?
Trying to create a Matlab app in R2023b. The deployed application should connect to a Moku:Go device (which is using its own Matlab toolbox) and take some measurements. The app is running smoothly when running from Matlab, but giving an error message when running from the deployed standalone app.
I have looked at the following topic: https://www.mathworks.com/matlabcentral/answers/1786755-modifying-the-search-path-is-not-supported-by-matlab-compiler?s_tid=sug_su
I have added the following line in my Matlab startup code and have made sure that all the required Moku files are embedded during the app deployment:
addpath(genpath(‘C:UsersusernameAppDataRoamingMathWorksMATLAB Add-OnsToolboxesmoku-MATLAB(2)’))
Please advise what can be done to have the deployed app running.Trying to create a Matlab app in R2023b. The deployed application should connect to a Moku:Go device (which is using its own Matlab toolbox) and take some measurements. The app is running smoothly when running from Matlab, but giving an error message when running from the deployed standalone app.
I have looked at the following topic: https://www.mathworks.com/matlabcentral/answers/1786755-modifying-the-search-path-is-not-supported-by-matlab-compiler?s_tid=sug_su
I have added the following line in my Matlab startup code and have made sure that all the required Moku files are embedded during the app deployment:
addpath(genpath(‘C:UsersusernameAppDataRoamingMathWorksMATLAB Add-OnsToolboxesmoku-MATLAB(2)’))
Please advise what can be done to have the deployed app running. Trying to create a Matlab app in R2023b. The deployed application should connect to a Moku:Go device (which is using its own Matlab toolbox) and take some measurements. The app is running smoothly when running from Matlab, but giving an error message when running from the deployed standalone app.
I have looked at the following topic: https://www.mathworks.com/matlabcentral/answers/1786755-modifying-the-search-path-is-not-supported-by-matlab-compiler?s_tid=sug_su
I have added the following line in my Matlab startup code and have made sure that all the required Moku files are embedded during the app deployment:
addpath(genpath(‘C:UsersusernameAppDataRoamingMathWorksMATLAB Add-OnsToolboxesmoku-MATLAB(2)’))
Please advise what can be done to have the deployed app running. appdesigner, moku, search path MATLAB Answers — New Questions
Add lines of text to CNC programming code
Hello, I am trying to generate a code in which after a tool change (depending on the tool) Matlab puts a new line of code with an M7 or M8, for example, within a bunch of text I have this:
N80T16M6
I want Matlab to create a new line with a M7 and M8 like this
N80T16M6
M7
M8
It varies depending on the number after the T (which is the number of the tool) for example T15 would just have M7. Is there a way of programming this? Adding the information of which tool needs what?
Besides this, I want to include in a certain point of the text the stock dimensions, for example (x10::y-5::z-0.1::) just as I wrote it with the parenthesis
and as extra information as I mentioned before this lines of code are within a bunch of lines but always starts with an N number, like this:
Thanks a lot in advance!Hello, I am trying to generate a code in which after a tool change (depending on the tool) Matlab puts a new line of code with an M7 or M8, for example, within a bunch of text I have this:
N80T16M6
I want Matlab to create a new line with a M7 and M8 like this
N80T16M6
M7
M8
It varies depending on the number after the T (which is the number of the tool) for example T15 would just have M7. Is there a way of programming this? Adding the information of which tool needs what?
Besides this, I want to include in a certain point of the text the stock dimensions, for example (x10::y-5::z-0.1::) just as I wrote it with the parenthesis
and as extra information as I mentioned before this lines of code are within a bunch of lines but always starts with an N number, like this:
Thanks a lot in advance! Hello, I am trying to generate a code in which after a tool change (depending on the tool) Matlab puts a new line of code with an M7 or M8, for example, within a bunch of text I have this:
N80T16M6
I want Matlab to create a new line with a M7 and M8 like this
N80T16M6
M7
M8
It varies depending on the number after the T (which is the number of the tool) for example T15 would just have M7. Is there a way of programming this? Adding the information of which tool needs what?
Besides this, I want to include in a certain point of the text the stock dimensions, for example (x10::y-5::z-0.1::) just as I wrote it with the parenthesis
and as extra information as I mentioned before this lines of code are within a bunch of lines but always starts with an N number, like this:
Thanks a lot in advance! cnc, edit code MATLAB Answers — New Questions
Issues with matlab-Fortran interface
Hi,
I’m having issues with some Fortran code we have that uses matlab’s DLLs to open a .mat file. We are using Matlab R2023b. Our Fortran code is built for 64 bit windows.
Our code calls matOpen passing a filename and permission. I’ve looked in our IDE debugger and both of these parameters are valid values. The result is set to a mwpointer variable, which is appropriately sized for 64 bit.
Our code calls into the matlab DLLs that we got from r2023b/bin/win64. The DLLs in turn call into C:/Windows/System32/vcruntime140.dll, which promptly crash on trying to access invalid memory locations. Our vcruntime140.dll version is 14.31.31103.0.
I noticed though that the matlab binary folder mentioned above also holds a vcruntime140.dll file, and it is at version 14.29.30135.0. Do the r2023b matlab-fortran interface DLLs require this specific version of vcruntime140.dll?Hi,
I’m having issues with some Fortran code we have that uses matlab’s DLLs to open a .mat file. We are using Matlab R2023b. Our Fortran code is built for 64 bit windows.
Our code calls matOpen passing a filename and permission. I’ve looked in our IDE debugger and both of these parameters are valid values. The result is set to a mwpointer variable, which is appropriately sized for 64 bit.
Our code calls into the matlab DLLs that we got from r2023b/bin/win64. The DLLs in turn call into C:/Windows/System32/vcruntime140.dll, which promptly crash on trying to access invalid memory locations. Our vcruntime140.dll version is 14.31.31103.0.
I noticed though that the matlab binary folder mentioned above also holds a vcruntime140.dll file, and it is at version 14.29.30135.0. Do the r2023b matlab-fortran interface DLLs require this specific version of vcruntime140.dll? Hi,
I’m having issues with some Fortran code we have that uses matlab’s DLLs to open a .mat file. We are using Matlab R2023b. Our Fortran code is built for 64 bit windows.
Our code calls matOpen passing a filename and permission. I’ve looked in our IDE debugger and both of these parameters are valid values. The result is set to a mwpointer variable, which is appropriately sized for 64 bit.
Our code calls into the matlab DLLs that we got from r2023b/bin/win64. The DLLs in turn call into C:/Windows/System32/vcruntime140.dll, which promptly crash on trying to access invalid memory locations. Our vcruntime140.dll version is 14.31.31103.0.
I noticed though that the matlab binary folder mentioned above also holds a vcruntime140.dll file, and it is at version 14.29.30135.0. Do the r2023b matlab-fortran interface DLLs require this specific version of vcruntime140.dll? fortran, r2023b MATLAB Answers — New Questions
running matlab exe file results in “Too many input arguments. MATLAB:TooManyInputs error”
When compiling a MATLAB (.m) function (main_file below is code) into a standalone executable (.exe) through MATLAB Compiler, the command-line arguments passed to the executable are not being accepted. Instead of parsing the arguments through the getmcruserdata(‘syscommandargs’) function within the compiled MATLAB application, MATLAB is throwing an error, stating there are "Too many input arguments. the following code works fine when i dont pass any args (main_file.exe). however with passign args I get error. Note that I expect when i pass args the disp(‘Not enough arguments received.’); print message but it does not. I made the following function to exe which is named main_file.exe. Running main_file.exe "test1args" "test2args" results in error (Too many input arguments. MATLAB:TooManyInputs). Please help me to resolve it. Thanks.
function main_file
param1 = ‘test1args’;
param2 = ‘test2args’;
if isdeployed
disp("Reading input arguments");
args = getmcruserdata(‘syscommandargs’);
if isempty(args)
disp(‘Not enough arguments received.’);
else
% Parse args
args_cell = strsplit(args{1}, ‘ ‘);
if numel(args_cell) >= 2
param1 = args_cell{1};
disp(param1);
param2 = args_cell{2};
disp(param2);
else
disp(‘more than 2 arguments received.’);
end
end
else
disp(‘Running in MATLAB’);
param1 = ‘test1args’;
disp(‘test2args’);
disp(param1);
param2 = ‘Yes’;
disp(‘param2’);
disp(param2);
end
disp("hello from executable…")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, ‘process’, param2);
disp("process done")
endWhen compiling a MATLAB (.m) function (main_file below is code) into a standalone executable (.exe) through MATLAB Compiler, the command-line arguments passed to the executable are not being accepted. Instead of parsing the arguments through the getmcruserdata(‘syscommandargs’) function within the compiled MATLAB application, MATLAB is throwing an error, stating there are "Too many input arguments. the following code works fine when i dont pass any args (main_file.exe). however with passign args I get error. Note that I expect when i pass args the disp(‘Not enough arguments received.’); print message but it does not. I made the following function to exe which is named main_file.exe. Running main_file.exe "test1args" "test2args" results in error (Too many input arguments. MATLAB:TooManyInputs). Please help me to resolve it. Thanks.
function main_file
param1 = ‘test1args’;
param2 = ‘test2args’;
if isdeployed
disp("Reading input arguments");
args = getmcruserdata(‘syscommandargs’);
if isempty(args)
disp(‘Not enough arguments received.’);
else
% Parse args
args_cell = strsplit(args{1}, ‘ ‘);
if numel(args_cell) >= 2
param1 = args_cell{1};
disp(param1);
param2 = args_cell{2};
disp(param2);
else
disp(‘more than 2 arguments received.’);
end
end
else
disp(‘Running in MATLAB’);
param1 = ‘test1args’;
disp(‘test2args’);
disp(param1);
param2 = ‘Yes’;
disp(‘param2’);
disp(param2);
end
disp("hello from executable…")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, ‘process’, param2);
disp("process done")
end When compiling a MATLAB (.m) function (main_file below is code) into a standalone executable (.exe) through MATLAB Compiler, the command-line arguments passed to the executable are not being accepted. Instead of parsing the arguments through the getmcruserdata(‘syscommandargs’) function within the compiled MATLAB application, MATLAB is throwing an error, stating there are "Too many input arguments. the following code works fine when i dont pass any args (main_file.exe). however with passign args I get error. Note that I expect when i pass args the disp(‘Not enough arguments received.’); print message but it does not. I made the following function to exe which is named main_file.exe. Running main_file.exe "test1args" "test2args" results in error (Too many input arguments. MATLAB:TooManyInputs). Please help me to resolve it. Thanks.
function main_file
param1 = ‘test1args’;
param2 = ‘test2args’;
if isdeployed
disp("Reading input arguments");
args = getmcruserdata(‘syscommandargs’);
if isempty(args)
disp(‘Not enough arguments received.’);
else
% Parse args
args_cell = strsplit(args{1}, ‘ ‘);
if numel(args_cell) >= 2
param1 = args_cell{1};
disp(param1);
param2 = args_cell{2};
disp(param2);
else
disp(‘more than 2 arguments received.’);
end
end
else
disp(‘Running in MATLAB’);
param1 = ‘test1args’;
disp(‘test2args’);
disp(param1);
param2 = ‘Yes’;
disp(‘param2’);
disp(param2);
end
disp("hello from executable…")
app = RunLocallyMat();
disp("init done")
app.main_process(param1, ‘process’, param2);
disp("process done")
end standalone-application, matlab-compiler, command-line-arguments, executable MATLAB Answers — New Questions
Calculating Greatest Common Divisor using While loop
Instead of using built in ‘GCD’ function, I am to devise code to calculate the GCD of two numbers using a while loop. I cannot figure out how to code it. Requesting some help!
%% Input two numbers.
% There is no error checking so put in positive integers of bad things may
% happen – MC
x = input(‘Enter an integer > 0: ‘);
y = input(‘Enter another integer > 0: ‘);
if x >= y
numerator = x;
denominator = y;
else
numerator = y;
denominator = x;
end
%% Calculates the GCD
% ———— Replace this piece of the code with a while loop ———–
r = rem(numerator, denominator);
while r > 0
if r == 0
GCD = denominator;
break;
end
end
fprintf(‘The GCD of %d and %d is %d: it took calculationsn’,x,y,GCD)Instead of using built in ‘GCD’ function, I am to devise code to calculate the GCD of two numbers using a while loop. I cannot figure out how to code it. Requesting some help!
%% Input two numbers.
% There is no error checking so put in positive integers of bad things may
% happen – MC
x = input(‘Enter an integer > 0: ‘);
y = input(‘Enter another integer > 0: ‘);
if x >= y
numerator = x;
denominator = y;
else
numerator = y;
denominator = x;
end
%% Calculates the GCD
% ———— Replace this piece of the code with a while loop ———–
r = rem(numerator, denominator);
while r > 0
if r == 0
GCD = denominator;
break;
end
end
fprintf(‘The GCD of %d and %d is %d: it took calculationsn’,x,y,GCD) Instead of using built in ‘GCD’ function, I am to devise code to calculate the GCD of two numbers using a while loop. I cannot figure out how to code it. Requesting some help!
%% Input two numbers.
% There is no error checking so put in positive integers of bad things may
% happen – MC
x = input(‘Enter an integer > 0: ‘);
y = input(‘Enter another integer > 0: ‘);
if x >= y
numerator = x;
denominator = y;
else
numerator = y;
denominator = x;
end
%% Calculates the GCD
% ———— Replace this piece of the code with a while loop ———–
r = rem(numerator, denominator);
while r > 0
if r == 0
GCD = denominator;
break;
end
end
fprintf(‘The GCD of %d and %d is %d: it took calculationsn’,x,y,GCD) gcd MATLAB Answers — New Questions
Can you do the writeline function without the added terminator?
I know that the writeline function adds the ‘n’ terminator at the end of a string, but I was wondering if there was a way to write strings without the terminator. Lets look at the following example:
s = serialport(‘COM7’, 9600); % Open the serial port
choice = randi(2);
if choice == 1
writeline(s, "Bananas ");
elseif choice == 2
writeline(s, "Apples ");
end
writeline(s, "are good");
delete(s);
Notice how the intended output could either be "Bananas are good" or "Apples are good". However in practice, it becomes "Bananas
are good" or "Apples
are good". Is there any way to just stop this terminator from even activating?I know that the writeline function adds the ‘n’ terminator at the end of a string, but I was wondering if there was a way to write strings without the terminator. Lets look at the following example:
s = serialport(‘COM7’, 9600); % Open the serial port
choice = randi(2);
if choice == 1
writeline(s, "Bananas ");
elseif choice == 2
writeline(s, "Apples ");
end
writeline(s, "are good");
delete(s);
Notice how the intended output could either be "Bananas are good" or "Apples are good". However in practice, it becomes "Bananas
are good" or "Apples
are good". Is there any way to just stop this terminator from even activating? I know that the writeline function adds the ‘n’ terminator at the end of a string, but I was wondering if there was a way to write strings without the terminator. Lets look at the following example:
s = serialport(‘COM7’, 9600); % Open the serial port
choice = randi(2);
if choice == 1
writeline(s, "Bananas ");
elseif choice == 2
writeline(s, "Apples ");
end
writeline(s, "are good");
delete(s);
Notice how the intended output could either be "Bananas are good" or "Apples are good". However in practice, it becomes "Bananas
are good" or "Apples
are good". Is there any way to just stop this terminator from even activating? serial, arduino MATLAB Answers — New Questions
MATLAB-ADS (TADS) interface not pulling accurate simulation data from ADS and displaying erroneous/repetitive plot legends
Hi, I am using the TADS interface to work and better analyse my simulations on the BSIM3 MOSFET which I have originally done on ADS first. I am facing the following issues:
1. Upon establishing the interface I notice that for instaance when I am plotting the Iprobe1.i (Ids:drain-source current) vs. VD( drain voltage), I get the same form as is supposed for a BSIM3 model (multiple lines for increasing levels of VG (gate voltage) from 4 to 18V in steps of 2 (bottom to top in the graph)), the data points for x and y match the values in ADS, however the legend on the side is quite misleading and shows multiple lines for VG=4V,6V and so on. (Matlab figure is attached, screenshot here). I have tried individually checking off these multiple inputs on the legend using the Plot browser option but it disrupts the plot entirely. Kindly help me in figuring out the solution.
2. In the main GUI, as you can see (screenshot below) the Save Data button is supposed to save all the data points as per the choices for all the dependent and independant variables however, the data that is getting stored is erroneous and repetitive for all levels of VG, even though the original simulation data in ADS is correct. My assumption is something wrong is happening between the transition of the data from ADS to MATLAB and I am not able to figure out the problem in the code for the Save Data button if there is one. (I have attached the code with this post as well). Please help me in figuring out the problem behind these issues since this interface is not that commonly used yet and there are low to no examples on this.Hi, I am using the TADS interface to work and better analyse my simulations on the BSIM3 MOSFET which I have originally done on ADS first. I am facing the following issues:
1. Upon establishing the interface I notice that for instaance when I am plotting the Iprobe1.i (Ids:drain-source current) vs. VD( drain voltage), I get the same form as is supposed for a BSIM3 model (multiple lines for increasing levels of VG (gate voltage) from 4 to 18V in steps of 2 (bottom to top in the graph)), the data points for x and y match the values in ADS, however the legend on the side is quite misleading and shows multiple lines for VG=4V,6V and so on. (Matlab figure is attached, screenshot here). I have tried individually checking off these multiple inputs on the legend using the Plot browser option but it disrupts the plot entirely. Kindly help me in figuring out the solution.
2. In the main GUI, as you can see (screenshot below) the Save Data button is supposed to save all the data points as per the choices for all the dependent and independant variables however, the data that is getting stored is erroneous and repetitive for all levels of VG, even though the original simulation data in ADS is correct. My assumption is something wrong is happening between the transition of the data from ADS to MATLAB and I am not able to figure out the problem in the code for the Save Data button if there is one. (I have attached the code with this post as well). Please help me in figuring out the problem behind these issues since this interface is not that commonly used yet and there are low to no examples on this. Hi, I am using the TADS interface to work and better analyse my simulations on the BSIM3 MOSFET which I have originally done on ADS first. I am facing the following issues:
1. Upon establishing the interface I notice that for instaance when I am plotting the Iprobe1.i (Ids:drain-source current) vs. VD( drain voltage), I get the same form as is supposed for a BSIM3 model (multiple lines for increasing levels of VG (gate voltage) from 4 to 18V in steps of 2 (bottom to top in the graph)), the data points for x and y match the values in ADS, however the legend on the side is quite misleading and shows multiple lines for VG=4V,6V and so on. (Matlab figure is attached, screenshot here). I have tried individually checking off these multiple inputs on the legend using the Plot browser option but it disrupts the plot entirely. Kindly help me in figuring out the solution.
2. In the main GUI, as you can see (screenshot below) the Save Data button is supposed to save all the data points as per the choices for all the dependent and independant variables however, the data that is getting stored is erroneous and repetitive for all levels of VG, even though the original simulation data in ADS is correct. My assumption is something wrong is happening between the transition of the data from ADS to MATLAB and I am not able to figure out the problem in the code for the Save Data button if there is one. (I have attached the code with this post as well). Please help me in figuring out the problem behind these issues since this interface is not that commonly used yet and there are low to no examples on this. tads interface, ads, plot, data extraction MATLAB Answers — New Questions
Armijou with steepest descent
with a given initial conditions of Armijou
% Parameters for Armijo condition
tau = 0.5;
a_prev = 1;
c1 = 0.5;
with steepest descent using armijo rule, to minimizing the function
f(x,y)=(x-2y^2)(x-3y^2)
how we can do it with plot of each iteraion ?with a given initial conditions of Armijou
% Parameters for Armijo condition
tau = 0.5;
a_prev = 1;
c1 = 0.5;
with steepest descent using armijo rule, to minimizing the function
f(x,y)=(x-2y^2)(x-3y^2)
how we can do it with plot of each iteraion ? with a given initial conditions of Armijou
% Parameters for Armijo condition
tau = 0.5;
a_prev = 1;
c1 = 0.5;
with steepest descent using armijo rule, to minimizing the function
f(x,y)=(x-2y^2)(x-3y^2)
how we can do it with plot of each iteraion ? armijou, steepest, descent, optimization, step MATLAB Answers — New Questions
How to calculate period of signal with matlab
Hi everybody,
I have the signal x2(t)=|cos(10*pi*t)|.How can i calculate its period with matlab?I am new matlab so each help will be usefullHi everybody,
I have the signal x2(t)=|cos(10*pi*t)|.How can i calculate its period with matlab?I am new matlab so each help will be usefull Hi everybody,
I have the signal x2(t)=|cos(10*pi*t)|.How can i calculate its period with matlab?I am new matlab so each help will be usefull period, signal MATLAB Answers — New Questions
Incompatible Sizes for ode45 Output Assignment
I am trying to propagate orbits for a class project, and I’d like each orbit that is solved for using ode45 to be properly labelled instead of seeing ‘data1’ through ‘data11’ in the legend for the plot3() graph. If I can solve for each orbit without overriding it in the while loop, then I can just plot3() for each orbit individually, that’s why I have the idea of using the counter j as an index for an additional dimension in the ode45 output matrix.
%% Maneuver Type 1: a-change to get aInSat to same altitude/r/a value as YH
% Do maneuvers assuming we use all available thrust
j = 1;
% need to keep track of a_t & V_IS for overshoot issue, and T for phasing
% and other stuff for project like how long it took
while (r_IS(j) < a_YH)
V_IS(j + 1) = V_IS(j) + dv;
a_t(j) = ((2/r_IS(j)) – (V_IS(j + 1)^2)/Mu)^-1;
T(j) = pi*a_t(j)^(3/2) / sqrt(Mu);
% In-Sat can either be at 0[deg] or 180, mod() considers this
if(mod(j,2) == 0)
r_N = A_pn([r_IS(j);0;0],O_IS,w_IS,i_IS);
V_N = A_pn([0;V_IS(j + 1);0],O_IS,w_IS,i_IS);
x_0 = [r_N;V_N];
else
r_N = A_pn([-r_IS(j);0;0],O_IS,w_IS,i_IS);
V_N = A_pn([0;-V_IS(j + 1);0],O_IS,w_IS,i_IS);
x_0 = [r_N;V_N];
end
[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)], x_0, opts);
r_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),1:3));
V_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),4:6));
if(r_IS(j + 1) < a_YH)
% plot only if InSat does NOT end up past yellowhammer
plot3(trans_Orbit(:,1),trans_Orbit(:,2),trans_Orbit(:,3),’g’,’Linewidth’,2);
end
j = j + 1;
end
Throws the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in Project (line 74)
[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)],x_0,opts);
The thing is, this fails after j = 8 iterations. It properly assigns the outputs from ode45 considering an additional dimension, but not past a certain point, the reason for which I cannot understand.
Again, if I can save all of the orbits without overriding any, I can print them all at the same time to allow for a proper legend.I am trying to propagate orbits for a class project, and I’d like each orbit that is solved for using ode45 to be properly labelled instead of seeing ‘data1’ through ‘data11’ in the legend for the plot3() graph. If I can solve for each orbit without overriding it in the while loop, then I can just plot3() for each orbit individually, that’s why I have the idea of using the counter j as an index for an additional dimension in the ode45 output matrix.
%% Maneuver Type 1: a-change to get aInSat to same altitude/r/a value as YH
% Do maneuvers assuming we use all available thrust
j = 1;
% need to keep track of a_t & V_IS for overshoot issue, and T for phasing
% and other stuff for project like how long it took
while (r_IS(j) < a_YH)
V_IS(j + 1) = V_IS(j) + dv;
a_t(j) = ((2/r_IS(j)) – (V_IS(j + 1)^2)/Mu)^-1;
T(j) = pi*a_t(j)^(3/2) / sqrt(Mu);
% In-Sat can either be at 0[deg] or 180, mod() considers this
if(mod(j,2) == 0)
r_N = A_pn([r_IS(j);0;0],O_IS,w_IS,i_IS);
V_N = A_pn([0;V_IS(j + 1);0],O_IS,w_IS,i_IS);
x_0 = [r_N;V_N];
else
r_N = A_pn([-r_IS(j);0;0],O_IS,w_IS,i_IS);
V_N = A_pn([0;-V_IS(j + 1);0],O_IS,w_IS,i_IS);
x_0 = [r_N;V_N];
end
[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)], x_0, opts);
r_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),1:3));
V_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),4:6));
if(r_IS(j + 1) < a_YH)
% plot only if InSat does NOT end up past yellowhammer
plot3(trans_Orbit(:,1),trans_Orbit(:,2),trans_Orbit(:,3),’g’,’Linewidth’,2);
end
j = j + 1;
end
Throws the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in Project (line 74)
[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)],x_0,opts);
The thing is, this fails after j = 8 iterations. It properly assigns the outputs from ode45 considering an additional dimension, but not past a certain point, the reason for which I cannot understand.
Again, if I can save all of the orbits without overriding any, I can print them all at the same time to allow for a proper legend. I am trying to propagate orbits for a class project, and I’d like each orbit that is solved for using ode45 to be properly labelled instead of seeing ‘data1’ through ‘data11’ in the legend for the plot3() graph. If I can solve for each orbit without overriding it in the while loop, then I can just plot3() for each orbit individually, that’s why I have the idea of using the counter j as an index for an additional dimension in the ode45 output matrix.
%% Maneuver Type 1: a-change to get aInSat to same altitude/r/a value as YH
% Do maneuvers assuming we use all available thrust
j = 1;
% need to keep track of a_t & V_IS for overshoot issue, and T for phasing
% and other stuff for project like how long it took
while (r_IS(j) < a_YH)
V_IS(j + 1) = V_IS(j) + dv;
a_t(j) = ((2/r_IS(j)) – (V_IS(j + 1)^2)/Mu)^-1;
T(j) = pi*a_t(j)^(3/2) / sqrt(Mu);
% In-Sat can either be at 0[deg] or 180, mod() considers this
if(mod(j,2) == 0)
r_N = A_pn([r_IS(j);0;0],O_IS,w_IS,i_IS);
V_N = A_pn([0;V_IS(j + 1);0],O_IS,w_IS,i_IS);
x_0 = [r_N;V_N];
else
r_N = A_pn([-r_IS(j);0;0],O_IS,w_IS,i_IS);
V_N = A_pn([0;-V_IS(j + 1);0],O_IS,w_IS,i_IS);
x_0 = [r_N;V_N];
end
[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)], x_0, opts);
r_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),1:3));
V_IS(j + 1) = vecnorm(trans_Orbit(j,length(trans_Orbit),4:6));
if(r_IS(j + 1) < a_YH)
% plot only if InSat does NOT end up past yellowhammer
plot3(trans_Orbit(:,1),trans_Orbit(:,2),trans_Orbit(:,3),’g’,’Linewidth’,2);
end
j = j + 1;
end
Throws the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in Project (line 74)
[T_ode(:,j), trans_Orbit(j,:,:)] = ode45(@(q,x) xdot(q,x,Mu), [0 T(j)],x_0,opts);
The thing is, this fails after j = 8 iterations. It properly assigns the outputs from ode45 considering an additional dimension, but not past a certain point, the reason for which I cannot understand.
Again, if I can save all of the orbits without overriding any, I can print them all at the same time to allow for a proper legend. ode45, indexing MATLAB Answers — New Questions
Find exact vector order in another vector array
I am trying to find a way to grab indivdual cells within a cell array that I can then use to find the exact order found in a larger matrix array.
I am having a difficult time trying to find a way to grab the exact order/vector in each cell array to locate the indices in the second larger matrix array.
For example, my cell array "att_event_codes" is the array I’m grabbing my desired vectors to find in the larger matrix array:
att_event_codes{1,1} : 9 10 12 11 20 12 33 21 42 22 18
att_event_codes{1,2}: 9 10 12 11 20 12 33 21 40 41 22 18
If I grab, for example, att_event_codes{1,1} as a vector I want to use:
vector = (att_event_codes{1,1});
I want to take that vector assignment to find the exact order of event codes in my larger matrix called "event_codes" (1×19277 double).
I have tried several matlab functions such as find, ismember, and strcmp and have been unable to figure out how to get them to work taking into account the entire vector rather than working with individual items within the vector. For example:
vector = (att_event_codes{1,1});
mask = ismember(event_codes,vector);
test = find(mask)
test returns 1×14953 double
Another way that I’ve tried (which is probably a better way to do this):
[~,test] = ismember(vector, event_codes)
test returns 1×11 double:
1 2 3 8 4 3 25 11 3655 5 15
The correct (desired) answser for this "test" would return an index of 3647:3657.
Thank you.I am trying to find a way to grab indivdual cells within a cell array that I can then use to find the exact order found in a larger matrix array.
I am having a difficult time trying to find a way to grab the exact order/vector in each cell array to locate the indices in the second larger matrix array.
For example, my cell array "att_event_codes" is the array I’m grabbing my desired vectors to find in the larger matrix array:
att_event_codes{1,1} : 9 10 12 11 20 12 33 21 42 22 18
att_event_codes{1,2}: 9 10 12 11 20 12 33 21 40 41 22 18
If I grab, for example, att_event_codes{1,1} as a vector I want to use:
vector = (att_event_codes{1,1});
I want to take that vector assignment to find the exact order of event codes in my larger matrix called "event_codes" (1×19277 double).
I have tried several matlab functions such as find, ismember, and strcmp and have been unable to figure out how to get them to work taking into account the entire vector rather than working with individual items within the vector. For example:
vector = (att_event_codes{1,1});
mask = ismember(event_codes,vector);
test = find(mask)
test returns 1×14953 double
Another way that I’ve tried (which is probably a better way to do this):
[~,test] = ismember(vector, event_codes)
test returns 1×11 double:
1 2 3 8 4 3 25 11 3655 5 15
The correct (desired) answser for this "test" would return an index of 3647:3657.
Thank you. I am trying to find a way to grab indivdual cells within a cell array that I can then use to find the exact order found in a larger matrix array.
I am having a difficult time trying to find a way to grab the exact order/vector in each cell array to locate the indices in the second larger matrix array.
For example, my cell array "att_event_codes" is the array I’m grabbing my desired vectors to find in the larger matrix array:
att_event_codes{1,1} : 9 10 12 11 20 12 33 21 42 22 18
att_event_codes{1,2}: 9 10 12 11 20 12 33 21 40 41 22 18
If I grab, for example, att_event_codes{1,1} as a vector I want to use:
vector = (att_event_codes{1,1});
I want to take that vector assignment to find the exact order of event codes in my larger matrix called "event_codes" (1×19277 double).
I have tried several matlab functions such as find, ismember, and strcmp and have been unable to figure out how to get them to work taking into account the entire vector rather than working with individual items within the vector. For example:
vector = (att_event_codes{1,1});
mask = ismember(event_codes,vector);
test = find(mask)
test returns 1×14953 double
Another way that I’ve tried (which is probably a better way to do this):
[~,test] = ismember(vector, event_codes)
test returns 1×11 double:
1 2 3 8 4 3 25 11 3655 5 15
The correct (desired) answser for this "test" would return an index of 3647:3657.
Thank you. vector indexing, indexing, vectors MATLAB Answers — New Questions