https://au.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-03-29T06:49:47Ztag:au.mathworks.com,2005:Question/5095372020-03-07T05:42:25Z2020-03-29T06:49:47ZObjective Function must return a scalar value.Dear friends,
I am trying to do an optimization for a function using a "fmincon" function. I have got an error and couldn't find the problem.
The following is the error obtained :
Error using fmincon (line 609)
Supplied objective function must return a scalar value.
Error in Topo_3D (line 31)
[x,fval,ef,output,lambda,hessian] = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon,options);
A copy of my fmincon function is attached.
I appreciate if somebody help with this issue and how can be solved.
Thank you very much.
RTFQ
Richardhttps://au.mathworks.com/matlabcentral/profile/authors/17695287-richardtag:au.mathworks.com,2005:Question/4776232019-08-26T15:09:39Z2020-03-29T06:48:58ZAdding vertical line to graph at certain heightHi everyone,
I attached a picture of what I want to achieve - I'm using a script with a loop that creates a plot for each participant in a study and would like to add a vertical line at 4.5 seconds. I did manage to add a vertical line using
x=[4.5,4.5];
y=[-10,0];
plot(x,y)
However the problem is that I need to specify y-values. This is a problem because the y scale can differ vastly between participants (for some it will be 600 - 700, for some 0 - 10). Is there a universal way to add a line that simply starts at the bottom (at the x-axis) and goes up to a certain y-value? Thank you in advance!Rose Potterhttps://au.mathworks.com/matlabcentral/profile/authors/15159153-rose-pottertag:au.mathworks.com,2005:Question/5136902020-03-29T06:47:32Z2020-03-29T06:48:09ZERROR: FMINCON requires all values returned by functions to be of data type double.I have this function evalQ_test:
function Q = evalQ_test(x)
%%%
%%% Q_1 = x(1)+x(2);
%%%
Q=double(-(Q_1+Q_2+Q_3));
end
I omitted most of what the real content of the function here by %%%.
Following https://www.mathworks.com/help/optim/ug/writing-scalar-objective-functions.html,
I have this objective function:
function [f, g, H] = evalQ_1(x)
% Calculate objective f
f = @(x) evalQ_test(x);
if nargout > 1 % gradient required
g = [f([x(1)+delta;x(2)])-f([x(1);x(2)]);f([x(1);x(2)+delta])-f([x(1);x(2)])];
if nargout > 2 % Hessian required
H = [x(1),0;0,x(2)];
end
end
And Hessian function:
function Hout = hessianfcn(x,lambda)
delta = 10^(-6);
% Hessian of objective
H = [x(1),0;0,x(2)];
% Hessian of nonlinear inequality constraint
Hg = 2*eye(2);
Hout = H + lambda.ineqnonlin*Hg;
Suppose the gradient and hessian are calaulated correctly here.
Then I run:
fun = @evalQ_1;
x0 = [1;1];
options = optimoptions('fmincon','Algorithm','interior-point',...
'SpecifyObjectiveGradient',true,'SpecifyConstraintGradient',true,...
'HessianFcn',@hessianfcn);
[x,fval,exitflag,output] = fmincon(fun,x0,[],[],[],[],[],[],[],options);
However, I have the error:
"Error using fmincon (line 694)
FMINCON requires all values returned by functions to be of data type double."
Is it because I am using a nested objective function? Or anything else?
Thanks in advance!!Chenhttps://au.mathworks.com/matlabcentral/profile/authors/5673852-chentag:au.mathworks.com,2005:Question/5136892020-03-29T06:42:19Z2020-03-29T06:42:19Zmcc error with uisetcolor on macos catalinaDear experts,
We noticed a compatibility issue of compiled app on macos catalina (10.15.3). This issue were reproducable in MATLAB 2018a and 2019b.
The color selection funciton "uisetcolor" works well in the MATLAB enviroment.
However, when we compiled this script to an standalone app using mcc, the output of the app goes to blank.
Thank you very much.
Mingrui Xiahttps://au.mathworks.com/matlabcentral/profile/authors/17970291-mingrui-xiatag:au.mathworks.com,2005:Question/5136762020-03-29T04:13:59Z2020-03-29T06:40:20ZHow to remove rows in a matrix based on the first columnHey Guys,
I have a Numeric matrix of 224836 rows by 3 columns and I need to be able to filter out some of thge data points which are incorrect.
The First column has a set of data points less than 300000 and I need to be able to delete not only those points but the whole rows that they are in so that I can plot a 3d graph, so far I have only been able to filter out the first column and second as they are very similar numbers (most above 550000) but the third is depth in metres and only only has a range of 100.
Please help!
(I am using 2019a)MILLER BIGGELAARhttps://au.mathworks.com/matlabcentral/profile/authors/17682795-miller-biggelaartag:au.mathworks.com,2005:Question/5136682020-03-29T03:08:03Z2020-03-29T06:34:38Zgenerate matrix of each iterationdear friend please help me to generate a matrix 'yy' which stores matrix "xx" in each iteration.
%% direct search methods
clc;
clear variables;
delta=[2;2];
eps=10^(-3);
%% BOX EVOLUTINARY OPTIMIZATION METHOD
x0=[1;1];
% k=(delta(1)^2+delta(2)^2)^0.5;
for i=1:3
x1=x0+[1;-1];
x2=x0+[-1;-1];
x3=x0+[-1;1];
x4=x0+[1;1];
xx=[x0 x1 x2 x3 x4];
yy=xx();
f(1)=diremtd(x0);f(2)=diremtd(x1);
f(3)=diremtd(x2);f(4)=diremtd(x3);f(5)=diremtd(x4);
A=[f(1),f(2),f(3),f(4),f(5)];
k=min(A);
for j=1:5
if k==f(j)
tt=xx(:,j);
t=f(j);
end
end
x0=tt;
end
%% THANK YOUDEVhttps://au.mathworks.com/matlabcentral/profile/authors/15879045-devtag:au.mathworks.com,2005:Question/5136832020-03-29T05:20:34Z2020-03-29T06:32:00ZIndex exceeds the number of array elements (1).s(1) = 100; % Start at 100
step1 = 0:1; % The step goes from 0 to 1
F1 = [25000, 100000]; %The number of simulations for the walker
for Z = 1:length(F1) %Retrieves the length of each simulation
for B = 1:F1(Z)
for L = 100:2601 % This is for the 2500 steps, and we repeat the functions from part 1
o(L) = L; % This keeps track of the time
d(L) = rand; %Retrieves a random value for the walker
if d(L) > .5
s(L) = s(L-1) + step1; %The walker steps to the right
elseif d(L) < .5
s(L) = s(L-1) - step1; %The walker steps to the left
else
s(L) = .5;
end
end
Endp(B) = s(L); %This stores the poisiton for each simulation
endOmar Seraghttps://au.mathworks.com/matlabcentral/profile/authors/16131570-omar-seragtag:au.mathworks.com,2005:Question/5134822020-03-27T22:49:09Z2020-03-29T06:26:04ZHow to measure the aspect ratio of a certain part of an image
I am working with the mnist dataset and I am trying to calculate the aspect ratio of every number. The aspect ratio is defined as the minimum ractangular area that the number covers any idea how to do that?datanoobhttps://au.mathworks.com/matlabcentral/profile/authors/17969074-datanoobtag:au.mathworks.com,2005:Question/5135642020-03-28T12:38:09Z2020-03-29T06:20:13ZCalculate longterm daily averageI manged to do monthly average like this.
mat = randi([0 14600], 730, 5, 2);
sc1 = (datetime(1981,1,1):datetime(1982,12,31))';
splitmat = num2cell(permute(mat, [1 3 2]), [1 2]);
TT1 = timetable(sc1,splitmat{:});
monthlyaverage = retime(TT1, 'monthly', 'mean');
If I do
monthlyaverage = retime(TT1, 'daily', 'mean');
it will return the same value as the data is daily. However, I am interested to get longterm daily average that means average of day of the year (day 1 ... day 365). The final answer number of rows will be only 365. is there similar approach that is concise like retime to do it?
thanksTunechihttps://au.mathworks.com/matlabcentral/profile/authors/3196327-tunechitag:au.mathworks.com,2005:Question/5127632020-03-25T01:56:30Z2020-03-29T06:17:28Zhow to find the length and width of connected componentshi everyone.
i want to know how to find the length and width of connected components as i already label the connected components using bwlabel and draw the boundries using regionprops and boundry but now the only thing i need to know is how to find the length and width of that drawn boundries(connected components). as i want to seprate those regions that have length and width equall to humans.QuestionsAccounthttps://au.mathworks.com/matlabcentral/profile/authors/17542596-questionsaccounttag:au.mathworks.com,2005:Question/3262482017-02-21T21:30:57Z2020-03-29T06:16:59Zdsolve returns imaginary components when it shouldnt..how to fix this?I am having trouble with solving 2nd order differential equation with 'dsolve':
q=1*10^3; %N/m
L=2; %m
E=200*10^9; %Pa
I=177*10^-8; %m^4
syms W(x)
W=dsolve('D2W=(1/(E*I))*((-A*x)+q*((x^2)/2))','x')
which returns solution
% solution
W =- (q*exp(-1)*x^4*1i)/24 + (A*exp(-1)*x^3*1i)/6 + C3*x + C4
when the solution should have zero imaginary components since solving by hand gives me:
% by hand
W2=(1/(E*I))*(-A*(x^3)/6+q*(x^4)/24)+C0*x+C1
Any explanation or advice?
Andrejhttps://au.mathworks.com/matlabcentral/profile/authors/9773816-andrejtag:au.mathworks.com,2005:Question/1109942013-12-30T00:52:58Z2020-03-29T06:00:25ZLabelling three axes of moody plotI've written the following code, which use another function 'Moody', to plot the moody plot. I've plotted it correctly, I think. With log scales on both the x and y axis. The x and y axes are labelled and scaled. *Is it possible for me to label the third axis?* This axis denotes the relative roughness and is the axis parallel to the y-axis. *Also, is there a way that I could label more of the divisions along the y axis?* As it stands there are only two values but I would like to have the values between these labelled also. The code is as follows:
Moody:
function f = Moody(relr,Re)
% 'moody' finds friction factor by solving the Colebrook equation (Moody Chart)
% Inputs: e/D, Re.
% Output: f.
% Note: Laminar and turbulent flow are correctly accounted for
if (Re < 0)
error (sprintf('Reynolds number = %f cannot be negative',Re));
elseif (Re < 2000)
f = 64/Re; return %Laminar flow
end
if (relr > 0.05)
warning (sprintf('epsilon/diameter ratio = %f is not on Moody chart',relr));
end
if Re<4000, warning('Re = %f in transition range',Re); end
% --- Use fzero to find f from Colebrook equation.
% coleFun is an anonymous function object to evaluate F(f,e/d,Re)
% fzero returns the value of f such that F(f,e/d/Re) = 0 (approximately)
% fi = initial guess from Haaland equation, see White, equation 6.64a
% Iterations of fzero are terminated when f is known to whithin +/- dfTol
coleFun = @(f,ed,Re) 1.0/sqrt(f) + 2.0*log10( ed/3.7 + 2.51/( Re*sqrt(f)));
fi = 1/(1.8*log10(6.9/Re + (relr/3.7)^1.11))^2; % initial guess at f
dfTol = 5e-6;
f = fzero(coleFun,fi,optimset('TolX',dfTol,'Display','off'),relr,Re);
% --- sanity check:
%if f<0
%error(sprintf('Friction factor = %f, but cannot be negative',f));
%end
Moody Plot:
% myMoody makes a simple Moody chart
% Generates a log-spaced vector of Re values in the range 2500 <= Re < 10^8
Re = logspace(log10(2500),8,50);
relr = [0 0.00001 0.00005 0.0001 0.0002 0.0005 0.001 0.002 0.005 0.01 0.02 0.03 0.04 0.05];
f = zeros(size(Re));
% Plot f(Re) curves for one value of epsilon/D at a time
% Temporarily turn warnings off to avoid lots of messges when 2000 < Re < 4000.
warning('off')
figure('units','normalized','outerposition',[0 0 1 1]);
title('Moody Plot')
hold('on');
% Nested loop to find f values.
for i=1:length(relr)
for j=1:length(Re)
f(j) = Moody(relr(i),Re(j));
end
loglog(Re,f,'k-', 'LineWidth', 1.5)
end
ReLam = [100 2000];
fLam = 64./ReLam;
plot(ReLam,fLam,'r-');
xlabel('Re');
ylabel('f','Rotation',0)
axis([0 1e8 0 2e-1]);
hold('off');
grid on
warning('on');
% MATLAB resets loglog scale? Set it back.
set(gca,'Xscale','log','Yscale','log'); %Formats/Scales axes using handles.Davidhttps://au.mathworks.com/matlabcentral/profile/authors/4632998-davidtag:au.mathworks.com,2005:Question/5135742020-03-28T13:31:44Z2020-03-29T05:53:43Zconfusion Matrix ,sensitivity and specificityI have actual Y and prdicted Y matrix of 27×1 double type. i have written the following code but its not working. Kindly help me where i am wrong?
[cm,order] = confusionmat(actual_Y,predicted_Y);
% if yHat are your predictions and yval are your y true then
tp = sum((predicted_Y == 1) & (actual_Y == 1))
fp = sum((predicted_Y == 1) & (actual_Y == 0))
tn = sum((predicted_Y == 0) & (actual_Y == 1))
fn = sum((predicted_Y == 0) & (actual_Y == 0))
sensitivity = tp/(tp + fn) %TPR
specificity = tn/(tn + fp) %TNR
precision = tp / (tp + fp)
FPR = fp/(tn+fp);
Accuracy = (TP+TN)./(TP+FP+TN+FN);
recall = tp / (tp + fn)
F1 = (2 * precision * recall) / (precision + recall);
Saba Bashirhttps://au.mathworks.com/matlabcentral/profile/authors/15700746-saba-bashirtag:au.mathworks.com,2005:Question/5102782020-03-11T09:36:30Z2020-03-29T05:52:44ZHow can I calculate distance between a point in a given radius inside a geographic coordinate grid? Hello all,
I tried to search for similar questions, and I have got different solutions, but nothing to combine all my tasks, hence I still can't find the proper approach for my problem. Some of the approaches include:
https://www.mathworks.com/matlabcentral/answers/492031-interpolation-of-scattered-earthquake-data
https://www.mathworks.com/matlabcentral/answers/423998-circles-with-particular-radius-for-latitude-and-longitude-points-plotted-on-map
I need to create a grid which contains earthquake data, namely longitude and latitude points (N & E geographic coordinates). What I need is to divide the area into a 0.5 km interval 2-D grid in the horizontal coordinates.
For each grid point, I would need to plot a circle with radius 6 km, and count how many events fall within the circle as well as calculate the distance between the center point of the circle and each event point (earthquake event).
Attached is the file containing the earthquake data needed for the analysis.
Cheers,
H.
Harith Al Kubaisyhttps://au.mathworks.com/matlabcentral/profile/authors/9053294-harith-al-kubaisytag:au.mathworks.com,2005:Question/5136802020-03-29T04:32:10Z2020-03-29T05:52:19ZSelect only January and April months among 30 years monthly data (how to filter?)Hey all,
I have a cell (1 x 92) which includes 92 tables . In each table I have a column named dates. I want to filter the whole table based on January and April. I wish if it is possible have the value of January and April as 2 column after all existing column in each table (cell array), for example:
Thank you so muchBehzad Navidihttps://au.mathworks.com/matlabcentral/profile/authors/15525777-behzad-naviditag:au.mathworks.com,2005:Question/5135762020-03-28T14:17:47Z2020-03-29T05:51:52Zhow to solve this error 'Undefined function or variable 'uiopen'.'I am facing problem in opening any file in matlab.It is showing this error "Undefined function or variable 'uiopen'." in command window.With this this window is shown in figure.
How can I solve it?
riya shahrinhttps://au.mathworks.com/matlabcentral/profile/authors/15983192-riya-shahrintag:au.mathworks.com,2005:Question/3110952016-11-07T20:04:52Z2020-03-29T05:46:08ZError about combining MATLAB mex file and ModeFrontierHi everybody
I linked MATLAB mex file with ModeFrontier. During running I get this error:
from job_err file:
com.jacob.com.ComFailException: Can't map name to dispid: execute
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at it.esteco.jacob.JacobDispatch.callMethod(JacobDispatch.java:48)
at it.esteco.activex.ActiveXAdapter.callMethod(ActiveXAdapter.java:51)
at it.esteco.integration.matlab.job.win.MatlabApplication.execute(MatlabApplication.java:76)
at it.esteco.integration.matlab.job.win.MatlabWin.execute(MatlabWin.java:177)
at it.esteco.integration.matlab.job.win.MatlabWin.execute(MatlabWin.java:197)
at it.esteco.integration.matlab.job.MatlabIntegration.cleanUp(MatlabIntegration.java:326)
at it.esteco.integration.matlab.job.MatlabIntegration.start(MatlabIntegration.java:114)
at it.esteco.jobagent.integration.StaIntegrationJob$3.call(StaIntegrationJob.java:51)
at it.esteco.jobagent.integration.StaIntegrationJob$3.call(StaIntegrationJob.java:48)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
from jvm_err file:
Client RMI URL: rmi://127.0.0.1:13879/it.esteco.jobagent.JobAgent/2409635/1478546034052
Server jvmerr log file: D:\Program Files\MATLAB\R2014a\ModeFrontier\MyCode_00001\log\01000-01999\01103\Matlab9_00000\jvm_err.log
Nov 7, 2016 11:07:02 PM it.esteco.integration.matlab.job.MatlabIntegration start
WARNING: A COM exception has been encountered:
At Invoke of: execute
Description: 800706be / The remote procedure call failed.
com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: execute
Description: 800706be / The remote procedure call failed.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at it.esteco.jacob.JacobDispatch.callMethod(JacobDispatch.java:48)
at it.esteco.activex.ActiveXAdapter.callMethod(ActiveXAdapter.java:51)
at it.esteco.integration.matlab.job.win.MatlabApplication.execute(MatlabApplication.java:76)
at it.esteco.integration.matlab.job.win.MatlabWin.execute(MatlabWin.java:179)
at it.esteco.integration.matlab.job.MatlabIntegration.evaluateScript(MatlabIntegration.java:305)
at it.esteco.integration.matlab.job.MatlabIntegration.start(MatlabIntegration.java:107)
at it.esteco.jobagent.integration.StaIntegrationJob$3.call(StaIntegrationJob.java:51)
at it.esteco.jobagent.integration.StaIntegrationJob$3.call(StaIntegrationJob.java:48)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
iman AHMADIhttps://au.mathworks.com/matlabcentral/profile/authors/8965392-iman-ahmaditag:au.mathworks.com,2005:Question/5136882020-03-29T05:44:57Z2020-03-29T05:44:57ZNon-Persistent CSMA plotting of GraphHello,
I tried plotting a non-persistent graph but there's no output showing.
Here's the code:
G= 0:0.05:100;
a= 0.01;
NonPersistentCSMA= G.*(exp(-a*G))/(G*(1+2*a)+exp(-a*G));
plot(G,NonPersistentCSMA);
Kindly advise.
Jirah Marie Navarrohttps://au.mathworks.com/matlabcentral/profile/authors/17932391-jirah-marie-navarrotag:au.mathworks.com,2005:Question/5135962020-03-28T16:59:46Z2020-03-29T05:44:43Z[c] = confusion(t,y) and not classified observationsHi
[c] = confusion(t,y)
[c] its Confusion value = fraction of samples misclassified
but output of code bellow can be values:
1)classified correctly
2)classified incorrectly
3)not classified
net = fitnet(hl,trainFcn)
[net,tr] = train(net,x,t);
y = net(x)
[c] = confusion(t,y)
if im getting c = 0 it mean all values were classified correctly but it will consider values which were not classified ?Tomasz Kaczmarskihttps://au.mathworks.com/matlabcentral/profile/authors/17173063-tomasz-kaczmarskitag:au.mathworks.com,2005:Question/5136872020-03-29T05:43:02Z2020-03-29T05:43:02ZCoefficient Handle for Nonconstant Coefficients In specifyCoefficients there is an option to choose the coefficient "f" as a non-constant, for instance in the following form:
f = @(location,state)location.y.^2.*tanh(location.z)/1000;
I need to set f as follows:
a=@(t,z) interp2(XX,TT,V,t,z);
f = @(location,state) a(location.y,location.x);
This gives the following error:
Error using pde.PDEModel/solveStationaryNonlinear (line 27)
Unsuitable initial guess U0 (default: U0=0).
Error in pde.PDEModel/solvepde (line 77)
Ali Hagverdiyevhttps://au.mathworks.com/matlabcentral/profile/authors/8028550-ali-hagverdiyevtag:au.mathworks.com,2005:Question/5136842020-03-29T05:35:36Z2020-03-29T05:42:56ZHow to step through a discrete model simulation one step at a timeI have a discrete-time ARX model that I want to use to represent the plant in a simulation:
Ts = 1;
sigma = 0.01;
d = 3;
sys = idpoly([1 -2.4 1.9 -0.5],[0.01 0.001 -0.007],[],[],[],sigma^2,Ts,'IOdelay',d);
How do I simulate this system one timestep at a time in a for loop with my control algorithm?
N = 10;
u = zeros(N,1);
y = zeros(N,1);
for k=1:N
u[k] = rand()*2 - 1;
y[k] = sys ...?
end
(I know how to simulation a whole trajectory):
u = rand(N,1)*2 -1;
y = sim(sys,u);Bill Tubbshttps://au.mathworks.com/matlabcentral/profile/authors/4985015-bill-tubbstag:au.mathworks.com,2005:Question/5136862020-03-29T05:42:09Z2020-03-29T05:42:09Zcontrol system bode plot
how to plot this two equatio and the resutant output is shown in the figure
the alpha value should be any fractional value(eg-alpha=0.01 to 0.09).
one of the matlab community person helped me but his alpha value is 1 not fractional the code is given below
(hold off;
alpha=1;Wcr=10;
w1=logspace(-1,log10(Wcr),1000);w2=logspace(log10(Wcr),3,1000);
Mag1=20*ones(1,numel(w1));Mag2=@(w2) 20*alpha*log10(w2);
semilogx(w1,Mag1);hold on;semilogx(w2,Mag2(w2));grid on;xlabel('Frequency');ylabel('dB'))Irshad Baruahhttps://au.mathworks.com/matlabcentral/profile/authors/9521830-irshad-baruahtag:au.mathworks.com,2005:Question/5135222020-03-28T07:55:54Z2020-03-29T05:39:52ZNormalization of test data - neural networki am using neural network for training and testing the data. i use features like nucleus area, perimeter, diameter, eccentricity for training.
i have values for features like:
Area - 2513, Perimeter - 203.811, Diameter - 56.5655, Eccentricity - 0.736247.
i have to normalize those values and have to save the normalized values in same '.mat' file to test the model. please help me to solve this, and provide me with the correct code.
Thank you in advance.vidhya vhttps://au.mathworks.com/matlabcentral/profile/authors/17321594-vidhya-vtag:au.mathworks.com,2005:Question/1205722014-03-07T13:30:47Z2020-03-29T05:36:41ZIf else condition to determine if a year is a leap yearHi there.
Given a variable Y which stores a year in the 20th century (between 1901 and 2000), write MATLAB code to create a variable Days and assign it a value of 366 if the year is a leap year or a value of 365 otherwise. chafah zacharyhttps://au.mathworks.com/matlabcentral/profile/authors/4352213-chafah-zacharytag:au.mathworks.com,2005:Question/5136852020-03-29T05:35:44Z2020-03-29T05:35:44ZMatlab closed loop Autotuner PID with embedded coderHi,
I want to generate C code using Embedded Coder for autotune PID. Using matlab 2019b.
1. Microcontroller used: Rx23T with FPU enabled, so can using single precision floats.
2. Need to autotune of PID for oven application. Have a sensor to read temperature values every 100ms.
3. So inputs have:
a) Reference temperature: float32_t , temperature need to set
b) Current temperature: float32_t, current temperature of oven
4. Outputs need:
a) Autotune PID values
b) 0-65535 value for PWM duty cycle, this will be feed via MCU to a Solid state relay which will control on/off of heater.
5. No plant model/transfer function available, only input mentioned available
6. I hwas trying to make simulink slx file. Attached is snapshot. Some confusion i have is:
a) u+du : How it will be used here?
b) I my application closed loop or open loop autotuner suits?
c) %conv : When 100% will it tell that autotuning completes? What is there is some error? Is there any error also?
d) PID gains: Need to feed back autotune PID games to "Discrete PID controller" block, how to do that?
e) How to get output PWM value from this 0-65535?
7. Is my approach ok? or something wrong?
Vhttps://au.mathworks.com/matlabcentral/profile/authors/6016868-vtag:au.mathworks.com,2005:Question/4417282019-01-27T14:36:29Z2020-03-29T05:23:39ZConnect Neurosky Mindwave in ATTENTIONI using code :
function read_ATTENTION
TG_DATA_ATTENTION = 2;
Matlab code to read attention using Mindwave mobile
%Clear Screen
clc;
%Clear Variables
clear all;
%Close figures
close all;
%Preallocate buffer
data_att = zeros(1,256);
%Comport Selection
portnum1 = 14;
%COM Port #
comPortName1 = sprintf('\\\\.\\COM%d', portnum1);
% Baud rate for use with TG_Connect() and TG_SetBaudrate().
TG_BAUD_115200 = 115200;
% Data format for use with TG_Connect() and TG_SetDataFormat().
TG_STREAM_PACKETS = 0;
% Data type that can be requested from TG_GetValue().
TG_DATA_ATTENTION = 2;
%load thinkgear dll
loadlibrary('Thinkgear.dll');
%To display in Command Window
fprintf('Thinkgear.dll loaded\n');
%get dll version
dllVersion = calllib('Thinkgear', 'TG_GetDriverVersion');
%To display in command window
fprintf('ThinkGear DLL version: %d\n', dllVersion );
% Get a connection ID handle to ThinkGear
connectionId1 = calllib('Thinkgear', 'TG_GetNewConnectionId');
if ( connectionId1 < 0 )
error( sprintf( 'ERROR: TG_GetNewConnectionId() returned %d.\n', connectionId1 ) );
end;
% Attempt to connect the connection ID handle to serial port "COM3"
errCode = calllib('Thinkgear', 'TG_Connect', connectionId1,comPortName1,TG_BAUD_115200,
TG_STREAM_PACKETS);
if ( errCode < 0 )
error( sprintf( 'ERROR: TG_Connect() returned %d.\n', errCode ) );
end
fprintf( 'Connected. Reading Packets...\n' );
i=0;
j=0;
%To display in Command Window
disp('Reading Brainwaves');
figure;
while i < 20
if (calllib('Thinkgear','TG_ReadPackets',connectionId1,1) == 1) %if a packet was read...
if (calllib('Thinkgear','TG_GetValueStatus',connectionId1,TG_DATA_ATTENTION ) ~= 0)
j = j + 1;
i = i + 1;
%Read attention Valus from thinkgear packets
data_att(j) = calllib('Thinkgear','TG_GetValue',connectionId1,TG_DATA_ATTENTION );
%To display in Command Window
disp(data_att(j));
%Plot Graph
plot(data_att);
title('Attention');
%Delay to display graph
pause(1);
end
end
end
%To display in Command Window
disp('Loop Completed')
%Release the comm port
calllib('Thinkgear', 'TG_FreeConnection', connectionId1 );
but the wrong code command window shows up:
Error: File: Connect.m Line: 36 Column: 88
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
means line 36 is:
errCode = calllib('Thinkgear', 'TG_Connect', connectionId1,comPortName1,TG_BAUD_115200,
TG_STREAM_PACKETS);
can you help me to solve this ? thankyou
Tsalsabilla Winny Junikahttps://au.mathworks.com/matlabcentral/profile/authors/12365525-tsalsabilla-winny-junikatag:au.mathworks.com,2005:Question/3000892016-08-18T04:00:00Z2020-03-29T05:21:30ZWhy do I not see tabs in the MATLAB Editor in R2016a?Why do I not see tabs in the MATLAB Editor in R2016a? In my older versions of MATLAB, I can see the name of my M-file as a tab in the editor. How come it does not appear that way in R2016a?
MathWorks Support Teamhttps://au.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:au.mathworks.com,2005:Question/5136452020-03-28T21:50:53Z2020-03-29T05:17:52ZHow to show word from excel?I want to show the word from excel. But I don't know how to show it. This is my code.
clc;
clear all;
T=readtable('EVASUSANTIDATA.xlsx');
x1=T.PENDAFTARAN;
x2=T.TUNDA;
x3=T.KUOTA;
y=T.LAMA;
For example, I want to get this result:
KOTA KUOTA LAMA
KOTA BENGKULU 311 21
it's the data number one in excel. With 'KUOTA' is 'x3' and 'LAMA' is 'y' Eddy Iswardihttps://au.mathworks.com/matlabcentral/profile/authors/16292322-eddy-iswarditag:au.mathworks.com,2005:Question/5135122020-03-28T06:00:50Z2020-03-29T05:01:30ZHow can I optimize the value of a matrix?I want to find the optimal B matrix (2*4 matrix) that makes the elements of beta_d (1*4 vector) which is a function of B matrix, equal to the corresponding ones of a "given" beta_u (1*4 vector), i.e. I want to obtain the value of B matrix that makes beta_d(1,1) = beta_u(1,1) && beta_d(1,2) = beta_u(1,2) && beta_d(1,3) = beta_u(1,3) && beta_d(1,4) = beta_u(1,4).
On my attached code, as I am a beginner in MATLAB, I generated random value of B matrix and used 'while loop' to check if my condition is satisfied or not. This way is not efficient and takes very long time to give me a result.
Can anyone help me to optimize the value of B matrix in more efficient and faster way?
% Given H (4*2 matrix)
% Given A (2*2 diagonal matrix)
% Given C (4*4 matrix)
% Given P (4*4 diagonal matrix)
% Given C_l = 4; (constant value)
% Given beta_u (1*4 vector)
% I want to find the optimal B matrix (2*4 matrix) that makes the elements of the 1*4 beta_d vector equal to the corresponding ones of beta_u 1*4 vector
% i.e I want beta_d(1,1) = beta_u(1,1) && beta_d(1,2) = beta_u(1,2) && beta_d(1,3) = beta_u(1,3) && beta_d(1,4) = beta_u(1,4)
%% My non-efficient code:
B = zeros(2,4); % intial value of B 2*4 matrix
beta_d = zeros(1,4); %intial value of beta_d 1*4 vector
% compare each element of beta_d with the corresponding one in beta_u
% optimize the value of B
while(beta_d(1) ~= beta_u(1) || beta_d(2) ~= beta_u(2) || beta_d(3) ~= beta_u(3) || beta_d(4) ~= beta_u(4)) %check the condition
B = randn(2,4); % generate a random 2*4 B matrix
for j=1:1:2 % calculcate the 2*2 diagonal D matrix whose value depends on B
d(j) = (B(j,:)*P*B(j,:)')/((2^(2*C_l))-(norm(A(:,j))^2));
end
D = diag(d);
for i=1:1:4 % calculate beta_d (1*4 vector) whose value depends on B and D
V_d(i)=C(i,:)*P*B'*H(i,:)'*inv(1+H(i,:)*(A'*D*A+B*P*B')*H(i,:)');
sigma_d(i)=norm((V_d(i)*H(i,:)*B-C(i,:))*(P^(1/2)))^2+(V_d(i)^2)*(1+H(i,:)*A'*D*A*H(i,:)');
beta_d(i)=((P(i,i))/sigma_d(:,i));
end
end Ahmed elsayedhttps://au.mathworks.com/matlabcentral/profile/authors/17706604-ahmed-elsayedtag:au.mathworks.com,2005:Question/5136822020-03-29T04:55:11Z2020-03-29T04:55:11ZPDEToolbox - Unsuitable initial guess U0 (default: U0=0)Hello everyone.
I am trying to model a reaction of ammonia cracking ocurring in a Plug Flow (Cylindrical) Reactor with the geometry in the annex figure AQ4.jpg. For that end, I created the code below:
%1. Reactor Configuration [m]
L_aq4 = 1.5; %Reactor length
D_aq4 = 0.1; %Reactor diameter
%2. Miscellaneous Parameters
Diff_H2 = (5*10^-9)*800^1.682; %Average diffusion coefficient
lambda_gas = 6.09*10^-2; %Average thermal condutivity of the gas
%3. Creating the PDE Model
N = 5;
model = createpde(N);
% 1 = Total matter balance for the gases
% 2 = Matter balance for species NH3
% 3 = Matter balance for species N2
% 4 = Matter balance for species H2
% 5 = Heat balance
%3.2.1. Creating the PDE Model - Geometry (Cylinder)
gm = multicylinder (D_aq4/2,L_aq4);
model.Geometry = gm;
mesh_HminHmax = generateMesh(model,'Hmax',0.5,'Hmin',D_aq4);
pdegplot(model,'FaceLabels','on','FaceAlpha',0.5);
%3.2.2. Setting Boundary Conditions (Initial conditions not needed
%for steady-state problems)
C0_NH3 = 160; %[mol.m^-3]
T0 = 300; %[K]
Tw = 800; %[K]
h1 = ones(N,1);
h1d = diag(h1);
h3 = [0 0 0 0 1];
h3d = diag(h3);
r1 = [C0_NH3 C0_NH3 0 0 T0];
r3 = [0 0 0 0 Tw];
applyBoundaryCondition(model,'dirichlet','Face',1,'h',h1d,'r',r1);
applyBoundaryCondition(model,'dirichlet','Face',3,'h',h3d,'r',r3);
%3.2.3. Setting PDE Coefficients (Elliptic equation type)
c = [0 Diff_H2 Diff_H2 Diff_H2 lambda_gas]';
specifyCoefficients(model,'m',0,'d',0,'c',c,'a',0,'f',@fcoeffunction);
result = solvepde(model);
pdeplot3D(model,'ColorMapData',result.NodalSolution)
%4. Functions
function f = fcoeffunction(location,state)
nr = length(location.x);
f = zeros(5,nr);
R = 8.314; %Gas constant
ug = 1.5; %Gas velocity
cpavg_g = 3.727*10^1; %Average heat capacity of the gas
dHr_cr = 1.611*10^5; %Heat of cracking reaction
k_cr = 8.4*10^8; %Pre-exponential factor of cracking reaction
E_cr = 1.611*10^5; %Activation energy of cracking reaction
K_cr = k_cr.*exp(-E_cr./(R.*state.u(5,:))); %Arrhenius "constant" of cracking reaction
r_cr = K_cr.*state.u(2,:); %Reaction rate
f(1,:) = -ug.*state.uz(1,:) + 2.*r_cr;
f(2,:) = ug.*state.uz(2,:) + 2.*r_cr;
f(3,:) = ug.*state.uz(3,:) - r_cr;
f(4,:) = ug.*state.uz(4,:) - (3.*r_cr);
f(5,:) = (ug.*state.u(1,:).*cpavg_g).*state.uz(5,:) + dHr_cr.*r_cr;
end
The system of PDEs consist in the following equations:
1) ug*du(1)/dz = 2*r_cr
2) ug*du(2)/dz = -2*r_cr + Diff_H2*div(grad(u(2)))
3) ug*du(3)/dz = r_cr + Diff_H2*div(grad(u(3)))
4) ug*du(4)/dz = 3*r_cr + Diff_H2*div(grad(u(4)))
5) ug*cpavg_g*u(1)*du(5)/dz = -dHr_cr*r_cr + lambda*div(grad(u(5)))
For the boundary conditions:
a) For Face 1 (entrance of reactor): u(1) = u(2) = 160; u(3) = u(4) = 0; u(5) = 300;
b) For Face 3 (walls): u(5) = 800. Other variables are not bounded.
c) For Face 2 (exit): No boundary conditions.
But when I try to run the code, I get the following errors:
Warning: Matrix is singular to working precision.
> In pde.EquationModel/solveStationaryNonlinear (line 21)
In pde.PDEModel/solvepde (line 77)
In Codigo_AQ4 (line 55)
Error using pde.EquationModel/solveStationaryNonlinear (line 27)
Unsuitable initial guess U0 (default: U0=0).
By reading the documentation, the error "Unsuitable initial guess U0" means the initial guess is NaN or Inf. Is there any way to change the default U0 = 0 to prevent this? For what I understand, since I specified the boundary conditions at the entrace (Face 1), I would have specified U0, which, in this case, is not zero. Is there anything I am overlooking? Thanks in advance for the help.Gabriel Shttps://au.mathworks.com/matlabcentral/profile/authors/17716840-gabriel-stag:au.mathworks.com,2005:Question/5135532020-03-28T11:23:14Z2020-03-29T04:42:33ZWhy there is a sudden jump from 0 to 2pi and from 2pi to 0 in position of DC motor in my Design in simulink? And why are the continuous simulations occurring in my designHere is a sudden jump from 0 to 2pi and from 2pi to 0 in position of DC motor in my Design in simulink. I want to know why this is happening.
And also the oscillations are also continuous, so how can we remove the continuously occuring oscillations.
PFA for the Reference design.
Ayush Srivastavahttps://au.mathworks.com/matlabcentral/profile/authors/12879388-ayush-srivastavatag:au.mathworks.com,2005:Question/5129732020-03-25T21:53:01Z2020-03-29T04:39:58ZHow to generate a round robin schedule with 4 players in each gameI'm trying to come up with a schedule for me and my friends to have a Smash Bros league. Each game will have 4 players that receive more points the better they do. How would I go about generating a schedule in which all the teams play each other a similar amount of times? Our league is going to have 10 teams.Jacob Nelsonhttps://au.mathworks.com/matlabcentral/profile/authors/17943025-jacob-nelsontag:au.mathworks.com,2005:Question/5135582020-03-28T12:00:09Z2020-03-29T04:33:06ZMonthly data to seasonal using sumHi, I wish you are safe and healthy!
I have a 1 x 3 cell with three 360 x 3 table. Each table has a column date with 30 years of monthly data (30 x 12 = 360). I want to have data for seasonal scale, winter, spring, summer and autumn correspond to December–February, March-May, June–August, and September–November, respectively using sum. I would like to create each season in a separate column with the corresponding name of the season and located after all existing columns in the tables.
Thank you so much. Behzad Navidihttps://au.mathworks.com/matlabcentral/profile/authors/15525777-behzad-naviditag:au.mathworks.com,2005:Question/5136792020-03-29T04:31:37Z2020-03-29T04:31:37Zode15s meshgrid issueWhen trying to run a code created by one of my professors to be manipulated for my homework, I get an error that says:
Error in ode15s (line 294)
[kJ,kI] = meshgrid(maxK,maxK);
My code cannot run because my ode15s solver is somehow incorrect on y computer even though I have never manipulated it before. Please send help.
Thank you,
KaylaKayla Jacobshttps://au.mathworks.com/matlabcentral/profile/authors/8625509-kayla-jacobstag:au.mathworks.com,2005:Question/5116062020-03-18T18:50:42Z2020-03-29T04:30:33ZIs it possible to change the color of an object in Simscape Multibody during a simulation?I would like to be able to visually communicate system parameters by the color of a body. For example, a linkage turns yellow when it gets within 10 degrees of its limits, or a wheel turns red when it stops turning, etc.
Is this possible? Or does anyone have any tricks to convey this information synchronously with the model animation?Cyndia Caohttps://au.mathworks.com/matlabcentral/profile/authors/13329891-cyndia-caotag:au.mathworks.com,2005:Question/5136782020-03-29T04:17:01Z2020-03-29T04:28:19ZHow to work around the precision problem?I am aware that certain numbers cannot be perfectly represented in binary, and as a result some of the numbers are not exact.
I am trying to calculate the numerical derivative of x^4 + 3x^3 - 2x^2 + x - 2
n = 10001;
lb = 0;
ub = 2;
dx = (ub-lb)/(n-1);
t = 1:n;
x = t*dx - dx;
u0 = x.^4+3*x.^3-2*x.^2+x-2;
figure;
hold on;
plot(x,u0);
drawnow;
u = u0;
ntemp = n;
ntempstart = 1;
for i = 1:4
du_dx = dudx(u,dx,length(ntempstart:ntemp));
ntempstart = ntempstart+1;
ntemp = ntemp - 1;
plot(x(ntempstart:ntemp),du_dx);
drawnow;
u = du_dx;
end
function du_dx = dudx(u,dx,n)
du_dx = zeros(1,n-2);
for i = 2:n-1
du_dx(i-1) = (u(i+1) - u(i-1))/(2*dx);
end
end
This is a debugging process for a numerical solution of the KdV equation and I am asked to solve the derivatives in KdV using derivative definition such as the one defined here. I am trying to get to the bottom of this:
When I run the above code with n = 1001 or smaller number of increments, it produces the expected derivative results. But when I increase it to 10001 as shown, I get the following. I believe the problem is caused by the precision limitations. Is the only solution to not use such a high number of increments? I tried to round the values for the third and fourth derivative, but they do not help. Rounding for all cases makes it worse.
Zhangxi Fenghttps://au.mathworks.com/matlabcentral/profile/authors/6880103-zhangxi-fengtag:au.mathworks.com,2005:Question/5136512020-03-28T23:08:52Z2020-03-29T04:19:28ZFunction running slow than scripts when placed in a 'for loop'?I am trying to execute a program which has a function being called in a for loop, say:
%version1
for i =1 : 1000
x = myfunc1(a,b,c);
y = myfunc2(d,e,f);
[m,n,o] = myfunc(x,y);
end
Now, when I code the same goal in a different way using scripts like:
%version2
for i =1 : 1000
x = a + b + c; %function is more complicated
y = d + e + f; %function is more complicated
m = x*y; %function is more complicated
n = x*x*y; %function is more complicated
o = x*y*y; %function is more complicated
end
Version 2 is 3x faster than version 1 while both give same values. Why is that happening? When to use scripts and when to use functions in a generic sense?
Thanks..Angshuman Podderhttps://au.mathworks.com/matlabcentral/profile/authors/17472414-angshuman-poddertag:au.mathworks.com,2005:Question/5136772020-03-29T04:16:55Z2020-03-29T04:18:20Zcurve fitting and image segmentationHi all, I have a grayscale image-'FLIR0888.jpg' (attatched within) I have segmented this image into right and left breasts by fitting a polynomial curve and finding the intersection point of the two fitted curves. Now, below is the image of right breast and the curve fitted is shown in blue. How do i segment the grayscale image along this blue curve? I want the part of the image below this blue curve to be gone. How do I approach this? I have attatched the code and the original image below, thanks in advance.
clc;
clear;
close all;
a=rgb2gray(imread('FLIR0888.jpg'));
ed=edge(a,'canny',0.2,0.5);
bw1=bwareaopen(ed,10);
bw=imdilate(bw1,true(3));
se = strel('disk',4);
I=imclose(bw,se);
BW=imclearborder(I);
[B,L]= bwboundaries(BW,'noholes');
[~,I] = sort(cellfun(@length,B),'descend');
BB= B(I);
x1 = BB{1}(:, 2);y1 = BB{1}(:, 1);
x2 = BB{2}(:, 2);y2 = BB{2}(:, 1);
P1=polyfit(y1,x1,3);
P2=polyfit(y2,x2,3);
yy = linspace( 1, size(L,1));
p1=polyval( P1, yy );
p2=polyval( P2, yy);
x_intersect = fzero(@(x) polyval(P1-P2,x),3);
y_intersect = polyval(P1,x_intersect);
segimgR=a(:,1:y_intersect);
[m,n]=size(segimgR);
segimgl=a(:,y_intersect:end);
segimgL=imresize(segimgl,[m,n]);
figure()
subplot(2,2,1);imshow(a);title('original image');
subplot(2,2,2);imshow(a, 'border', 'tight' );
hold on
plot(p1,yy);
plot(p2,yy);
hold off
subplot(2,2,3);imshow(segimgR);
subplot(2,2,4);imshow(segimgL);
figure()
subplot(1,2,1);imshow(segimgR);
hold on
plot(p1,yy);
hold off
Apoorva Maiyahttps://au.mathworks.com/matlabcentral/profile/authors/15769688-apoorva-maiyatag:au.mathworks.com,2005:Question/1695492015-01-11T07:30:46Z2020-03-29T04:08:47ZHow can I write such a large matrix? thank you very much, how can I construct the matrix b, b: no. of column=20 and
no. of rows=2^20=1048576.
the first column=[0 1 0 1 0 1 ........]
the second column=[0 0 1 1 0 0 1 1 0 0 1 1 ........]
the third column=[0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 ..........]
the fourth column=[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1..................]
and so on. instead of the following command
for j=1:20
for k=0:(2^(ns-j))-1
a((2^(j-1))+1+k*(2^j):(2^j)+k*(2^j))=1;
end
b(j,:)=a;
clear a
end
b=b';
to take less time compared with the commands I useesraahttps://au.mathworks.com/matlabcentral/profile/authors/5323729-esraatag:au.mathworks.com,2005:Question/5136752020-03-29T04:05:23Z2020-03-29T04:05:23ZHow do I plug in the same value into different equations using a for loop?I have several equations that came from polynoial fits in excel, theyre aout 4500 different equations. I just want to plug in the same value into each one of them.
How do I do this ? Can I use a for loop? I just want to do it effectively.Aisha Junet Fregosohttps://au.mathworks.com/matlabcentral/profile/authors/17977627-aisha-junet-fregosotag:au.mathworks.com,2005:Question/5136112020-03-28T18:30:58Z2020-03-29T04:00:40ZHow to graph values of a function above and below 0 as separate functions?I need to create a graph of y=sin(x). Where y is greater than zero, have a separate function of y^2, and where y is less than zero, have a function y^3. These should all exist on the same plot.
I think I have to define y2 and y3 ouside of the if statement. If I set y2=y; ouside 'if', I have y throughout the whole graph. Either way, the if statement doesn't seem to work.
And on top of that, I don't know how to graph this, because x and y2 will be different lengths if y2 only exists where y>0
Here is what I came up with, but it totally doesn't work. The photo included is a more complex function, but the idea is exactly the same. I'm supposed to use if and elseif. Thank you! Stay safe and healthy everyone!
t= 0:0.2:3*pi;
y=sin(t);
figure(1)
plot(t,y,'-.b')
grid on
hold on
if y>0
y2=y.^2;
elseif y<0;
y3=y.^3;
end
figure(1)
plot(t,y2,'om')
figure(1)
plot(t,y3,'dk')
Konrad Kruschehttps://au.mathworks.com/matlabcentral/profile/authors/17692371-konrad-kruschetag:au.mathworks.com,2005:Question/5136742020-03-29T03:52:15Z2020-03-29T03:52:57ZMatlab 2020 plot icons missingI recently installed 2020 and the plot tools are not the same.
There used to be an icon on the very right of the toolbar to open figure palette,
plot browser, and property editor. Now I have to click view > figure palette,
then view > plot browser, then view > property editor.
Is there a way to add these icons as before?Zahra Sharifnezhadazizihttps://au.mathworks.com/matlabcentral/profile/authors/8736014-zahra-sharifnezhadazizitag:au.mathworks.com,2005:Question/5136692020-03-29T03:24:17Z2020-03-29T03:51:29Zillogical graph values when plotting shear diagramI am trying to solve the following problem where i need to plot the shear diagram but in deed when ever i try to plot my graph it comes with illogical values
i am forced to use the function calc with no change to it (thats the only condition ) i can only change my script and in what context do i call my function
am getting the following graph
My script :
clc;
clear all;
w=2;
EI=1e6;
L=10;
x=linspace(0,L,1000)
a1=1;
an=4;
UDL=an-a1;
a=linspace(a1,an,1000);
dis=linspace(1,L,1000);
for i=1:length(a)
res=calc(dis(i),L,[w a(i)],EI);
v(i)=res(1);
m(i)=res(2);
y(i)=res(3);
end
plot(x,v);
the function calc :(should not change anyhting in it)
function [ res ] = calc( x,L,Load,EI )
%it is used to find the shear moment and deflection
%for a simply supported beam in 2 cases
% UDL, point load
if length(Load)==1 %UDL
P=Load;
res(1) = P*L/2-P*x;
res(2) = P*L/2*x-P*x ^2/2;
res(3) = -P*x/(24*EI)*(L^3-2*L*x^2+x^3);
elseif length(Load)==2 %Point load
F=Load(1);
a=Load(2);
b=L-a;R1=F*b/L;R2=F*a/L;
if x <= a
res(1) = R1;
res(2) = R1*x;
res(3) = -F*b*x/(6*L*EI)*(L^2-x^2-b^2);
else
res(1) = -R2;
res(2) = R1*x -F*(x-a);
res(3) = -F*b/(6*L*EI)*(L/b*(x-a)^3+(L^2-b^2)*x-x^3);
end
else
res=[];
end
end
Ali Ramadanhttps://au.mathworks.com/matlabcentral/profile/authors/17352668-ali-ramadantag:au.mathworks.com,2005:Question/5136732020-03-29T03:50:55Z2020-03-29T03:50:55Zwhy I cant use velodyneFileReaderhello here,
I am new to this velodyne toolbox, and I am try using velodyneFileReader to read my recorded PCAP file (around 9GB).
the code is as follows
veloReader = velodyneFileReader('velodyne.pcap','VLP16')
but it gives me
vision.internal.VelodyneFileReader/open
Error reading packet from PCAP file bogus savefile header.
velodyneFileReader (line 269)
tmpReturnStruct = open(this.VelodyneFileReaderObj, this.FileName,...
rosbagtest (line 4)
veloReader = velodyneFileReader('velodyne.pcap','VLP16')
I have tried this command with my other PCAP files (up to 1GB), they were all fine, so I am wondering if there is a size limit with this command or some other issues, thanks.
YUSHENG WANGhttps://au.mathworks.com/matlabcentral/profile/authors/17978375-yusheng-wangtag:au.mathworks.com,2005:Question/5136702020-03-29T03:26:04Z2020-03-29T03:26:04Zhow to start with FFTHI every one ,
I had data for 3 sensors with time ,the data = 33034 cell
so Now I need to change from time domain to freqancy domian
I don't know exactly how to start . first calcute the time interval / sampling freqancy
Evahttps://au.mathworks.com/matlabcentral/profile/authors/8229550-evatag:au.mathworks.com,2005:Question/3804972018-02-03T00:33:39Z2020-03-29T03:23:53ZHigh Idle CPU Usage Due to Java on LinuxI have experienced this across multiple versions of Matlab and Linux kernels and have yet to find the cause. I'm currently on 2017b, Linux Mint 18.1, kernel 4.12. As soon as I launch Matlab, three of my 4 cores are pegged, and the 4th core is showing 50% usage. The GUI is completely unresponsive and eventually I will either get a Java crash in the command window or I have to kill the Matlab process entirely. Launching with -nojvm doesn't cause the same problem, but I would like to be able to run Matlab with the GUI.
>ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.3.0.713579 (R2017b)
MATLAB License Number: XXXXXX
Operating System: Linux 4.12.0-041200-generic #201707022031 SMP Mon Jul 3 00:32:52 UTC 2017 x86_64
Java Version: Java 1.8.0_121-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.3 (R2017b)
Simulink Version 9.0 (R2017b)
Bioinformatics Toolbox Version 4.9 (R2017b)
Control System Toolbox Version 10.3 (R2017b)
Curve Fitting Toolbox Version 3.5.6 (R2017b)
DSP System Toolbox Version 9.5 (R2017b)
Image Processing Toolbox Version 10.1 (R2017b)
Instrument Control Toolbox Version 3.12 (R2017b)
Mapping Toolbox Version 4.5.1 (R2017b)
Optimization Toolbox Version 8.0 (R2017b)
Parallel Computing Toolbox Version 6.11 (R2017b)
Signal Processing Toolbox Version 7.5 (R2017b)
Simscape Version 4.3 (R2017b)
Simscape Multibody Version 5.1 (R2017b)
Simscape Power Systems Version 6.8 (R2017b)
Simulink Control Design Version 5.0 (R2017b)
Stateflow Version 9.0 (R2017b)
Statistics and Machine Learning Toolbox Version 11.2 (R2017b)
Symbolic Math Toolbox Version 8.0 (R2017b)
------------------------------------------------------------------------
Segmentation violation detected at Fri Feb 2 18:30:59 2018
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Current Graphics Driver: Unknown hardware
Current Visual : 0x20 (class 4, depth 24)
Default Encoding : UTF-8
Deployed : false
GNU C Library : 2.23 stable
Host Name : rosetta
MATLAB Architecture : glnxa64
MATLAB Entitlement ID: 1535817
MATLAB Root : /usr/local/MATLAB/R2017b
MATLAB Version : 9.3.0.713579 (R2017b)
OpenGL : hardware
Operating System : Linux 4.12.0-041200-generic #201707022031 SMP Mon Jul 3 00:32:52 UTC 2017 x86_64
Processor ID : x86 Family 6 Model 78 Stepping 3, GenuineIntel
Virtual Machine : Java 1.8.0_121-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11804000), display :0
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 00000007413ce3e7 RBX = 00007f9ddb91fb60
RCX = 0000000000000000 RDX = 0000000000000088
RSP = 00007f9dcc2f82f0 RBP = 00007f9dcc2f8350
RSI = 00007f9dcc2f8380 RDI = 00000000000003b8
R8 = 00007f9ddb91bc60 R9 = 0000000000000877
R10 = 00007f9dcc2f8300 R11 = 0000000000000001
R12 = 00007f9dcc2f8380 R13 = 0000000000000004
R14 = 00007f9ddb91f9e0 R15 = 00007f9dcc2f8420
RIP = 00007f9ddaf33bf5 EFL = 0000000000010216
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007f9ddaf33bf5 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+06130677
[ 1] 0x00007f9ddaf3b9b8 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+06162872
[ 2] 0x00007f9ddb2e3579 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+09995641
[ 3] 0x00007f9ddb2e61a2 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+10006946
[ 4] 0x00007f9ddb2ec02d /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+10031149
[ 5] 0x00007f9ddb2a2c10 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+09731088
[ 6] 0x00007f9ddb423a57 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+11307607
[ 7] 0x00007f9ddb42b535 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+11339061
[ 8] 0x00007f9ddb42990a /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+11331850
[ 9] 0x00007f9ddb429c8e /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+11332750
[ 10] 0x00007f9ddb42a100 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+11333888
[ 11] 0x00007f9ddb281268 /usr/local/MATLAB/R2017b/sys/java/jre/glnxa64/jre/lib/amd64/server/libjvm.so+09593448
[ 12] 0x00007f9e0b5cf6ba /lib/x86_64-linux-gnu/libpthread.so.0+00030394
[ 13] 0x00007f9e0b3053dd /lib/x86_64-linux-gnu/libc.so.6+01078237 clone+00000109
[ 14] 0x0000000000000000 <unknown-module>+00000000
ss32https://au.mathworks.com/matlabcentral/profile/authors/5624262-ss32tag:au.mathworks.com,2005:Question/5136642020-03-29T02:35:57Z2020-03-29T03:18:44Zerror message "management.cpp:712 (anonymous namespace)" when compiling mex with openmpHello,
I am compiling mex function with openmp using MATLAB 2019b and gcc-6.3.0.
My mex command is the following:
mex mex_count.cpp CXXFLAGS="$CXXFLAGS -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -std=c++11 -fopenmp" -lgomp;
While mex is compiled competed successfully, I still got the following error message:
Building with 'g++'.
MEX completed successfully.
MATLAB: management.cpp:712: find: Assertion `find: no active context for type '(anonymous namespace)::AlreadyReportedFailure'' failed.
Hello World from thread 0, 0
Hello World from thread 0, 5
Hello World from thread 0, 10
MATLAB: management.cpp:712: find: Assertion `find: no active context for type '(anonymous namespace)::AlreadyReportedFailure'' failed.
The same code runs successfully using MATLAB 2017b and gcc-4.8.5. The error occurs when I move everything to google cloud platform.
Thank you,
YangfanYangfan Sunhttps://au.mathworks.com/matlabcentral/profile/authors/6875619-yangfan-suntag:au.mathworks.com,2005:Question/5130712020-03-26T10:04:30Z2020-03-29T03:17:11ZComplex implicit function 2D plotI am trying to plot a implicit function of the form
H2 = 100;
n2 = 2.0;
n1 = 1.47;
rho = 0;
m = 1;
fun = @(x,y) sqrt((2.*pi/x)^2.*n2^2-y^2).*H2-2.*atan( ((n2/n1)^(2.*rho)).*sqrt((y^2-n1^2.*(2.*pi/x)^2)/(n2^2.*(2.*pi/x)^2-y^2)) )-m.*pi;
I already tried
ezplot(fun, [300, 700, 0, 1]);
But it shows no plot and there is a warning
Warning: Function failed to evaluate on array inputs; vectorizing the function may speed up its
evaluation and avoid the need to loop over array elements.
Any help?
ThanksJiacong Sunhttps://au.mathworks.com/matlabcentral/profile/authors/17711599-jiacong-suntag:au.mathworks.com,2005:Question/5136612020-03-29T02:11:36Z2020-03-29T03:11:41Zhdl coder error when compiling stateflowI can't figure out this error hdl coder is giving me when compiling a stateflow chart with parallel charts
Enumerated name 'IN_NO_ACTIVE_CHILD' is present in types 'state_type_is_TIMEOUT_WATCHER' and 'state_type_is_COUNT_IS_VALID'. Use unique enum type names for HDL code generation.
I attached the chart as pictures
Thanks for any helpAmish Rughoonundonhttps://au.mathworks.com/matlabcentral/profile/authors/1927235-amish-rughoonundontag:au.mathworks.com,2005:Question/5136582020-03-29T01:20:08Z2020-03-29T03:07:17Zwritematrix with Range has problem. Hello.
I am confusing while I am using 'writematrix'.
Here is the code have the problem.
for i=1:5
CellRange = ['A',num2str(i)];
writematrix(filename,'Sheet',1,'Range','CellRange')
end
I know the Range should be Character type.
for i=1:5
firstRow = i;
firstCol = 'C';
cellRange = [firstCol,num2str(firstRow)];
end
Result of cellRange is character type as I expected.
But when I applied this into upper code, it's error message said that 'The range must be a character vector of the form 'A1:B2' or 'A1''
Is there something adjust for this?
Thank you. Kyoungtak Kimhttps://au.mathworks.com/matlabcentral/profile/authors/12674754-kyoungtak-kim