https://ww2.mathworks.cn/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-12-15T14:05:41Ztag:ww2.mathworks.cn,2005:Question/4358952018-12-15T13:59:49Z2018-12-15T14:05:41ZWhy matlab not simplify my answer?Hello can you hel me please
Here is my script:
u=symunit;
L= input('Lenght of where you would like to measure the deflection in meter: ')*u.m
L=unitConvert(L,u.mm);
W=8500*u.N;
E=42000 *u.N/u.mm^2;
I=10*(10^6)*u.mm^4;
D=(W*L^3)/(8*E*I)
and the answer is :
D =
(53125/21)*[mm]
How can I get matlab to simplify this for me? Thanks
Milan Sumegihttps://ww2.mathworks.cn/matlabcentral/profile/authors/13607472-milan-sumegitag:ww2.mathworks.cn,2005:Question/4358962018-12-15T14:02:46Z2018-12-15T14:02:46ZWhy my subplot imshow not equally. Hi, I have a problem. My subplot imshow not equally even though image size is equally.
k = 1;
for i=1:2:col_size
m = 1;
for r=1:rml
n = 1;
for c=col(i):col(i+1)
letter(m,n) = ime(r,c);
n = n + 1;
end
m = m + 1;
end
if size(letter,2) >= 6 && size(letter,1) <= 90
subplot(1,(col_size/2),k);
imshow(letter);
k = k + 1;
end
clear letter;
end
Suttipong Pramuansinhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14372374-suttipong-pramuansintag:ww2.mathworks.cn,2005:Question/4351942018-12-11T16:45:16Z2018-12-15T14:02:35ZHow to delete the following items([yr , y3 ,y4 ,y11, y111, yr1 ,yr11, yn1 ,yn11, fn, fnr, fn1, fn2])syms y yr y1 y2 y3 y4 y11 y111 yr1 yr11 yn1 yn11 h fn fnr fn1 fn2
r=1.7585889236061132562137339518147
eq1=-y2-(r - 2)/r*y+ 2/(r*(r - 1))*yr+ (2*r - 4)/(r - 1)*y1 -(h^3*(r^4 - 8*r^3 + 22*r^2 - 23*r + 6))/(120*r)*fn+ (h^3*(- r^2 + 2*r + 3))/(60*r)*fnr -(h^3*(- r^3 + 4*r^2 + 9*r - 26))/60*fn1+ (h^3*(- r^3 + 2*r + 1))/120*fn2
eq2=-h*y3-(r - 3)/r*y+ 3/(r*(r - 1))*yr+ (r - 4)/(r - 1)*y1 -(h^3*(3*r^4 - 24*r^3 + 66*r^2 - 67*r + 12))/(240*r)*fn -(h^3*(r^4 - 5*r^3 + 5*r^2 + 5*r - 4))/(40*r*(r^2 - 3*r + 2))*fnr -(h^3*(- 3*r^4 + 15*r^3 + 15*r^2 - 137*r + 116))/(120*(r - 1))*fn1+ (h^3*(- r^4 + 2*r^3 + 2*r^2 + 3*r - 12))/(80*(r - 2))*fn2
eq3=-h^2*y4+2/r*y+ 2/(r*(r - 1))*yr -2/(r - 1)*y1+ (h^3*(- r^4 + 8*r^3 - 22*r^2 + 18*r + 5))/(120*r)*fn -(h^3*(r^4 - 5*r^3 + 5*r^2 + 5*r + 5))/(60*r*(r^2 - 3*r + 2))*fnr -(h^3*(- r^4 + 5*r^3 + 5*r^2 - 75*r + 77))/(60*(r - 1))*fn1+ (h^3*(- r^4 + 2*r^3 + 2*r^2 + 42*r - 81))/(120*(r -2))*fn2
eq4=-h*y11-(r - 1)/r*y+ 1/(r*(r - 1))*yr+ (r - 2)/(r - 1)*y1 -(h^3*(r^4 - 8*r^3 + 22*r^2 - 21*r + 6))/(240*r)*fn+ (h^3*(- r^2 + 2*r + 3))/(120*r)*fnr-(h^3*(- r^3 + 4*r^2 + 9*r - 8))/120*fn1 -(h^3*(r^3 - 2*r + 1))/240*fn2
eq5=-h^2*y111+2/r*y+ 2/(r*(r - 1))*yr -2/(r - 1)*y1 -(h^3*(r^4 - 8*r^3 + 22*r^2 - 28*r + 10))/(120*r)*fn -(h^3*(r^4 - 5*r^3 + 5*r^2 + 5*r - 10))/(60*r*(r^2 - 3*r + 2))*fnr -(h^3*(- r^4 + 5*r^3 + 5*r^2 - 35*r + 22))/(60*(r - 1))*fn1+ (h^3*(- r^4 + 2*r^3 + 2*r^2 - 8*r + 4))/(120*(r - 2))*fn2
eq6=-h*yr1-(r - 1)/r*y+ (2*r - 1)/(r*(r - 1))*yr -r/(r - 1)*y1+ (h^3*(2*r^4 - 13*r^3 + 28*r^2 - 22*r + 5))/240*fn+ (h^3*(4*r^3 - 15*r^2 + 10*r + 5))/(120*(r - 2))*fnr+(h^3*r*(- 2*r^3 + 7*r^2 + 2*r - 3))/120*fn1+ (h^3*r*(2*r^4 - 5*r^3 + 2*r^2 + 2*r - 1))/(240*(r - 2))*fn2
eq7=-h^2*yr11-2/r*y+ 2/(r*(r - 1))*yr -2/(r - 1)*y1+ (h^3*(4*r^4 - 22*r^3 + 38*r^2 - 22*r + 5))/(120*r)*fn -(h^3*(- 14*r^4 + 55*r^3 - 55*r^2 + 5*r + 5))/(60*r*(r^2 - 3*r + 2))*fnr -(h^3*(4*r^4 - 15*r^3 + 5*r^2 + 5*r - 3))/(60*(r - 1))*fn1+ (h^3*(4*r^4 - 8*r^3 + 2*r^2 + 2*r - 1))/(120*(r - 2))*fn2
eq8=-h*yn1-(r + 1)/r*y -1/(r*(r - 1))*yr+ r/(r - 1)*y1+ (h^3*(r^3 - 8*r^2 + 22*r - 5))/240*fn+ (h^3*(r^3 - 5*r^2 + 5*r + 5))/(120*(r^2 - 3*r + 2))*fnr+ (h^3*r*(- r^3 + 5*r^2 + 5*r - 3))/(120*(r - 1))*fn1 -(h^3*r*(- r^3 + 2*r^2 + 2*r - 1))/(240*(r - 2))*fn2
eq9=-h^2*yn11-2/r*y+ 2/(r*(r - 1))*yr -2/(r - 1)*y1 -(h^3*(r^4 - 8*r^3 + 22*r^2 + 22*r - 5))/(120*r)*fn -(h^3*(r^4 - 5*r^3 + 5*r^2 + 5*r + 5))/(60*r*(r^2 - 3*r + 2))*fnr -(h^3*(- r^4 + 5*r^3 + 5*r^2 + 5*r - 3))/(60*(r - 1))*fn1+ (h^3*(- r^4 + 2*r^3 + 2*r^2 + 2*r - 1))/(120*(r - 2))*fn2
sadeem alqarnihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12452026-sadeem-alqarnitag:ww2.mathworks.cn,2005:Question/4358942018-12-15T13:53:36Z2018-12-15T13:55:16ZFourier transform how to get coefficientsHey everyone, i know that matlab have the method for fourier transform implemented but i was wondering if there is anything that could give me coefficients of fourier transfrom.Vincent Sinhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13709665-vincent-sintag:ww2.mathworks.cn,2005:Question/4358932018-12-15T13:49:13Z2018-12-15T13:51:05ZCode generation for simulink model with MATLAB function withinHi
I'm trying to generate a C code(in .cpp files format) for a simulink model which contains a MATLAB function block using embedded coder .
The generated code is expected to run on an Arduino platform.
I am able to generate a C code when I select the output of my generated code format as " C code" in the embedded coder window, but I got the following error while generating a "C code in .cpp files" format:
### Starting build procedure for model: code_gen_model
### Generating code into build folder: C:\Users\lakshmi\Documents\MATLAB\Simulink\test\code_gen_model_ert_rtw
### Invoking Target Language Compiler on code_gen_model.rtw
### Using System Target File: C:\Program Files\MATLAB\R2017a\rtw\c\ert\ert.tlc
### Loading TLC function libraries ......
### Initial pass through model to cache user defined code ....
### Caching model source code .................................................
### Writing source file code_gen_model.cpp
### Writing header file climate_control.h .
### Writing header file rtwtypes.h
### Writing source file ert_main.cpp
### TLC code generation complete.
### Build procedure for model: 'code_gen_model' aborted due to an error.
Reference to non-existent field 'generateCodeOnly'.
I have selected the check box " Generate code only" in the Configuration Parameters-> Code Generation
I appreciate if someone can provide any inputs on how to solve this issue.
Regards,
Rajalakshmi
Rajalakshmi Menasinakaihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12705334-rajalakshmi-menasinakaitag:ww2.mathworks.cn,2005:Question/4016242018-05-20T08:27:31Z2018-12-15T13:50:26ZSolution of system of linear equationDear All
I need to solve the system of linear equations. I have 5 variables [t0 rp V theta alpha]. I need to calculate V, theta, alpha from the following three equations at different known values of t0 and rp using solve command but the following message appears. Note : the first guess for t0=20e-3;rp=0.2e-2.
"Error using solve (line 278)
Input with 3 variables and output with 2 variables are inconsistent."
a = 0.45611;b1= 17.03;
q1 = 0.062988; q2 = 18.68;
c1 = 0.0026617;c2= -0.9238;
g=9.81; S=0.012;ro=1000;mw=5;rw=0.2e-3;m_bar=0.8;
syms V alpha theta
d1 =((1/2)*ro*V^2)*S*(a + b1*alpha^2);
Q = ((1/2)*ro*V^2)*S*(q1+q2*alpha);
T = ((1/2)*ro*V^2)*S*(c1 + c2*alpha);
eqn1 = -t0*g*sin(theta)+Q*alpha-d1 == 0;
eqn2 = t0*g*cos(theta)-Q-d1*alpha == 0;
eqn3 = T-m_bar*g*rp*cos(theta)==0;
eqns=[eqn1 eqn1 eqn3]
vars = [V alpha theta];
[solv, solu] = solve(eqns, vars)Barkathttps://ww2.mathworks.cn/matlabcentral/profile/authors/5528315-barkattag:ww2.mathworks.cn,2005:Question/4358922018-12-15T13:40:51Z2018-12-15T13:47:56ZI would like to write a computation that will take a vector of 1xN length and then add adjacent matrix values . I would like to write a computation that will take a vector of 1xN length and then add adjacent matrix values .
e.g. [a+b,c+d,e+f,g+h,....etc]
My thoughts were to write something along the lines of n-(n-1), n-(n-2) to calculate this step.
However I don't want to continuously write this for a N=256 row.
How could I do this? Victor Fletcherhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14218587-victor-fletchertag:ww2.mathworks.cn,2005:Question/4358862018-12-15T12:44:26Z2018-12-15T13:45:36ZHow to xlabel and ylabel while using pchip?x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30]
y=[76.35 65.69 61.58 60.04 59.60 59.71 60.12 60.67 61.30 61.96 62.64 63.30 63.94 64.55 65.13 65.67 66.18 66.66 67.10 67.56 67.98 68.39 68.77 69.14 69.65 69.82 70.14 70.44 70.74 71.01]
xi=0.1:0.01:35;
yi=interp1(x,y,xi,'pchip');
plot(x,y,'r*',xi,yi)
xlabel('energy')
ylabel('efficiency')
This is the code. When I run it the plot appears but there is no xlabel and ylabel. What's the problem in it?Asit Srivastavahttps://ww2.mathworks.cn/matlabcentral/profile/authors/13266273-asit-srivastavatag:ww2.mathworks.cn,2005:Question/4358912018-12-15T13:31:58Z2018-12-15T13:42:23Zwriting variable in xls fileHi
i have a code that produce three variable a b c
i want to save this value in a xls file that the value writing in sheet1 at A B C column
what is the proper statament to write thiw variable
thank you very much
Georgegeorge veropouloshttps://ww2.mathworks.cn/matlabcentral/profile/authors/1021212-george-veropoulostag:ww2.mathworks.cn,2005:Question/3058582016-10-05T10:03:53Z2018-12-15T13:37:43Zsolving system of fife linear equationsHow can I get answer of solving system of fife linear first order equations with seven unknowns? I want the answer will be as a function of only two unknowns.Shirin Muhammadhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8904701-shirin-muhammadtag:ww2.mathworks.cn,2005:Question/4358832018-12-15T12:18:14Z2018-12-15T13:37:19ZIs there an Optimization Tool that returns a function?Hey:)
So this is my problem:
I want to maximize the final mass of an ascending rocket into an orbit by controlling the trajectory over a thrust vector control variable a(t). So I need an Optimization Toolbox that returns me the optimal function a(t), but the objective function I want to minimize is m(t). And I couldn't find anything about this anywhere. I tried for example fmincon, but fmincon only returns a scalar.
Do you have any ideas?
Brendan Görreshttps://ww2.mathworks.cn/matlabcentral/profile/authors/13254816-brendan-gorrestag:ww2.mathworks.cn,2005:Question/3132842016-11-21T14:44:12Z2018-12-15T13:36:50Zsolve any amount of systems of linear equationsi have a question that wants me to solve any number of systems of linear equations and to differentiate between no solutions, infinite solution, and one solution and list it out. i'm just really confused and i don't know where to start. I understand solving when the system is given im just having trouble because it's notRachel Younghttps://ww2.mathworks.cn/matlabcentral/profile/authors/9237671-rachel-youngtag:ww2.mathworks.cn,2005:Question/73802011-05-13T15:53:32Z2018-12-15T13:36:35ZSolving a system of linear equations getting the matrixHello,
I have a system of linear equation of this shape {Z}=[A_1]{X}+[A_2]{Y}, where Y has different variables (in the example there are 2, but might arrive at 6 in the future) and they are polynomials of grade n=6 (in the example I limit to 2).
example:
z_1=A_0+A_1*x_1+A_2*x_1^2+A_3*y_1+A_4*y_1^2
z_2=A_0+A_1*x_2+A_2*x_2^2+A_3*y_2+A_4*y_2^2
z_3=A_0+A_1*x_3+A_2*x_3^2+A_3*y_3+A_4*y_3^2
z_4=A_0+A_1*x_4+A_2*x_4^2+A_3*y_4+A_4*y_4^2
z_5=A_0+A_1*x_5+A_2*x_5^2+A_3*y_5+A_4*y_5^2
I put the combination of polynomials together. I want to calculate the coefficients A_i, since I know x_i, y_i and z_i.
Is there a function or a straightforward manner to calculate or do you have any suggestion how to approach it?
Thank you
Antoniomortain Antoniohttps://ww2.mathworks.cn/matlabcentral/profile/authors/2412497-mortain-antoniotag:ww2.mathworks.cn,2005:Question/4081452018-06-30T02:09:32Z2018-12-15T13:35:44ZHow to setup system of linear equations in matrix form?I have a system of four linear equations that I need to put into matrix form.
Equations are in the form of:
5x1+4x2-2x3+6x4=4
3x1+6x2+6x3+4.5x4=10 etc.
Giovanni Virgenhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12684839-giovanni-virgentag:ww2.mathworks.cn,2005:Question/660052013-03-05T18:56:40Z2018-12-15T13:34:51ZHow to solve a system of linear equations ?Hi,how can i solve this system in Mupad and get only the positive real solutions.
x + y + z = 50
5x + y + 0.1z = 50
Thank You :)Sudohttps://ww2.mathworks.cn/matlabcentral/profile/authors/3909641-sudotag:ww2.mathworks.cn,2005:Question/136672011-08-14T05:36:50Z2018-12-15T13:34:24ZSolving system of linear equation by Gaussian eliminationHow I can get the solution of system of linear equation by Gaussian elimination in MATLAB ?Reza Selimhttps://ww2.mathworks.cn/matlabcentral/profile/authors/2982459-reza-selimtag:ww2.mathworks.cn,2005:Question/3517552017-08-07T00:28:02Z2018-12-15T13:33:47Z how to solve a system of linear equations (56 unknown Variables - 56 equations)with regards , how to solve this system of linear equations ? (56 equations)
(unknown Variables are : b1 c1 d1 e1 g1 f1 s1 q1 b2 c2 d2 e2 g2 f2 s2 q2 b3 c3 d3 e3 g3 f3 s3 q3 b4 c4 d4 e4 g4 f4 s4 q4 b5 c5 d5 e5 g5 f5 s5 q5 b6 c6 d6 e6 g6 f6 s6 q6 b7 c7 d7 e7 g7 f7 s7 q7 )
homa bayathttps://ww2.mathworks.cn/matlabcentral/profile/authors/6392476-homa-bayattag:ww2.mathworks.cn,2005:Question/4121552018-07-25T22:27:38Z2018-12-15T13:33:16ZHelp solving systems of linear equationsI am trying to write a code to properly charge balance chemical reactions (complex redox reactions), and have run into some math issues. I am starting with a simple equation that I know the solution for:
I am trying to solve the equation Ax=B for the matrix A=[3 0 -2;4 2 -3;-1 4 0] when B=[0;0;0], the solution I am looking for is x=[4;1;6]. However, when I try to solve for x using x=A\B I get the following warning "Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.462128e-19." and the solution I get is x=[0;0;0].
How do I get a nonzero solution for my A matrix?
Thanks
Jesse Waltershttps://ww2.mathworks.cn/matlabcentral/profile/authors/9590407-jesse-walterstag:ww2.mathworks.cn,2005:Question/4358902018-12-15T13:31:55Z2018-12-15T13:31:55ZHow to build the stress strain curve from displacement?I am very much new in matlab, how to find the stress strain curve from displacement? i have the big data from Digital Image Correlation (DIC) software.
please give some idea how to start. thanks in advance.humayun kabir biplobhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14354720-humayun-kabir-biplobtag:ww2.mathworks.cn,2005:Question/3680972017-11-20T11:37:56Z2018-12-15T13:31:05ZSystem of linear equation with mixed solutionHi all,
Suppose I have a system of linear equations consist of 5 linear equation with 5 unknowns.
I would expect one of the solution to be a real number and the other four can be a complex number---of which 2 of them are the conjugate of the other two.
I am using "linsolve" to find the solution.
But how to force linsolve so that one of the solution is restricted to be a real number?
Or, is there any other function or method available to solve the problem?
I am copying the example matrix to be solved below. System to be solved is A*X = B
A =
-2.6561 + 0i -1.1497 + 0i -0.99492 + 0i -1.1497 + 0i -0.99492 + 0i
2 + 0i 1 + 0i 1 + 0i 1 + 0i 1 + 0i
0 + 0i 0 - 1.0723i 0 - 0.99746i 0 + 1.0723i 0 + 0.99746i
0 + 0i 0 + 1.8491i 0 + 0.047561i 0 - 1.8491i 0 - 0.047561i
-0.25067 + 0i -1.7245 + 0i -0.047682 + 0i -1.7245 + 0i 0.047682 + 0i
B =
62.5
56.731
4.9963
0
0
thank you,BeeTiawhttps://ww2.mathworks.cn/matlabcentral/profile/authors/318942-beetiawtag:ww2.mathworks.cn,2005:Question/72252011-05-11T13:32:01Z2018-12-15T13:30:51ZSolving a system of linear equations question.[EDIT: Wed Jun 15 04:15:02 UTC 2011 - Reformat - MKF]
hey . how i solve this linear equations (ODE) in matlab
x+y-2=-2z
3x+z=y+6
x+3y+4z-4=0
zizohttps://ww2.mathworks.cn/matlabcentral/profile/authors/2783119-zizotag:ww2.mathworks.cn,2005:Question/3451412017-06-17T12:22:41Z2018-12-15T13:30:20Zsolving systems of linear equations I fail to run/solve the linear equ. (Ax=B) form as below:
x1+x2=10;
x1-x2=2;
if u can help;
% it is fine with x=A\B;
clc; clear all;
syms u
A=[1 1; 1 -1]
B= [10; 2]
for i=1:2
for j=1:2
E1=A(i,j)*u - B(i) end
[uarray(j)] =solve(E1)
end
uarray=double(uarray)
% I am getting=>[0,10],[0,-2]
% I am getting=> 0 -2
ARUN BORGOHAINhttps://ww2.mathworks.cn/matlabcentral/profile/authors/3453952-arun-borgohaintag:ww2.mathworks.cn,2005:Question/4358892018-12-15T13:22:35Z2018-12-15T13:27:49Zhow can I make a s-function of PDE script file.I am trying to Use PID with concentric heat exchanger to maintain the cold water (flowing ini inner tube) outlet temperature at a specific temperature using steam(in outer tube).for that I have written .m file expressing model equation of heat exchanger. I want to make a s function representing heat exchanger to use in simulink with PID.
I am having lot of errors. i have attached my both .m files and simulink file.Chandra Kant Singhhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11476152-chandra-kant-singhtag:ww2.mathworks.cn,2005:Question/3132972016-11-21T15:35:54Z2018-12-15T13:26:37ZSystem of linear equationsmake a script that would solve a system of any number of linear equations and can tell the difference between no solution, infinite solutions, or unique solutionRachel Younghttps://ww2.mathworks.cn/matlabcentral/profile/authors/9237671-rachel-youngtag:ww2.mathworks.cn,2005:Question/4358852018-12-15T12:37:16Z2018-12-15T13:24:24ZFinding a vector as a subset of an arrayI have
a = [2 2];
b = [2 3];
How to find that 'b' contains all the elements of 'a' i.e. here two 2's. Here 'b' contains only one '2'. Prasanna Venkateshhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12939119-prasanna-venkateshtag:ww2.mathworks.cn,2005:Question/4358882018-12-15T13:17:38Z2018-12-15T13:17:38Zhow can i remove object with height smaller than x i want to remove objects from image with height smaller than x
mohamed mansourhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14369775-mohamed-mansourtag:ww2.mathworks.cn,2005:Question/4356962018-12-14T07:37:19Z2018-12-15T13:13:03ZHow can I detect that which squares are ticked in the image?How can I detect that which squares are ticked in the image?
I'm think use the normxcorr2 or imshowpair to compare the original image with ticked image, but I not sure how to do this.
Original Image:
AlexMThttps://ww2.mathworks.cn/matlabcentral/profile/authors/8178244-alexmttag:ww2.mathworks.cn,2005:Question/4350062018-12-10T18:13:05Z2018-12-15T13:10:33ZError using + Matrix dimensions must agree.how can i solve this error?
Below is my script:
function [y, cons] = TP_CONSTR_objfun(x)
y = [0,0];
cons = [0,0];
theta1=[0:0.1:pi];theta2=[0:0.1:pi];
for theta1=1:length(x(1))
for theta2=1:length(x(2))
y(1) = (-sqrt(x(1).^2+x(2).^2+x(3).^2)).*2.*(x(3)+x(1).*cos(x(4)));
%%%%%
e=(x(1).*(sin(theta1)-sin(theta2))./(2.*x(3)+x(1).*cos(theta2)-x(1).*cos(theta1)));
f=x(1).*x(3).*(cos(theta2)+cos(theta1))./(2.*x(3)+x(1).*cos(theta2)-x(1).*cos(theta1));
px=e.*y+f;
d=1+e.^2;
g=2.*(e.*f-e.*x(1).*cos(theta1)+e.*x(3)-x(1).*sin(theta1));
h=f.^2-2.*f.*(x(1).*cos(theta1)-x(3))-2.*x(1).*x(3).*cos(theta1)+x(3).^2+x(1).^2-x(2).^2;
py=-g+sqrt(g.^2-4.*d.*h)./2.*d;
%%%%%%%%%%
y(2)=(((py - x(1).*sin(theta2)).^2.*(sin(theta1).*(x(3) + px) - py.*cos(theta1)).^2)./(2.*(x(1).*py.*cos(theta1) - 2.*x(3).*py - x(1).*py.*cos(theta2) + x(1).*x(3).*sin(theta1) + x(1).*x(3).*sin(theta2) - x(1).*px.*sin(theta1) + x(1).*px.*sin(theta2) - x(1).^2.*cos(theta1).*sin(theta2) + x(1).^2.*cos(theta2).*sin(theta1)).^2) + ((py - x(1).*sin(theta1)).^2.*(py.*cos(theta2) + sin(theta2).*(x(3) - px)).^2)./(2.*(x(1).*py.*cos(theta1) - 2.*x(3).*py - x(1).*py.*cos(theta2) + x(1).*x(3).*sin(theta1) + x(1).*x(3).*sin(theta2) - x(1).*px.*sin(theta1) + x(1).*px.*sin(theta2) - x(1).^2.*cos(theta1).*sin(theta2) + x(1).^2.*cos(theta2).*sin(theta1)).^2) + ((sin(theta1).*(x(3) + px) - py.*cos(theta1)).^2.*(x(3) - px + x(1).*cos(theta2)).^2)./(2.*(x(1).*py.*cos(theta1) - 2.*x(3).*py - x(1).*py.*cos(theta2) + x(1).*x(3).*sin(theta1) + x(1).*x(3).*sin(theta2) - x(1).*px.*sin(theta1) + x(1).*px.*sin(theta2) - x(1).^2.*cos(theta1).*sin(theta2) + x(1).^2.*cos(theta2).*sin(theta1)).^2) + ((py.*cos(theta2) + sin(theta2).*(x(3) - px)).^2.*(x(3) + px - x(1).*cos(theta1)).^2)./(2.*(x(1).*py.*cos(theta1) - 2.*x(3).*py - x(1).*py.*cos(theta2) + x(1).*x(3).*sin(theta1) + x(1).*x(3).*sin(theta2) - x(1).*px.*sin(theta1) + x(1).*x.*sin(theta2) - x(1).^2.*cos(theta1).*sin(theta2) + x(1).^2.*cos(theta2).*sin(theta1)).^2)).^(1./2).*((py - x(1).*sin(theta1)).^2./(2.*(x(3).*sin(theta1) - py.*cos(theta1) + px.*sin(theta1)).^2) + (py - x(1).*sin(theta2)).^2./(2.*(py.*cos(theta2) + x(3).*sin(theta2) - px.*sin(theta2)).^2) + (x(3) + px - x(1).*cos(theta1)).^2./(2.*(x(3).*sin(theta1) - py.*cos(theta1) + px.*sin(theta1)).^2) + (x(3) - px + x(1).*cos(theta2)).^2./(2.*(py.*cos(theta2) + x(3).*sin(theta2) - px.*sin(theta2)).^2)).^(1./2);
end
end
% constraint function
c = (-sqrt(x(1).^2+x(2).^2+x(3).^2))-0.5;
if(c<0)
cons(1) = abs(c);
end
c = (2.*(x(3)+x(1).*cos(x(4))))-1.5;
if(c<0)
cons(2) = abs(c);
end
Thank youDikra dikrahttps://ww2.mathworks.cn/matlabcentral/profile/authors/8439132-dikra-dikratag:ww2.mathworks.cn,2005:Question/4358872018-12-15T12:58:28Z2018-12-15T13:00:55ZLeave One Out Cross Validation Hyperparameter TuningHi,
I have a dataset of motion data from different subjects which is used to do activity recognition.
To make u understand something like this
SUBJECTS DATA1 DATA2 DATA3 ........ ACTIVITY
1 32133 322332 212121 WALKING
1 54322 424242 342757 LYING
2 32133 322332 212121 WALKING
2 52322 424652 321217 RUNNING
Now my prediction is the activity column and i know there are specific function that can separate my dataset in training test and tuning hyperparameters ....
However while i'm building the classifier model i want to do a specific cross-validation in which every fold is made by all data from all subjects except one for testing. So i was thinking to use the built-in function of MATLAB and bayesopt to tune the hyperparameter of the model.
I have a data set of around 16600 observation and if i use the 'LeaveOut' option in cvpartion it gave me back the same number of folds.
Does anyone can give some advice on this ?
Every help or documentation is really appreciate.
P.S.
Observations from all subjects are not always the same number Mirko Jobhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6956447-mirko-jobtag:ww2.mathworks.cn,2005:Question/4358212018-12-14T19:00:02Z2018-12-15T12:58:18ZCan't seem to figure out how to begin on this project: Drawing circular shapes from a function that is created by connecting points.This seems like a very difficult project and I've been having trouble with this problem for a very long time. Can anybody help me figure out how to do this?
Sarjeel Zamanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11568309-sarjeel-zamantag:ww2.mathworks.cn,2005:Question/3976842018-04-27T05:43:33Z2018-12-15T12:56:13ZHow to implement a Savitzky Golay Filter in SimulinkIt is very easily to write code of Savitzky Golay Filter in matlab,but how to implement it in simulink.Can anyone please help.bidyut mandihttps://ww2.mathworks.cn/matlabcentral/profile/authors/11261743-bidyut-manditag:ww2.mathworks.cn,2005:Question/3538312017-08-23T19:13:07Z2018-12-15T12:53:57ZUsing Savitzky-Golay filter in real time simulink modelI want to use Savitzky-Golay filter in my simulink model. This function is available in matlab as this
outputsignal=sgolayfilt(inputsignal,order of filter,window size);
The way it works is as follows from some reading in the internet:
It uses least squares to regress a small window of your data onto a polynomial, then uses the polynomial to estimate the point in the center of the window. Finally the window is shifted forward by one data point and the process repeats. This continues until every point has been optimally adjusted relative to its neighbors. It works great even with noisy samples from non-periodic and non-linear sources.
I am unable to use this function in simulink. Can this be achieved in simulink using a matlab function block?
Note: I would like to generate embedded code with this,hence the need to do it in simulink. Vishal Shankarhttps://ww2.mathworks.cn/matlabcentral/profile/authors/5757766-vishal-shankartag:ww2.mathworks.cn,2005:Question/4358492018-12-14T23:08:14Z2018-12-15T12:51:15ZHow to calculate multiplying two matrices using (for) and (if) loops together ???How to calculate multiplying two matrices provided that the number of line elements in the first matrix equals the number of column elements in the second matrix (using the loop (for) and (if) together) thank youhcourah samehttps://ww2.mathworks.cn/matlabcentral/profile/authors/14369858-hcourah-sametag:ww2.mathworks.cn,2005:Question/4358802018-12-15T11:44:42Z2018-12-15T12:45:43ZChange the output Y-labels in a figure of a multi-output dynamic system
I don't know how I can change the names of the Y-labels out(1), out(2), out(3) and out(4) in this multiplot figure...thomas michielshttps://ww2.mathworks.cn/matlabcentral/profile/authors/7632051-thomas-michielstag:ww2.mathworks.cn,2005:Question/4358842018-12-15T12:23:31Z2018-12-15T12:25:27Zhow to transmit data serially from Raspberry Pi to Arduino through USB cable?Basically, my objective is to: Take a snapshot from an USB camera connected to Raspberry Pi and detect a particular object and followed by some calculations, serially transmit a 1x3 vector to Arduino Uno through USB cable.
Now , I created two models, one is to serially transmit the data from Raspberry Pi, while the other is used to serially receive the data and to flag the led on/off. These models were deployed to their respective hardwares, but I was unable to get the results. Please help me to fix this problem. I have attached both the Simulink models with this question.
Also, do I need to connect the two boards ground and vcc pins(through voltage divider bridge) together for this?
Omkar Bhanaphttps://ww2.mathworks.cn/matlabcentral/profile/authors/9528744-omkar-bhanaptag:ww2.mathworks.cn,2005:Question/4358822018-12-15T12:15:30Z2018-12-15T12:15:30ZHow can I get the subfolders to expand?Hello, I am trying to select a folder and set that folder as a root node of a graphical tree so as to be able to open the subfolders of the tree recursively. I am using:
tree= uitree ('v0', 'Root', uigetdir, 'Parent', []);
I am able to select a folder and it is set as the rootnode. When I click on the folder it opens and all the files and subfolders appear, however I am unable to open the subfolders. Whenever I click on the + to the left of the subfolders the + just disappears. Is there a way to solve that?
Any help appreciated. Thank you.Fatima Mansourhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13764834-fatima-mansourtag:ww2.mathworks.cn,2005:Question/4358812018-12-15T11:54:14Z2018-12-15T12:07:33ZCalling multiple outputs from a function in a loopI am trying to call multiple outputs from a function in a for loop. The code I tried initially is below
for i =1:tsteps
[tnewfin1 (:,i+1),crfin1(1,i)] = newtstep (tnewfin1 (:,i));
end
However I constantly received the error "Invalid use of operator".
I changed it to the following,
for i =1:tsteps
[tnewfin,crfin] = newtstep (tnewfin1 (:,i));
tnewfin1 (:,i+1) = tnewfin
crfin1(1,i) = crfin
end
which worked, despite not really changing what is happening.
I thought the first one would work because initially, when I just wanted one output from the function, the following code ran succesfully
for i =1:tsteps
tnewfin1 (:,i+1) = newtstep (tnewfin1 (:,i));
end
Why would it work to call one output but not two, or why is the first scenario an "invalid use of operator"?Samuel Newallhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14033696-samuel-newalltag:ww2.mathworks.cn,2005:Question/4357852018-12-14T15:23:12Z2018-12-15T12:02:21ZHow to acieve a scatter plot like this.Hi I have to do a scatter plot where each point in e.g. the xy-plane consist of determined value. My question is how do i plot a discrete amout of values where each of the values is related to a x, y-coordinate. I have seen reports with plots similar to the one presenten in the picture:
Hope to hear your input.
Best regards.Andreas Christensen Sørensenhttps://ww2.mathworks.cn/matlabcentral/profile/authors/5642231-andreas-christensen-sorensentag:ww2.mathworks.cn,2005:Question/1024822009-06-27T01:11:00Z2018-12-15T11:43:21ZWhy does REGEXPREP return an answer different from what I expect when I use space in the replacing pattern?If I enter the following at MATLAB Command Prompt:
res=regexprep('ZZZABAB','^[^A]*A','Q')
the result is QBAB.
If I then enter
res=regexprep('ZZZABAB','^[^A]*A','')
the result is B. I expect the result to be BAB.MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ww2.mathworks.cn,2005:Question/4358772018-12-15T11:13:36Z2018-12-15T11:42:41ZArray is filled incorrectlyI have to calculate the approximate value of the integral using taylor expansion. It is also necessary to calculate the number of required terms and the elapsed time for different accurancy. But arrays are filled incorrectly. As for the number of terms, the first value is calculated correctly, but then the entire array is filled with this value. What's wrong?
syms x;
func = cos(x^2);
a = 0;
b = 0.5;
id = true;
k = 1;
acc_array = [10^(-10) 10^(-9) 10^(-8) 10^(-7) 10^(-6) 10^(-5) 10^(-4) 10^(-3)];
time = [0 0 0 0 0 0 0 0];
terms_number = [0 0 0 0 0 0 0 0];
start = cputime;
for i = 1:8
while (id)
taylor_series = taylor(func, x, 'Order', k);
terms = children(taylor_series);
if (terms~=0)
for j = 1:length(terms)
terms_int = int(terms(j), [a b]);
if (abs(terms_int)<=acc_array(i))
id = false;
end
k = k + 1;
end
end
end
terms_number(i) = length(terms);
if (i > 1)
time(i) = cputime - time(i-1);
else
time(i) = cputime - start;
end
end
time
terms_number Valentin Shchepetovhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14273224-valentin-shchepetovtag:ww2.mathworks.cn,2005:Question/4358752018-12-15T11:00:56Z2018-12-15T11:34:02ZHow can I convert an array of hex values to a num?
I have an array with '30' '2E' '30' '31' for example, it is a part of a xbee frame, so I would like to get the value (0.01) and I do not know how... Maybe hex2num? But i dont knoe how to insert the values on it.
I know how to do the oposite operation:
>>dec2hex('0.01')
4×2 char array
'30'
'2E'
'30'
'31'
Please help, I'm trying everything...Alejandro Jimenezhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9681067-alejandro-jimeneztag:ww2.mathworks.cn,2005:Question/4358662018-12-15T07:56:57Z2018-12-15T11:31:28ZHow can I store dates as arrays for further process when using Matlab GPU computing?In the following attached code, I would like to record the variable Z in the while loop as array for further process, for example, finding the max value of Z in the array. But the dynamic array is not supported in the arrayfun for GPU computing. How to solve this problem?
function test_GPU_computing
maxIterations=500;
gridSize=1500;
xlim=[-0.75, -0.73];
ylim=[ 0.12, 0.14];
t=tic();
x=gpuArray.linspace( xlim(1), xlim(2), gridSize );
y=gpuArray.linspace( ylim(1), ylim(2), gridSize );
[xGrid,yGrid] = meshgrid( x, y );
count=arrayfun( @tar_fun,xGrid, yGrid, maxIterations );
count=gather(count);
gpuArrayfunTime=toc(t)
figure(3)
imagesc(x,y,count)
reset(gpuDevice(1))
function count=tar_fun(x0,y0,maxIterations)
z0=complex(x0,y0);
z=z0;
count=1;
while (count <= maxIterations) && (abs(z) <= 2)
count=count+1;
z=z*z+z0;
end
count=log(count);Shan Yinhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14145224-shan-yintag:ww2.mathworks.cn,2005:Question/4358782018-12-15T11:16:43Z2018-12-15T11:16:43Zdetecting spikes am working on LIF (leaky integrated fire neuron) and i give periodic ramp signal as excitation current. now i want how to detect how many spikes occur inside each ramp windows. so if you have any idea about it someone give me hint...am working on LIF (leaky integrated fire neuron) and i give periodic ramp signal as excitation current. now i want how to detect how many spikes occur inside each ramp windows. ASHENAFI FEKEDE HAILEhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13312698-ashenafi-fekede-hailetag:ww2.mathworks.cn,2005:Question/4358762018-12-15T11:08:09Z2018-12-15T11:13:26ZI am writing an FEM code for a curved box girder bridge and getting an error..Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.359430e-32. > In Dec14 (line 579) X_matrix=inv(K_modi)*F_matrix;Virajan Vermahttps://ww2.mathworks.cn/matlabcentral/profile/authors/13253143-virajan-vermatag:ww2.mathworks.cn,2005:Question/3951442018-04-16T05:03:16Z2018-12-15T11:01:01Zi am trying to solve bouc-wen hysteresis model anybody help me to solve this problemi am trying to solve the bouc-wen hysteresis model using ordinary differential equations help me solve this problemSABARIANAND D Vhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8832171-sabarianand-d-vtag:ww2.mathworks.cn,2005:Question/4358742018-12-15T10:51:45Z2018-12-15T10:51:45ZGet position and dimensions of rectangular ROI as normalised [0,1] instead of pixelsI can use h = drawrectangle() and then get the position and dimensions using h.Position. This gives me an answer in pixels but I would like them as normalised to the image, between 0 and 1. Is there a way to do this in MATLAB without calculating it from the height and width of the image? It's fairly trivial to do this manually, I just wondered if there may be a function that would do it for me.KiFi85https://ww2.mathworks.cn/matlabcentral/profile/authors/13856860-kifi85tag:ww2.mathworks.cn,2005:Question/4358732018-12-15T10:46:42Z2018-12-15T10:46:42ZNumerically solve integration of random variable using symbolic valuesHello,
I am trying to solve an equation in matlab using symbolic values and a random variable with a lognormal distribution. This is the code I have so far:
FOCR=0.0036;
sigma=1;
syms eB
func= @(X) X.*pdf('Lognormal',X,0,sigma);
N=int(func,X,eB,inf);
D=exp(0.5*sigma^2)-N;
EB=solve(N/D==FOCR,eB);
When I execute this code step by step I notice that I get an error when I try to compute the integral, N of func on [eB,inf]. This is what the error says:
Error using symengine
Unable to prove 'X <= 0' literally. Use 'isAlways' to
test the statement mathematically.
Error in sym/subsindex (line 821)
X =
find(mupadmex('symobj::logical',A.s,9))
- 1;
Error in sym/privsubsasgn (line 1096)
L_tilde2 =
builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 933)
C = privsubsasgn(L,R,inds{:});
Error in lognpdf (line 36)
x(x <= 0) = Inf;
Error in pdf (line 107)
y = lognpdf(x,a,b);
Error in @(X)X.*pdf('Lognormal',X,0,sigma)
Error in sym>funchandle2ref (line 1302)
S = x(S{:});
Error in sym>tomupad (line 1215)
x = funchandle2ref(x);
Error in sym (line 214)
S.s = tomupad(x);
Error in sym/int (line 63)
f = sym(f);
Does anyone know how to solve this issue or what I am doing wrong here?
Thanks in advance,
RenéRené Wijnenhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14054194-rene-wijnentag:ww2.mathworks.cn,2005:Question/4358722018-12-15T10:32:40Z2018-12-15T10:32:40ZElectric Load Time-Series Forecasting using AR, KNN and SVMI want to forecast the next week (horizon = 7) electric load with lag=7 using AR, KNN and SVM, where should I start? Is there a code that could help me with that or even a tutorial ?Mohab Mostafahttps://ww2.mathworks.cn/matlabcentral/profile/authors/6462704-mohab-mostafatag:ww2.mathworks.cn,2005:Question/4334622018-12-03T07:17:22Z2018-12-15T10:18:42ZHow to find five unknown parameters of an equationHello all,
Greetings.
I am very new to matlab.
How to find five unknown parameters of an equation. Looking for help on this.
My Equation,
Y = [a * B^c * D^-0.33 * exp(-e / FG)] – [h * J]
Where, [ G = k * L + m * N ] ;
Here unknown parameters are [ a, c, e, k, h ]
Known parameters are [ B, D, F, J, L, N]
these parameters have constraints like, (0<k>1); (m = 1 - k); (a>0); (c<0); (e>0); (h>0) and (Y>0)
I have to draw X-Y plot graph and also Least square regression analysis.
I have X-axis values, Y-axis values will be calculated from equation Y.
X = [0.0000032; 0.0000201; 0.00000280; 0.0000114; 0.00000790; 0.00000560; 0.000004; 0.0000012]
B = [53855; 27506; 52678; 27002; 26654; 27013; 53949; 53091]
D = [8.39; 8.32; 8.52; 8.42; 8.50; 8.61; 8.50; 8.60]
F = [0.0083; 0.0083; 0.0083; 0.0083; 0.0083; 0.0083; 0.0083; 0.0083]
L = [687; 740; 670; 705; 674; 647; 677; 649]
N = [636; 644; 624; 633; 626; 617; 626; 618]
J = [12; 4; 12; 3; 4, 3; 12; 13]
I have to find the unknown parameters using “Y” equation and later plot X-Y parity plot it should have R^2 > 0.85
Appreciate your help.
Thanks in advance.HARISH GANAPATHIhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11803641-harish-ganapathitag:ww2.mathworks.cn,2005:Question/4358712018-12-15T10:12:03Z2018-12-15T10:12:03ZHow can i solve network verification error when installing support package for matlab2016a Saad Shahhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14340762-saad-shah