http://www.mathworks.nl/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-07-23T20:09:44Ztag:www.mathworks.nl,2005:Question/1429662014-07-22T20:27:46Z2014-07-23T20:09:44ZHow to solve simultaneous trigonometric equation with summation from n=1 to inf. ?<p>I am trying to solve the set of simultaneous equations (shown in file attached, see bottom). x and y are known. For a particular value of psi3, I have to obtain psi1 and psi2 from these simultaneous equations?
I wonder if a combination of 'symsum' and 'solve' command will give a solution as the series is not convergent. In that case, how many terms should I take in the series? Never encountered such a set of equations.
Any kind of help is appreciated.Thanks for kindness.</p>Dinesh Kumar/matlabcentral/answers/contributors/4352325-dinesh-kumartag:www.mathworks.nl,2005:Question/1430942014-07-23T20:09:43Z2014-07-23T20:09:43ZUsing PLOTYY with multiple arrays of different sizes.<p>(x1,y1), (x2,y2), and (x3,y3) are pairs of arrays which each have a different size.</p><p>i.e.</p><pre class="language-matlab">size(x1)==size(y2)
size(x1)~=size(x2)).
</pre><p>The elements of (x3,y3) are of a different scale than the rest of the data and thus why I will be using PLOTYY.</p><p>If</p><pre class="language-matlab">size(x)==size(y4)==size(y5)
</pre><p>you can do this:</p><pre class="language-matlab">plotyy(x,[y4,y5],x3,y3)
</pre><p>and the result is 2 plots on one y-axis and one on the other.</p><p>It would therefore seem that I could do this:</p><pre class="language-matlab">plotyy([x1,x2],[y1,y2],x3,y3)
</pre><p>but that is not the case. I hope I have made my objective clear, and that someone will have some advice.</p>Kevin/matlabcentral/answers/contributors/5443616-kevintag:www.mathworks.nl,2005:Question/1430832014-07-23T19:20:55Z2014-07-23T20:00:20Zfast and beautiful way to convert vector ranges to indexes<p>Hi there,</p><p>my question could easily be solved with a simple loop but I'm curious if there is a nice genuine matlab way of doing this:
I have a vector "v1" containing 10 entries. First 5 belong together, next 2 belong together and the last 3 again (somehow). So I got a vector "v2" with</p><pre> v2 = [5; 2; 3];</pre><p>I want now something like</p><pre> v3 = [1 1 1 1 1 2 2 3 3 3];</pre><p>So I could access my v1 vector with:</p><pre> v1(v3==1);</pre><p>(Background for the question are different colors for each group with the plot-command.)</p><p>Thanks already in advance - I'm sure Matlab holds a nice and short way of doing this :-)</p><p>Vincent</p>Vincent/matlabcentral/answers/contributors/2936441-vincenttag:www.mathworks.nl,2005:Question/1430872014-07-23T19:36:02Z2014-07-23T19:58:50ZHow to loop through files that I have added to path?<p>Hi,</p><p>I have a folder that I added to matlab path. the folder contains 2400 .tif files - I need to loop through each image, do calculations on the image and then go to the next image to do same calculation. i am new to the matlab so I need the help. I will greatly appreciate the help. Thank you in advanced. Please help me.</p><p>thank you.
cocopuffs</p>cocopuffs/matlabcentral/answers/contributors/5467782-cocopuffstag:www.mathworks.nl,2005:Question/1430902014-07-23T19:42:56Z2014-07-23T19:53:00Zcell array question finding minimums of intervals of time matrices<p>I have a cell array that is a 1:100 cell (cellarray1).
each one of the contents of that cell is ALSO a cell.
The contents of each of those cells is time data that is either a 1X20 double, 1:30 double, a 1X200 double or anywhere in between.</p><p>I want to loop through the whole cell array, take every matrix of time data in the cell array, then we will say that m= the length of any random array of time data in the cell array. For each of the arrays of time data, I want to take the (2:m)-(1:m-1).
Then I will have the deltas between the time points for every cell array in the intire cell array.</p><p>Then I want to take the minimum number of each cell array and store that in an array.</p><p>(I can then use datestr(timearray1),'HH:MM:SS.FFF') to get all the minimum time intervals for every array in cellarray1.</p>charles atlas/matlabcentral/answers/contributors/1924889-charles-atlastag:www.mathworks.nl,2005:Question/1430912014-07-23T19:43:47Z2014-07-23T19:46:22ZHow to create a long list using the same number?<p>Simple question but can't find it anywhere. I need to make a long list of the number say, 59, a thousand times.</p><p>59</p><p>59</p><p>59</p><p>59
etc</p><p>What is the syntax to do this? Thanks</p>Shane/matlabcentral/answers/contributors/5292458-shanetag:www.mathworks.nl,2005:Question/1430892014-07-23T19:42:47Z2014-07-23T19:42:47ZHow do I get the "To file" to work??<p>I am trying to take data from my arduino analog input and write it into a .mat file in a "timeseries" save format. The error I keep recieving is as follows:</p><p>model error</p><p>The code generated for 'EMG_viewer/To File' cannot support Timeseries logging format using current target 'realtime.tlc'. Consider switching the logging format to Array or selecting a target that supports Timeseries format.</p><p>What am I doing wrong? My model only consists of 3 blocks. 'Analog input' , 'gain' (5/1025) , 'To File'. Thank you!</p>Daniel Sluder/matlabcentral/answers/contributors/3858227-daniel-sludertag:www.mathworks.nl,2005:Question/1430882014-07-23T19:41:33Z2014-07-23T19:41:33ZReal time detect keypress<p>I'd like to create a simple program to emulate real time programming but without sensors (so any student with a computer and MATLAB can work with it anywhere). Wanting a simple problem (assignment) I'd like to avoid using a GUI. My thought was to detect a keypress and initiate action based on what key was pressed and whether or not a given different key had been pressed first. Real time programming does not use pauses or anything that waits without monitoring. If this is not possible, maybe I can do something with the mouse pointer location instead? I understand that this can be obtained from the root object.</p>Michael/matlabcentral/answers/contributors/1065471-michaeltag:www.mathworks.nl,2005:Question/1430662014-07-23T17:28:51Z2014-07-23T19:38:13ZDisable Command Line During Point Selection<p>I'm trying to use datacursormode to select a two points on a 3D plot. The point selection is working just fine. However, I'm using 'pause' to wait for the user to click a point. The problem is that 'pause' requires you to press a key to continue. This is activating my command window, switching me from my program GUI to view the code, and I have to switch back to my GUI before I can click the next point.</p><p>Is there either a way to disable the command window so that "pressing a key to continue" does not enter a command; or an alternative to 'pause' that continues upon the mouse being clicked?</p><p>I'm using R2014a on Windows 7.</p><p>Some relevant code:</p><pre class="language-matlab">dcm_obj = datacursormode(handles.mainfig);
set(dcm_obj, 'Enable', 'on', 'SnapToDataVertex', 'off');
pause
f = getCursorInfo(dcm_obj);
selpt1 = f.Position;
</pre><p>Thanks!</p>Jacob/matlabcentral/answers/contributors/5066505-jacobtag:www.mathworks.nl,2005:Question/357082012-04-17T07:49:02Z2014-07-23T19:37:52Zspiht algorithm<p>looking for spiht algorithm for image compression</p>Nag Arjun/matlabcentral/answers/contributors/3433268-nag-arjuntag:www.mathworks.nl,2005:Question/1430822014-07-23T19:13:15Z2014-07-23T19:37:39ZNeed help with writing the objective function for a genetic algorithm<p>I usually use AMPL to write mixed integer programs, but now I need to implement a Genetic Algorithm so I'm trying to write my objective function on Matlab. I cannot handle the summation over specific ranges like I used to do in AMPL. It'll be great if someone can help me figuring out how to write the attached objective function in Matlab. Thanks.</p>Ameera/matlabcentral/answers/contributors/5472365-ameeratag:www.mathworks.nl,2005:Question/1430852014-07-23T19:27:39Z2014-07-23T19:34:07Zsymbollic solving from character string<p>Hi everyone,
I have a string consisting of e.g. 'y = ca / dy' and wish to solve this symbolically for ca and then calculate ca if I have data for y and dy. I know to do this you would normally type</p><p>syms y ca dy</p><p>and then use solve. But how can I use syms where y, ca and dy come from a cell array e.g.</p><p>inputs = {'y','ca','dy'}</p><p>ie something like this i would have thought: syms inputs{1} inputs{2} inputs{3}</p><p>Thanks for any help you can provide in this</p>David/matlabcentral/answers/contributors/3109457-davidtag:www.mathworks.nl,2005:Question/803352013-06-26T16:04:54Z2014-07-23T19:31:49ZHow can I get Infrared image from kinect in matlab?<p>I wanna use Image acquisition toolbox to obtain an IR image from kinect. not depth image.</p>Laila Kazemi/matlabcentral/answers/contributors/2627338-laila-kazemitag:www.mathworks.nl,2005:Question/1430862014-07-23T19:29:25Z2014-07-23T19:29:25ZHow to use mexw64 files <p>i have a c file with s function and succesfully compiled it into .mexw64 extention.
how do i use this file for my simulink model.</p>Raghavender/matlabcentral/answers/contributors/5214907-raghavendertag:www.mathworks.nl,2005:Question/1428082014-07-21T18:58:03Z2014-07-23T19:29:24ZHeatmap and Contour figures in Matlab<p>Suppose that I have this information that first column is feature one of a motor, Second column is feature two and column three is response (in this case performance of motor).</p><pre class="language-matlab">[34 56 100
12 12 80
7 6 60
3 4 20
1 1 10.5
0 0 1]
</pre><p>I want have something like heatmap or contour that for example I have a warmer (for instance red color) for first row in matrix and more light color for row two and etc. What should I do?</p><p>Thanks.</p>Jack/matlabcentral/answers/contributors/5193869-jacktag:www.mathworks.nl,2005:Question/867512013-09-10T01:28:40Z2014-07-23T19:28:40ZMatlab R2013a Kinect toolbox infrared<p>Hi all,</p><p>I've been using the Kinect Toolbox and have been able to get both color and depth images (great work Mathworks!). According to this site:</p><p><a href = "http://www.codeproject.com/Articles/528305/GetplustheplusIRplusStreamplusandpluscontrolplusth">http://www.codeproject.com/Articles/528305/GetplustheplusIRplusStreamplusandpluscontrolplusth</a></p><p>"Capturing IR stream data is as simple as capturing a color image stream, as the SDK returns the infrared stream as a part of the color image stream data. The only changes are required on ColorImageFormat and PixelFormats."</p><p>So I tried to use this command to acquire the IR signal:</p><p>colorVid = videoinput('kinect',1,'InfraredResolution640x480Fps30');</p><p>but that failed. Also, I tried to use colorVid.ColorStream = 'Enabled', but that resulted in an invalid property. Does the kinect toolbox support acquiring the IR signal?</p><p>Cheers,
Greg</p>Greg/matlabcentral/answers/contributors/307090-gregtag:www.mathworks.nl,2005:Question/1430812014-07-23T19:01:21Z2014-07-23T19:25:50ZFinding the Confidence Interval of Slope<p>I currently have a set of data points. I am plotting a linear regression line through this data. Now I want to find the confidence interval of the slope for this data.</p><p>I am currently using the regress function which works great. My only concern is that I read somewhere that the regress function uses an f-test to obtain the confidence interval. Is this true?</p><p>I am looking for a function that will get my data points and give me a confidence interval of the slope, using a t-test.</p><p>Please let me know if the regress function is fine or if there is something better.</p><p>Thanks!</p>Daniel/matlabcentral/answers/contributors/5478959-danieltag:www.mathworks.nl,2005:Question/1379902014-06-27T19:08:41Z2014-07-23T19:25:47ZGlobalSearch and MultiStart Syntax<p>Hi There</p><p>I want to use GlobalSearch and MultiStart for a parameter estimation problem using fmincon and lsqnonlin. The question is regarding the syntax. Both GlobalSearch for fmincon and MultiStart for lsqnonlin give the "not enough input argument " error. The objective function "Objective" that returns a value to fmincon has another function nested in it that gives the results of a set of ODEs. How do we add that in the createproblem of globalsearch or multistart, because the error point to that ode output function? Part of the code is written below.</p><p>Thanx</p><pre> options=optimset('Algorithm','sqp','DiffMinChange',5,'MaxIter',7000,'MaxFunEvals',7000,'TolX',1e-10,'TolFun',1e-10,'ObjectiveLimit',1e-12);</pre><pre> lb=[0 0 0 0 0 0 0 0 0 0 0 0 0 0];
ub=[inf inf inf inf inf inf inf inf inf inf inf inf inf inf];
A=[];
b=[];
Aeq=[];
beq=[];</pre><pre> problem=createOptimProblem('fmincon','objective',Objective,'A',A0,'lb',lb,'ub',ub,'Aineq',A,'bineq',b,'Aeq',Aeq,'beq',beq,'options',options);</pre><pre> gs = GlobalSearch; </pre><p>[xmin,Fmin] = run(gs,problem)</p><p>[Parameters,fval,exitflag,output]=fmincon(@(A) Objective (wd,fd,A),A0,A,b,Aeq,beq,lb,ub,nonlcon,options);</p>Nath/matlabcentral/answers/contributors/1974315-nathtag:www.mathworks.nl,2005:Question/1430842014-07-23T19:21:52Z2014-07-23T19:21:52ZHow to use histcn (histogram) in my matlab scipt. <p>Hi I am wondering how do i use the "histcn" (a histogram function) into my script.</p><p>This is my scipt:</p><p>clear all;</p><p>clc;</p><p>k1= 5;</p><p>k2= 1;</p><p>k3= 1;</p><p>k4= 1;</p><p>k5= 0.5;</p><p>Kb= 5;</p><p>o= 10;</p><p>oa= 0;</p><p>ob= 0;</p><p>Ot= o + oa + ob;</p><p>h = 1;</p><p>t = 0: h: 8000000;</p><p>a = zeros(1,length(t)); % Calculates upto certain time</p><p>b = zeros(1,length(t))'</p><p>a(1) = 20; % initial condition</p><p>b(1) = 0;</p><p>t(1)= 0;</p><p>m = 0;</p><pre> % mean & standard devation
std = .0925; </pre><pre> for i = 1: length (t);
randoma = m + std.*randn(1,1);
randomb = m + std.*randn(1,1);
a(i+1)= a(i) +h*((k3 + k4.*Kb.*a(i)).*(Ot./(1 + Kb.*(a(i) + b(i)))) - k5.*a(i))+randoma;
b(i+1)= b(i) + h*((k3 + k4.*Kb.*b(i)).*(Ot./(1 + Kb.*(a(i) + b(i)))) - k5.*b(i))+randomb;
function [count edges mid loc] = histcn(X, varargin)</pre><pre> end;</pre><p>t(end+1) = t(end)+h;</p><pre> title ('Foward Euler Method 2D') </pre><pre> xlabel('time'); </pre><pre> ylabel('A,B'); </pre><p>% ploting a trajectory 'a' vs. b'</p><p>figure (3)</p><p>plot(a,b);</p><p>xlim ([0 20])</p><p>ylim([0 14])</p><p>grid on</p><p>xlabel('A');</p><p>ylabel('B');</p><p>title ('FEM 2D graphing A vs. B')</p>bnlim bnlim/matlabcentral/answers/contributors/5456175-bnlim-bnlimtag:www.mathworks.nl,2005:Question/1397442014-07-01T15:34:49Z2014-07-23T19:20:53ZIntersection of 3 circles with chords present, and arcs removed<img src = "/matlabcentral/answers/uploaded_files/14897/3%20intersecting%20circles%20with%20arcs.gif"><img src = "/matlabcentral/answers/uploaded_files/14898/bubbles3.jpg"><p>Something like this, but with the arcs within another circle removed, as well as the remaining chord length after the chords intersect (similarly to the second image).</p><pre class="language-matlab">clear all
clc
m = 1000; % Number of points on circle
x_max = 50; % Uppermost x location of circle center
y_max = 50; % Uppermost y location of circle center
theta = 0:2*pi/m:2*pi; % Evaluated angles for circle
k=3
%generate circles and store their points.
for i =1:k
rad(i) = 15*rand; % Save circle radii to array
x_pos(i) = x_max*rand; % Save circle xi-positions to array
y_pos(i) = y_max*rand; % Save circle yi-positions to array
X{i}=x_pos(i)+rad(i)*cos(theta);
Y{i}=y_pos(i)+rad(i)*sin(theta);
end
figure,
hold on
for j=1:3
plot(X{j},Y{j})
end
%perform loops for comparison.
for i=1:k-1
for j=i+1:k
dC1 = sqrt((X{i}-x_pos(j)).^2+(Y{i}-y_pos(j)).^2)>=rad(j);
X{i}(~dC1)=NaN;
Y{i}(~dC1)=NaN;
dC2 = sqrt((X{j}-x_pos(i)).^2+(Y{j}-y_pos(i)).^2)>=rad(i);
X{j}(~dC2)=NaN;
Y{j}(~dC2)=NaN;
end
end
figure,
hold on
for j=1:3
X{j}(isnan(X{j})) = [];
Y{j}(isnan(Y{j})) = [];
plot(X{j},Y{j})
end
</pre><p>This code (posted by Joseph Cheng) does well for circle interactions until 3 overlap. Is there a way to allow this?</p>Sean/matlabcentral/answers/contributors/5385407-seantag:www.mathworks.nl,2005:Question/1425412014-07-19T14:06:33Z2014-07-23T19:20:51ZHow to fit the grid to a mesh with voids?<p>Hello everybody,</p><p>I have a mesh that includes some voids in. I would like to create a grid to represent that mesh but when I use mesh grid with X and Y coordinates given; the grid created goes through the voids as well :( Any ideas how to create a grid that fits to my mesh and leave blank the voids I have in the original mesh??</p>Ceren GURKAN/matlabcentral/answers/contributors/3671277-ceren-gurkantag:www.mathworks.nl,2005:Question/1414912014-07-11T19:28:02Z2014-07-23T19:17:39ZCustomize display of an enumeration class<p>I'd like to customize the display of an enumeration class using <tt>matlab.mixin.CustomDisplay</tt> .</p><p>If I have a regular (non-enumeration) class such as the following:</p><pre class="language-matlab">classdef test < handle & matlab.mixin.CustomDisplay
properties
value
end
methods
function obj = test(value)
obj.value = value;
end
end
methods (Access = protected)
function displayScalarObject(obj)
disp(['hello ', num2str(obj.value)])
end
end
end
</pre><p>then everything works fine - for example,</p><pre class="language-matlab">>> a = test(1)
a =
hello 1
</pre><p>But if I have an enumeration class such as the following (note the addition of the <tt>enumeration</tt> block):</p><pre class="language-matlab">classdef test < handle & matlab.mixin.CustomDisplay
properties
value
end
methods
function obj = test(value)
obj.value = value;
end
end
methods (Access = protected)
function displayScalarObject(obj)
disp(['hello ', num2str(obj.value)])
end
end
enumeration
enum1(1)
end
end
</pre><p>then the display is not customized - for example,</p><pre class="language-matlab">>> a = test.enum1
a =
enum1
</pre><p>Using the debugger, I can see that my <tt>displayScalarObject</tt> method is never called. Implementing other methods of <tt>matlab.mixin.CustomDisplay</tt> such as <tt>displayNonScalarObject</tt> and so on doesn't seem to help - these never get called either.</p><p>What's going on? Do <tt>disp</tt> and <tt>display</tt> work differently for enumeration classes, in such a way that anything that's overridden by <tt>matlab.mixin.CustomDisplay</tt> just gets ignored?</p><p>Is there a way to get a customized display with <tt>matlab.mixin.CustomDisplay</tt> , but using an enumeration class?</p><p>PS I am able to directly overload <tt>disp</tt> and/or <tt>display</tt> on an enumeration class that does not inherit from <tt>matlab.mixin.CustomDisplay</tt> , and this works fine. But I'm looking to use <tt>matlab.mixin.CustomDisplay</tt> if possible.</p>Sam Roberts/matlabcentral/answers/contributors/3674049-sam-robertstag:www.mathworks.nl,2005:Question/1304822014-05-21T10:55:59Z2014-07-23T19:17:28ZCan Matlab (Windows) display 10 bit images on a 10 bit monitor using a suitable graphics card?<p>Hello,</p><p>I am interesting in displaying images for bio-medical applications. Can matlab support 10 bit monitors (NEC SpectraView Reference 272) with 10 bits per channel graphics cards (Nvidia Quadro k5000 cards? I have looked through the forums but no definitive answer has been given. How would you display 10 bit images within MATLAB as most of the image formats only require 8 bits per channel?</p>Alec/matlabcentral/answers/contributors/4349511-alectag:www.mathworks.nl,2005:Question/1399142014-07-02T14:49:48Z2014-07-23T19:16:12ZExtract identical values from a data set<p>Hi everyone,</p><p>I have a data set for polar coordinates from this command:</p><pre class="language-matlab">[TH,R,Z] = cart2pol(xdata,ydata,zdata);
</pre><p>I then want to find same values of R and corresponding to them values of Z. I have tried these commands:</p><pre class="language-matlab">u=unique(R);
n=histc(R,u);
u(n>1);
find(R==u(n>1))
</pre><p>which gives me an error: Error using ==
Matrix dimensions must agree.</p><p>Error in NSMatlabNPC (line 108)
find(R==u(n>1))</p><p>And tried to use</p><pre class="language-matlab">find(diff(R)==0)
</pre><p>which returned me an empty matrix 1 by 0.</p><p>The problem is probably that I have several identical R of different values and these functions might not be suitable to identify them separately. Are there any other ways I could use to access the same R values?</p>Sofya/matlabcentral/answers/contributors/5380942-sofyatag:www.mathworks.nl,2005:Question/1424412014-07-18T19:17:22Z2014-07-23T19:11:42ZHow can I get a point cloud from a patch object?<p>I've downloaded the IGESToolBox from here and brought in a flowpath from CAD. The IGESToolbox plots the supplied file as a patch;</p><pre class="language-matlab">patch('faces',TRI,'vertices',P','FaceColor',clr,'EdgeColor','none');
</pre><p>I would like to extract the point cloud from the patch so I can make a ndgrid or trimesh. However, I can't figure out how to get the data out of TRI and P. I've tried 3 different ways and I just end up with a funky wedge shape instead of the flowpath.</p><p>Thanks for looking</p>Chris Virgin/matlabcentral/answers/contributors/2176679-chris-virgintag:www.mathworks.nl,2005:Question/1427092014-07-21T03:23:13Z2014-07-23T19:07:08ZGenerating Hessian of the Lagrangian with dynamic number of nonlinear constraints in Fmincon<p>Hi,</p><p>(I posted this in stack exchange 2 days back but didn't get a response. Hope it works here).</p><p>I'm using interior point algorithm for solving a nonlinear optimization problem and want to provide Hessian of the Lagrangian as part of fmincon to speed up the process (running couple of thousand variations for different sets of parameters)</p><p>The workflow that I'm designing has the (nonlinear) objective function, form of linear and nonlinear constraints each in separate function files. I use a master script which has the fmincon. Since i'm running different variations of the problems, sometimes there may be zero nonlinear equality & zero nonlinear inequality constraints and in other scenarios, nonzero number of nonlinear equality/inequality constraints. In short the number of nonlinear constraints are dynamic and stored in the 2 variables "NumOfNonLinEqConstr" and "NumOfNonLinInEqConstr"</p><p>I have taken a look at <a href = "http://www.mathworks.com/help/optim/ug/symbolic-math-toolbox-calculates-gradients-and-hessians.html">Generating Hessian using Symbolic toolbox</a> and few other web-pages but cannot see an example where the Hessian of the Lagrangian is constructed for dynamic number of constraints. In the referred matlab webpage example, like in one variation I tried replacing 10 with NumOfNonLinInEqConstr bu it doesn't work as matlabFunction does not work on cell data type. Can anybody provide a working example for constructing hessian of the lagrangian with dynamic number of nonlinear constraints</p><p>Relevant code lines from the matlab link provided below: My question is how could I avoid hard-coding 10 in the below code (and also avoid manual addition of the product of hessian of the constraint and lambda.ineqnonlin 10 times)?</p><pre> hessc = cell(1, 10);
for i = 1:10
hessc{i} = jacobian(gradc(:,i),x);
end</pre><pre> for i = 1:10
ii = num2str(i);
thename = ['hessc',ii];
filename = [currdir,thename,'.m'];
matlabFunction(hessc{i},'file',filename,'vars',{x});
end</pre><pre> function H = hessfinal(X,lambda)
%
% Call the function hessenergy to start
H = hessenergy(X);</pre><pre> % Add the Lagrange multipliers * the constraint Hessians
H = H + hessc1(X) * lambda.ineqnonlin(1);
H = H + hessc2(X) * lambda.ineqnonlin(2);
H = H + hessc3(X) * lambda.ineqnonlin(3);
H = H + hessc4(X) * lambda.ineqnonlin(4);
H = H + hessc5(X) * lambda.ineqnonlin(5);
H = H + hessc6(X) * lambda.ineqnonlin(6);
H = H + hessc7(X) * lambda.ineqnonlin(7);
H = H + hessc8(X) * lambda.ineqnonlin(8);
H = H + hessc9(X) * lambda.ineqnonlin(9);
H = H + hessc10(X) * lambda.ineqnonlin(10);</pre><pre> end</pre>Hari/matlabcentral/answers/contributors/4996260-haritag:www.mathworks.nl,2005:Question/1430772014-07-23T18:19:15Z2014-07-23T18:59:40ZMatlab and Computational Geometry<p>I am considering purchasing MATLAB for Student Use. Before actually purchasing MATLAB for Student Use, however, I would have to know and decide which of the following couple of products is better to purchase (from a cost-effective standpoint):</p><p>(1.) The MATLAB and Simulink Student Suite.
(2.) The MATLAB Student (unbundled).</p><p>I would like to know whether or not I need to purchase a MATLAB add-on in order to use the Computational Geometry functionality of the software.</p><p>Thank you.</p><p>Nyeng Gyang.</p>Nyeng Gyang/matlabcentral/answers/contributors/5478847-nyeng-gyangtag:www.mathworks.nl,2005:Question/1430652014-07-23T17:25:23Z2014-07-23T18:57:55ZSimulink Real-time Target screen stops responding but model is running<p>What would cause the Simulink RT Target screen to freeze up but the underlying model continues to run? There is no error on the screen.</p>Thomas Marullo/matlabcentral/answers/contributors/1142235-thomas-marullotag:www.mathworks.nl,2005:Question/1430782014-07-23T18:23:11Z2014-07-23T18:52:19ZDo you know sample code for neural network<p>Dear all
I am not perfect in matlab but not totally imperfect too. Moreover, I do not have sufficient license for several packages in matlab. Do you guys know sample code for neural network so that I can recode it to train may data for prediction. In fact, I prefer to write code instead using some license stuff. If some one is interested in teaching me some neural work and other optimization stuff, it will be great to have.</p><p>Thanks</p>Mahesh/matlabcentral/answers/contributors/3834561-maheshtag:www.mathworks.nl,2005:Question/1419182014-07-15T13:26:42Z2014-07-23T18:51:53ZWhat does the command 'SimulinkRealTime' mean when logging data with a file scope?<pre> When logging data with a file scope in simulink, I faced a command named 'SimulinkRealTime', but I did't understand how this command produced. For example, there is a statement'tg = SimulinkRealTime.target;' in http://www.mathworks.cn/cn/help/xpc/examples/data-logging-with-a-file-scope.html, but this statement does not work when I tried to use it. I cannot find a command in MATALB HELP named 'SimulinkRealTime'. My question is what does the command 'SimulinkRealTime' mean and how this command produced?
Thanks in advance.</pre>Xu/matlabcentral/answers/contributors/5319041-xutag:www.mathworks.nl,2005:Question/1430792014-07-23T18:36:41Z2014-07-23T18:48:55ZRead and write multiple excel files.one after the other<p>I have 2 folders each containing 4 excel files. Then I need to do arithmetic calculation between 1st excel file of folder 1 with 1st excel file stored in folder 2 and write result in 1st blank excel file that is stored in folder 3(Arithmetic operation I am able to do).
This process I want to do for all the files in the two folders. Is it possible?
If so what code do I need to add to my existing code. Should I use 'For' loop?</p>KRUNAL/matlabcentral/answers/contributors/5309685-krunaltag:www.mathworks.nl,2005:Question/1430802014-07-23T18:39:11Z2014-07-23T18:43:43ZHow to create a sequence.<p>I need to create a vector that holds a sequence. In the sequence the previous number is multiplied by 2. The sequence could stop at a desired number lets say 256 (but it could be a bigger number). How would one go about this?</p><p>Example
sequnce = 2,4,8,16,32,...,256.
vector = [2;4;8;16;32;64;128;256]</p><p>vector =</p><pre> 2
4
8
16
32
64
128
256</pre>Lord Chinex/matlabcentral/answers/contributors/5462497-lord-chinextag:www.mathworks.nl,2005:Question/1430382014-07-23T14:27:40Z2014-07-23T18:39:00ZCan not use Excel file when actxserver is used in standalone application <p>I have developed with MATLAB a standalone application which imports data, processes data and exports results. The importing and exporting are from and to .csv files handled by actxserver in the back. When the standalone application is running, if users try to open new file with MS Excel, the application might crash, no matter the newly openned file is the same as the files handled by MATLAB application or not. It doesn't happen all the time, but very frenquently. Any hint is appreciated.</p>Heng/matlabcentral/answers/contributors/3111364-hengtag:www.mathworks.nl,2005:Question/1424702014-07-18T22:20:45Z2014-07-23T18:36:28Zfmincon Gradients not Matching with Mine<p>Having an issue with fmincon... The nonlinear constraint gradients that I compute do not match with those created by fmincon according to the dialog that appears when DerivativeCheck is 'on'. The issue is that fmincon is claiming that my derivative and its derivative are not the same within a tolerance of 1e-6. The difference it claims is usually 3e-3 to 1e-5. And the strange part is that sometimes the derivative that fmincon computes varies from run to run. Sometimes the derivatives match within the tolerance, most of the time they don't. Here is the equality constraint I am using:</p><pre class="language-matlab">ceq(1) = x(1) * e(x(2)) - x(2)
</pre><p>where e is a griddedInterpolant that is a function of x(2). For example, the data that generates the griddedInterpolant could be as follows:</p><pre class="language-matlab">E = [0 2.0 1.0]
</pre><pre class="language-matlab">P = [0 0.5 1.0]
</pre><pre class="language-matlab">e = griddedInterpolant(P, E, 'linear', 'linear')
</pre><p>So, I estimate the gradient of the equality constraint using a simple "forward" method as follows:</p><pre class="language-matlab">deltaX = 1e-6; %Small step
</pre><pre class="language-matlab">eForward = e(x(2) + deltaX); %Value of e at x(2) plus the small step
</pre><pre class="language-matlab">gradceq(1,1) = e(x(2)) %Gradient of ceq with respect to x(1)
</pre><pre class="language-matlab">gradceq(1,2) = x(1)*(eForward-e)/deltaX - 1 %Gradient of ceq with respect to x(2)
</pre><p>I have tried adjusting the step that fmincon uses to compute the gradient with 'TypicalX' to match mine, and no dice. I have tried central differences as well. Here is the dialog that it shows me:</p><pre class="language-matlab">Nonlinear equality constraint derivatives:
Maximum relative difference between user-supplied
and finite-difference derivatives = 0.00354916.
User-supplied constraint derivative element (4,1): -0.996447
Finite-difference constraint derivative element (4,1): -0.999996
</pre>John/matlabcentral/answers/contributors/4956213-johntag:www.mathworks.nl,2005:Question/1430712014-07-23T17:57:08Z2014-07-23T18:34:49ZDimension error using VERTCAT, but pretty sure dimensions are consistent<p>rawdata is a numeric matrix (size 2500x136 double)</p><p>text is a string matrix (size 2x136)</p><p>Text matrix contains the labels I want to add to the rawdata matrix. I double-checked the variable dimensions by using the size( ) function. Help?!?</p><p><b>error message:</b></p><pre> Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in openfile (line 25)
labeled_data=[text; rawdata];</pre><p><b>code:</b></p><pre> %read the text file
fileID=fopen('Master_inventory.txt');
inventory=textread('Master_inventory.txt', '%s' ...
, 'delimiter', '\n', 'whitespace', '');
% search for directory
c = cellstr(inventory);
filedesired = 'M29AA216afc01c1asfh_0000.3LA';
indx = regexpcell(c,filedesired);
%retrieve directory
pat = inventory(indx);
path = cellstr(pat);
%open file
raw=path{1};
rawdata=load(raw);
%add column labels
filename = 'DC_labels.xls';
[data, text] = xlsread(filename,'A1:EF2');
text = cellstr(text);
labeled_data=[text; rawdata];</pre>Zeke Merchant/matlabcentral/answers/contributors/3264436-zeke-merchanttag:www.mathworks.nl,2005:Question/1430742014-07-23T18:05:54Z2014-07-23T18:34:32ZMy graph in matlab has a blank strip in the middle<p>i graphed the following</p><pre class="language-matlab">if true
% code
end[x,y]=meshgrid(-1:.01:1, -1:.01:1);
a = .619211.*x.^2;
b = (53913.*x.^8.*y.^2 + 2560.*x.^6);
c = 232.192.*(b).^1/2;
d = (c - 53913.*x.^4.*y).^1/3;
e = a./d;
f = (53913.*x.^8.*y.^2 + 2560.*x.^6).^1/2;
g = 232.192.*f;
h = (g - (53913.*x.^4.*y));
i = .0011982.*[(h).^1/3];
z = e - i;
surf(x,y,z);shading interp
</pre><p>and now my graph has a strip running through the middle that is blank. how do i get rid of it/fix it</p>Nismeta/matlabcentral/answers/contributors/5432022-nismetatag:www.mathworks.nl,2005:Question/1428772014-07-22T10:00:01Z2014-07-23T18:28:58Z Image acquisition toolbox app <p>How to capture video frames or images with uncompressed format in Image acquisition toolbox app,I'm using matlab-2013a and I have connected my logitech webcam c525 to the system</p>Sagar/matlabcentral/answers/contributors/5416206-sagartag:www.mathworks.nl,2005:Question/1418862014-07-15T10:01:22Z2014-07-23T18:28:36ZHow can I convert a negative definite matrix into positive definite matrix?<p>I want to convert matrix a=[-5 2; 6 1] into positive definite matrix.</p>kartik pandya/matlabcentral/answers/contributors/2405867-kartik-pandyatag:www.mathworks.nl,2005:Question/1402872014-07-04T10:35:11Z2014-07-23T18:28:07Zwhy I can't find some ActiveX controls, such as LED, Linear Gauge ActiveX Control, and Percent ActiveX Control?<p>I can't find some ActiveX controls, such as LED, Linear Gauge ActiveX Control,Percent ActiveX Control and so on in my Matlab2012b GUI, why?
I just can see some ActiveX controls as below picture:</p><img src = "/matlabcentral/answers/uploaded_files/15025/2014-07-04_18-29-06.jpg"><p>and my computer's Matlab information is as below, any something wrong?</p><img src = "/matlabcentral/answers/uploaded_files/15026/2014-07-04_18-21-44.jpg"><p>thank you</p>0532/matlabcentral/answers/contributors/4152284-0532tag:www.mathworks.nl,2005:Question/1430392014-07-23T14:30:42Z2014-07-23T18:25:58ZSubtract data from two columns and show result in 3rd column<pre> I have the following data in an excel sheet</pre><pre> A B C
736 373
734 371
725 364
719 361
711 353
706 347
699 342
689 337
680 327
676 318 </pre><p>So basically I want to run this as A(1) - B(1),A(2) - B(2)..A(n) -B(n) and it should create the outputs at C1, C2...Cn respectively.
Can anyone help me on this?</p>KRUNAL/matlabcentral/answers/contributors/5309685-krunaltag:www.mathworks.nl,2005:Question/1430412014-07-23T14:41:43Z2014-07-23T18:24:54Zhow to make these changes about exe file which is complied from matlab gui?<p>I have made a GUI procedure---a.m/a.fig by matlab and then compile it into exe file by 'mcc -m a'.</p><p>1.the logo of a.exe file is the picture as below:</p><img src = "/matlabcentral/answers/uploaded_files/15758/2.gif"><p>my question is that: shall I change it as anther picture as I want?</p><p>2.when I run a.exe, a black window will come out as below picture:</p><img src = "/matlabcentral/answers/uploaded_files/15757/1.gif"><p>my question is that: how shall I avoid this window when I run the a.exe file?</p><p>3.because a.m insert a picture(exist on F:\) into the procedure when I move the a.exe file to another computer, I should copy this picture to that computer 's F:\. my question is that: how can avoid this (copy this picture to that computer)?</p><p>thank you !</p>0532/matlabcentral/answers/contributors/4152284-0532tag:www.mathworks.nl,2005:Question/1430372014-07-23T14:25:39Z2014-07-23T18:20:19Zhow to fix the strong reflections<p>hi i make classification of digits so the reflection damage the digits anyone has idea how to fix
i try color>250 , but this is not enough, also may i use some how that reflection is in the same line!!</p><img src = "/matlabcentral/answers/uploaded_files/15755/Capture1.PNG">michael scheinfeild/matlabcentral/answers/contributors/1907797-michael-scheinfeildtag:www.mathworks.nl,2005:Question/1430602014-07-23T16:24:33Z2014-07-23T18:17:47ZLooking for an iterative Solver to use in a loop with changing constants?<p>I have not used any kind of iterative solver but I am facing a challenge when trying to resolve the following equation:</p><pre class="language-matlab">sigma = theta+acos((A+B+(2*A*B/(2*A*B/(A+B-(B-A)*cos(2*theta))-(A+B))))/(B-A))/2;
</pre><img src = "/matlabcentral/answers/uploaded_files/15759/ThetaSigmaEquation.gif"><p>A & B are variables input by the user but do not vary during the loop. Sigma is changing during the loop though and I need to determine theta at each loop. Can anyone advise an iterative solver to resolve this and demonstrate briefly how it would be used in this application since I have not used it before.</p><p>Thanks,
Adam</p>Adam/matlabcentral/answers/contributors/4996050-adamtag:www.mathworks.nl,2005:Question/1430762014-07-23T18:16:26Z2014-07-23T18:17:47ZHow can I implement a BJT in SimPowerSystems?<p>I am trying to implement a circuit in SimPowerSystems, where I'm using a PNP transistor as a comparator (comparing voltages at its base and emitter). When it turns on, it turns on an NPN transistor which is used as a switch. I understand the switch can be implemented with an IGBT (where I feed the signal to turn on the switch, to the gate of the IGBT). But is there some way I can implement the PNP BJT used as a comparator? Are there any other ways to implement a comparator in SimPowerSystems?</p><p>Thanks.
Kanishka</p>Kanishka Singh/matlabcentral/answers/contributors/3537718-kanishka-singhtag:www.mathworks.nl,2005:Question/1428962014-07-22T12:21:52Z2014-07-23T18:13:50ZBug in matlab R2012b version <p>Hello,</p><p>I use the MATLAB R2012b version and when I try this:</p><p>0.5:0.1:0.8 the answer is:</p><p>ans =</p><pre class="language-matlab">Columns 1 through 3
</pre><pre> 5.000000000000000e-01 6.000000000000000e-01 7.000000000000001e-01</pre><pre class="language-matlab">Column 4
</pre><pre> 8.000000000000000e-01</pre><p>Why the third term is not strictly equal to 0.7?
Furthermore when I try 0.5:0.1:0.9 the bug disappears!</p><p>Do you have an answer?
Note: (as a reminder go to "HOME", "Preferences" and select "long e")</p><p>Thanks in advance
Fabrice</p>scarzo/matlabcentral/answers/contributors/5108130-scarzotag:www.mathworks.nl,2005:Question/1430752014-07-23T18:12:55Z2014-07-23T18:12:55ZKalman filter's fusion technique<p>Hello,</p><p>Regarding fusion of separate measurements of the same state-type\entry (e.g. position acquired from several different sensors): Is it allowed to be implemented by simply using several '1's at the same column of the H matrix? It worked for me but are there theoretical restrictions for that? (this question is simplified here for the linear case (KF), but an equivalent question can be formulated for the nonlinear case (EKF)).</p><p>Thank you!</p>Sigalit/matlabcentral/answers/contributors/4402925-sigalittag:www.mathworks.nl,2005:Question/1430722014-07-23T18:03:30Z2014-07-23T18:11:41ZFor-loop: create new name and extract data<p>So I have the following code below and am trying to use a 'for loop' to simplify. I am guessing have to use two sets of for loop but I am lost at the moment.</p><p>I have a dNPP which is matrix with 20 values.</p><pre class="language-matlab">NPP_2001 = [dNPP(1:1)];
NPP_2002 = [dNPP(2:2)];
NPP_2003 = [dNPP(3:3)];
NPP_2004 = [dNPP(4:4)];
NPP_2005 = [dNPP(5:5)];
NPP_2006 = [dNPP(6:6)];
NPP_2007 = [dNPP(7:7)];
NPP_2008 = [dNPP(8:8)];
NPP_2009 = [dNPP(9:9)];
NPP_2010 = [dNPP(10:10)];
</pre><p>I am thinking something along the line like this;</p><pre class="language-matlab">for k=2001:2010
for j=1:10
</pre><pre class="language-matlab">end
end
</pre><p>Any help would be appreciated</p>Jung/matlabcentral/answers/contributors/4095279-jungtag:www.mathworks.nl,2005:Question/1430732014-07-23T18:05:12Z2014-07-23T18:05:12ZHow to receive UDP packets in matlab?<p>I'm trying to get IMU sensor data from my android phone (from this app) <a href = "https://play.google.com/store/apps/details?id=org.zwiener.wimu&hl=en.">The app</a> Can anyone tell me the best way I can accomplish this?</p><p>Thank you.</p>HJ Jay/matlabcentral/answers/contributors/4826083-hj-jaytag:www.mathworks.nl,2005:Question/1430242014-07-23T13:04:08Z2014-07-23T18:02:55ZCopy Figure not working after upgrade to OSX 10.9.4<p>Copy figure had been working under 10.8 and 2014a. I recently upgraded to 10.9.4 and reinstalled 2014a on my machine. Now when I copy figures it seems to want to cram the figure into 579x435 box. This of course screws up the title and other figure properties. I've tried playing around with the Copy Figure preference to no avail. How do I tell Matlab that the window size is the size I'd like the figure copied at?</p>Samuel Lazerson/matlabcentral/answers/contributors/2374778-samuel-lazersontag:www.mathworks.nl,2005:Question/1429542014-07-22T19:07:25Z2014-07-23T18:02:54Zhow to number selections in listbox?<p>hi, I have a listbox and its selections, when i click on the Add layer, a selection will be added in the listbox, now what i want is how to get that selection numbered so when I enter a name of a layer, it will automatically show 1.name of layer etc......
hope you can hekp me guuys and below there's an image so that you can understand well what i want
thanks</p>Jihad Chamseddine/matlabcentral/answers/contributors/5435815-jihad-chamseddine