http://mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-07-25T00:37:06Ztag:mathworks.com,2005:Question/1428962014-07-22T12:21:52Z2014-07-25T00:37:06ZBug 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</p>scarzo/matlabcentral/answers/contributors/5108130-scarzotag:mathworks.com,2005:Question/1432662014-07-24T23:55:44Z2014-07-25T00:32:12ZHow to remove the smudges and noise in this image?<img src = "/matlabcentral/answers/uploaded_files/15801/crack3.jpg"><p>I have the attached image of a crack. I have used the following code to remove most of the noise and blobs to leave only the crack pattern:</p><pre> %binarize an image and display it
I = imread('crack3.JPG');
level = graythresh(I);
BW = im2bw(I, level);
BW1 = imcomplement(BW); %colour inversion
G = fspecial('gaussian', [5 5], 0.5); %Create the gaussian filter with hsize = [5 5] and sigma = 0.5
BW2 = imfilter(BW1,G,'same');</pre><pre class="language-matlab">BW3 = bwareaopen(BW2,50); %removes objects with < 50 connected pixels
BW4 = bwmorph(BW3, 'bridge', 1);
BW5 = bwmorph(BW4, 'diag', 1);
BW6 = bwmorph(BW5, 'majority', 1);
figure, imshow(BW6)
</pre><p>but I am still having trouble removing some of the smudges occurring on the top left-hand corner and at various positions.</p><p>Any help would be appreciated. Thanks</p><p>Duncan</p>Duncan/matlabcentral/answers/contributors/5351214-duncantag:mathworks.com,2005:Question/1432602014-07-24T22:53:28Z2014-07-25T00:18:08Zwait for process in matlab2014a<p>Hello
How can I force matlab2014a to wait for a EXE process to complete? It used to be possible with "isprocess" in previous versions but it seems like this function does no longer exist in 2014a.
Thanks
Raphael</p>Raphael/matlabcentral/answers/contributors/171488-raphaeltag:mathworks.com,2005:Question/1432342014-07-24T18:29:33Z2014-07-25T00:16:38Zincomplete minor gridlines in semilogx plot<p>I would like to plot a semi-log plot with gridlines. The problem is that the plot needs to have a slightly elongated aspect ratio, and when I switch the aspect ratio the gridlines disappear. For example:</p><pre class="language-matlab">x = 10.^(-9).*[2,3,4];
y = [3,4,5];
</pre><pre class="language-matlab">figure(1); close(gcf); figure(1);
</pre><pre class="language-matlab">pos = get(gcf,'Position'); set(gcf,'Position',[pos(1),pos(2),0.5.*pos(3),pos(4)]);
</pre><pre class="language-matlab">semilogx(x,y,'-ok'); grid on; xlim([3*10^(-11),4*10^(-8)]);
</pre><p>no longer has minor xaxis gridlines even though XMinorGrid = on and XMinorTick = on. I can add most of the gridlines by altering the code to be:</p><pre class="language-matlab">x = 10.^(-9).*[2,3,4]; y = [3,4,5];
</pre><pre class="language-matlab">figure(1); close(gcf); figure(1);
</pre><pre class="language-matlab">pos = get(gcf,'Position'); set(gcf,'Position',[pos(1),pos(2),0.5.*pos(3),pos(4)]);
</pre><pre class="language-matlab">semilogx(x,y,'-ok'); grid on; xlim([3*10^(-11),4*10^(-8)]);
</pre><pre class="language-matlab">set(gca,'XTickMode','manual'); set(gca,'XTick',10.^[-11:1:-7]); %change
</pre><p>but I'm still missing the minor gridlines to the far right. Any ideas?</p><p>Thanks!!</p>Namaka/matlabcentral/answers/contributors/2566930-namakatag:mathworks.com,2005:Question/1431862014-07-24T13:06:15Z2014-07-25T00:07:30Zcustom fittype error ??Matrix dimensions must agree<p>Hi All,</p><p>I have a customer function dIdVdei that takes 10 inputs and outputs a value. I'd like to fit a function to that, varying 8 of the inputs for the fit, one of the inputs as an independent variable, and 1 as a fixed problem variable.</p><p>I create a custom fittype as so:</p><pre class="language-matlab">independentvars = {'V'};
dependentvars = {'y'};
problemvars = {'T'};
coeffvars = {'omega', 'G', 'Aw', 'uL', 'uM', 'g1', 'g2', 'dIdV0'};
expression = 'dIdVdei( V, T, omega, G, Aw, uL, uM, g1, g2, dIdV0)'; %just call the function
func = fittype(expression, 'coefficients', coeffvars, 'independent', independentvars, 'dependent', dependentvars, 'problem', problemvars);
</pre><p>The dIdVdei code works fine on its own, but when I try to create that fittype I get the error:</p><pre class="language-matlab">Expression dIdVdei( V, T, omega, G, Aw, uL, uM, g1, g2, dIdV0) is not a valid MATLAB expression, has
non-scalar coefficients, or cannot be evaluated:
Error in fittype expression ==> dIdVdei( V, T, omega, G, Aw, uL, uM, g1, g2, dIdV0)
??? Matrix dimensions must agree.
</pre><p>I'm having trouble figuring out what the cause is; note this is before trying to fit anything, its just creating the fittype object. Some of the inputs (omega, G, and Aw) can be vectors, but at this point the code shouldn't even know that so I don't see how that could be the problem.</p><p>Any advice is appreciated, thanks!</p>Darin/matlabcentral/answers/contributors/3032878-darintag:mathworks.com,2005:Question/1432672014-07-25T00:04:10Z2014-07-25T00:04:10ZVery basic problem with using isAlways<p>I'm trying to learn to use the symbolic math functionality and I was playing around with isAlways. I ran the following commands:
a=sym('a','real');
b=sym('b','real');</p><p>isAlways(a>b|a==b|a<b)</p><p>ans=1</p><p>isAlways(a>=b|a<b)</p><p>ans=1</p><p>isAlways(a>=b|a<=b)</p><p>ans=0</p><p>I'm not entirely sure what I'm doing wrong but I really did expect the last statement to be true as well. Any thoughts?</p><p>Thanks a lot!</p>Poachumsm/matlabcentral/answers/contributors/5481201-poachumsmtag:mathworks.com,2005:Question/1432652014-07-24T23:51:59Z2014-07-24T23:51:59ZMaximal values of polynomial<p>Given <i>J(x)=(p(x)^2)/q(x)</i> where both p and q are polynomials defined in the workspace by horizontal coefficient arrays, and <i>q(x) > 0</i> for all values of x.</p><p>Create a Matlab script that will compute and display the real and finite value of x for which J(x) is maximized, and also display the maximal value of J achieved at this x value (using only numerical calculations and not symbolic Matlab calculations).</p><p>The script should find the maxima using <i>dJ(x)/dx=0</i> .</p><p>I am fairly new working with Matlab and I am unsure on how to approach this problem. I have tried:</p><pre class="language-matlab">P=conv(p,p);
Q=q;
[a,b]=deconv(P,Q) %J(x)
[c,d]=deconv((conv(Q,polyder(P))+conv(P,polyder(Q))),conv(Q,Q)) %dJ(x)/dx
r=roots([c,d])
J=max(abs(r))
</pre><p>but I am not getting the correct answer. For <i>p(x)=2x+5</i> (i.e. [2 5]) and <i>q(x)=x^4+x^2+2x+2</i> (i.e. [1 0 1 2 2]), the maximal of J should be approximately 12.9 occurring at x=-0.27. Your help is greatly appreciated.</p>Zach/matlabcentral/answers/contributors/4598502-zachtag:mathworks.com,2005:Question/1432642014-07-24T23:45:06Z2014-07-24T23:45:06ZHow to apply ode solvers to ode systems written in matrix form skipping expansion of their right- hand-sides? Show a representative example. <p>Let DY=A(t)Y be a system of linear odes in matrix form, where Y is an n*1-matrix and A is n*n-matrix. How to apply ode-solvers directly to this system without expending it?</p><p>Assume now that a system is nonlinear:</p><p>DY=f(t,Y); Y is an n*1-matrix. The question is how to apply ode-solvers without expending this equation.</p>Mark/matlabcentral/answers/contributors/52003-marktag:mathworks.com,2005:Question/1430792014-07-23T18:36:41Z2014-07-24T23:42:18ZRead 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:mathworks.com,2005:Question/1432482014-07-24T20:41:18Z2014-07-24T23:34:05ZUsing lsqcurvefit with constant parameters<p>Hi,
I am trying to use lsqcurvefit to fit data to an interference function that I created.
The problem is that some of the parameters in the function should remain constant through the fitting process (ie. the wavelength of the laser does not change etc...).
I have seen some other stabs at this but none that were thorough and actually worked when I ran them.
Here is some of my code so you know what I am talking about:</p><pre class="language-matlab">initials = [Aref,Aprobe,w0,z,lambda,phi,x0,y0];
fitfunc = @(initials,x) InterferePhase1(initials,X2);
fitparams = lsqcurvefit(fitfunc,initials, X2 ,imageArray,[], []);
</pre><p>Ideally, I should be able to run this fit and have my initial values for lambda, x0, and y0 stay the same after lsqcurvefit runs.</p><p>Let me know if you need any additional information!</p><p>Thanks for all your help!</p>Chris/matlabcentral/answers/contributors/5181591-christag:mathworks.com,2005:Question/1432612014-07-24T22:55:38Z2014-07-24T23:05:43Zabout the generator polynomial<p>Hi, I saw a matlab program, its generator polynomial of convolutional code is writen as mem=4,gen=[19 29]. What's the meaning? Thank you.</p>Chi/matlabcentral/answers/contributors/5050845-chitag:mathworks.com,2005:Question/1432212014-07-24T16:59:52Z2014-07-24T23:04:51ZHow to make a graphic 3d(surface) from 3 vectors in MATLAB.<p>I have for example X = [ 1 3 4 5 6] , Y = [ 2 3 4 5 6] and Z =[ 1 2 3 2 1] and i want to make a surface graphic.</p><p>They are in orders, each column represents one point in the coordinate ystem xyz.</p><p>I saw many posts but couln´t find the solution.</p><p>Thank you in advance.</p>Franco Gentili/matlabcentral/answers/contributors/5480748-franco-gentilitag:mathworks.com,2005:Question/1432582014-07-24T22:41:34Z2014-07-24T22:47:06ZI do not want the output of the following program is a complex number<pre class="language-matlab">clc
a=[29580 -17580 0;-17580 35160 -17580;0 -17580 17580];
b=[30 0 0;0 30 0;0 0 20];
syms w
c=w*w*b;
d=a-c;
e=det(d);
f=solve(e)
</pre>tatina/matlabcentral/answers/contributors/5481140-tatinatag:mathworks.com,2005:Question/1432592014-07-24T22:45:10Z2014-07-24T22:45:10ZCaretPositionChanged callback for editbox not working<p>Hi all,</p><p>I'm trying to detect when the position of the cursor in an editbox changes. This is the current code I'm using in the figure's opening function:</p><pre class="language-matlab">jEdit=findjobj(myEditbox);
set(jEdit, 'CaretPositionChangedCallback', @myCallback);
</pre><p>But for some reason it doesn't work. Other callbacks such as InputMethodtextChangedCallback works fine, but that's not what I need.</p><p>Does anyone know how to fix it?</p><p>Thanks a lot!</p><p>Niko</p>Niko/matlabcentral/answers/contributors/4630773-nikotag:mathworks.com,2005:Question/1432102014-07-24T15:53:40Z2014-07-24T22:34:37ZGlobal minimum of multivariate function<p>Hi, I'm a Matlab beginner. I'm trying to find the global minimum of a 28 variables quadratic function and I would like the parameters to be strictly positive. This is what I'm doing right now:</p><pre class="language-matlab">A = -eye(28);
b = zeros(28,1);
for i=1:28,
b(i,1) = -0.0001;
end;
xstart = randn(1, 28);
problem = createOptimProblem('fmincon', 'x0', xstart, 'objective', fun, 'Aineq', A, 'bineq', b);
[x fval eflag output] = fmincon(problem);
gs = GlobalSearch('Display', 'iter');
[xming,fming,flagg,outptg,manyminsg] = run(gs,problem);
</pre><p>However, the solution obtained is not particularaly good. Also, I think there is some problem, since it is a 28 variable function and the solution is given after less than 5 seconds. Do you have any clue about what I'm missing?</p>Luca/matlabcentral/answers/contributors/5480503-lucatag:mathworks.com,2005:Question/1432512014-07-24T21:18:00Z2014-07-24T22:23:47ZConvert matlab struct to C struct for mex<p>I have a struct that I'm writing in C and need to use a mex function to use it in matlab. The struct was originally in matlab and need to have the variables:</p><pre class="language-matlab">force = feval(forcing, Euler, Euler.x(:,k));
q = squeeze(q(:,k,:));
q0 = squeeze(Euler.q0(:,k,:));
nx = Euler.nx(:,k);% normal vector
J = Euler.J(1,k);
rx = Euler.rx(1,k);
qh = reshape(qh(k:k+1,:),[],1);
k = k;
</pre><p>The mex function I have come up with is:</p><pre class="language-matlab">#include "mex.h"
/* Extract local info for element k */
/* local struct */
typedef struct
{
double force;
double q;
double q0;
double nx;
double J;
double rx;
double qh;
double k;
} LocalInfo;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *field;
LocalInfo Local;
field = mexGetVariable(const char global,const char force);
Local.force = mxGetScalar(field);
field = mexGetVariable(const char global,const char q);
Local.q = mxGetScalar(field);
field = mexGetVariable(const char global,const char q0);
Local.q0 = mxGetScalar(field);
field = mexGetVariable(const char global,const char nx);
Local.nx = mxGetScalar(field);
field = mexGetVariable(const char global,const char J);
Local.J = mxGetScalar(field);
field = mexGetVariable(const char global,const char rx);
Local.rx = mxGetScalar(field);
field = mexGetVariable(const char global,const char qh);
Local.qh = mxGetScalar(field);
field = mexGetVariable(const char global,const char k);
Local.k = mxGetScalar(field);
}
</pre><p>I don't think I'm using the mexGetVariable right, but I haven't used it before and can't figure it out.</p><p>The forcing function in the matlab part is:</p><pre class="language-matlab">function [f] = forcing(Euler, x)
% Compute the forcing to yield exact solution
</pre><pre class="language-matlab">% $$$ rhoExact = @(x,t) 1 + A * sin(pi * (x - t));
% $$$ if (Euler.forcingFlag ~= 1
% $$$ uExact = @(x,t) ones(size(x));
% $$$ else
% $$$ uExact = @(x,t) x;
% $$$ end
% $$$ pExact = @(x,t) ones(size(x));
% $$$ EnerExact = @(x,t) pExact(x,t)/gamm1 + ...
% $$$ 0.5 * rhoExact(x,t) .* uExact(x,t).^2;
</pre><pre class="language-matlab">if Euler.forcingFlag == 1,
</pre><pre> A = Euler.A;
t = Euler.time;
gamm1 = Euler.gamm1;</pre><pre> r = 1 + A * sin(pi * (x - t));
dr_t = -pi * A * cos(pi*(x-t));
dr_x = pi * A * cos(pi*(x-t));</pre><pre> u = x*1.e-4;
du_t = 0;
du_x = 1*1.e-4;</pre><pre> p = 1;
dp_t = 0;
dp_x = 0;</pre><pre> E = p / gamm1 + 0.5 * r .* u.^2;
dE_t = dp_t / gamm1 + 0.5 * dr_t .* u.^2 + r .* u .* du_t;
dE_x = dp_x / gamm1 + 0.5 * dr_x .* u.^2 + r .* u .* du_x;</pre><pre> fluxr = r .* u;
dfluxr_t = dr_t .* u + r .* du_t;
dfluxr_x = dr_x .* u + r .* du_x;</pre><pre> fluxru = r .* u.^2 + p;
dfluxru_x = dr_x .* u.^2 + 2 * r .* u .* du_x + dp_x;</pre><pre> fluxE = (E + p) .* u;
dfluxE_x = (dE_x + dp_x) .* u + (E + p) .* du_x;</pre><pre> f = zeros(size(x,1),3);
f(:,1) = dr_t + dfluxr_x;
f(:,2) = dfluxr_t + dfluxru_x;
f(:,3) = dE_t + dfluxE_x;</pre><pre class="language-matlab">else
f = zeros(size(x,1),3);
end
</pre>Nicholas/matlabcentral/answers/contributors/5208217-nicholastag:mathworks.com,2005:Question/1432452014-07-24T20:17:29Z2014-07-24T22:22:44Ztake the average of each column element of two rows (in a 2 dimensional array) and insert that average between the two rows<p>I'm trying to take the average of 2 row elements in a 2 dimensional array and insert that average between the two.</p><p>For example,with the array:</p><p>2,3,4</p><p>4,5,6</p><p>should result in:</p><p>2,3,4</p><p>3,4,5</p><p>4,5,6</p>Allan N/matlabcentral/answers/contributors/574658-allan-ntag:mathworks.com,2005:Question/1432472014-07-24T20:31:02Z2014-07-24T22:19:34ZHow can i solve this linear system ?<p>Hello,</p><p>I have a linear system of equation composed of 14 equations and 49 unknowns.
I know that my system can be writed in the Ax=b form and then performing the division A\b to find the unknown vector x.
I'm new to Matlab so sorry if I'm asking trivial questions.</p><p>My questions are the following:</p><p>1) My system should have multiple solutions since it is underdetermined. A\b only gives 1 solution. Is there any way to get more than 1 solution ?</p><p>2) I already know that all my 49 unknown are within the range [0;1]. How can I set this constrains to all my unkown ?</p><p>3) I may have some unknown that I already know before solving the system. Is it possible to restrict some value of the x vector without having to rewrite the whole system like it is said in the following thread: <a href = "http://www.mathworks.fr/matlabcentral/answers/17795-basic-matrix-equation-ax-b-with-restrictions">http://www.mathworks.fr/matlabcentral/answers/17795-basic-matrix-equation-ax-b-with-restrictions</a></p><p>4) Is it possible to import a matrix from a text file, because my A matrix is quite big ?</p><p>Regards,
Debzz</p>debzz/matlabcentral/answers/contributors/5481017-debzztag:mathworks.com,2005:Question/1432562014-07-24T22:06:27Z2014-07-24T22:06:27ZRange Doppler Response has a linear bias<p>The range doppler response of matlab's phased array system toolbox seems to have a linear bias for doppler frequency. The system is a moving radar platform (at certain altitude) and a stationary ground target and ground clutter (modeled as phased.ConstantGammaClutter object). In my particular case, 0 velocity will have everything in correct frequency (0 Hz for ground clutter and target), however for 10 m/s velocity, the frequency is 88 Hz more than what it should be (for both ground clutter and ground target), for 20 m/s it is 88*2 Hz more and so on. I am not sure if I'm missing some parameters, my phased.RangeDopplerResponse object is defined as follows</p><pre class="language-matlab">myResponse = phased.RangeDopplerResponse('RangeMethod','Matched Filter', ...
'PropagationSpeed',c, 'DopplerOutput','speed',...
'SampleRate', fs,'OperatingFrequency',fc,...
'DopplerFFTLengthSource','Property', ...
'DopplerFFTLength',1024);
</pre><p>Also, the limit on doppler frequency is supposed to be -PRF/2 to PRF/2 but it is a bit beyond that. This is not of too much concern, but the bias on doppler frequency is an issue. Any help or clarification is greatly appreciated. thanks</p>ramesh/matlabcentral/answers/contributors/3801971-rameshtag:mathworks.com,2005:Question/1423782014-07-18T14:16:46Z2014-07-24T21:57:38ZPlot - Problems with background colour<p>I can change the background colour in plots with "whitebg", but those colour changes are not saved, when I save the figure as a .png with</p><pre class="language-matlab">saveas(gcf,'test.png')
</pre><p>What can I do?</p><p>This is a different question, but</p><pre class="language-matlab">set(gcf,'Color',[0.8 0.8 0.8])
</pre><p>doesn't change the background colour at all.</p>Aaron/matlabcentral/answers/contributors/5445947-aarontag:mathworks.com,2005:Question/1432552013-10-18T04:00:00Z2014-07-24T21:48:03ZHow does the COLON operator work?<p>I want to know how the COLON operator works:</p><p>For example, in the command</p><pre class="language-matlab">v = a:d:b
</pre><p>I would like to know if the vector 'v' is calculated by repeated addition of multiples of 'd' to a.</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:mathworks.com,2005:Question/1424612014-07-18T21:46:38Z2014-07-24T21:43:25ZMatching two arrays that have similar values<p>I have two folders that have time stamped files. The time stamps are in this format:
MMDDYY HHMMSS.###
where ### is the number of milliseconds.</p><p>I need to compare the contents (file names) of the two folders and generate a new array (or structure) that contains all the files from both folders that have time stamps within 12 milliseconds of each other.</p><p>I have manipulated the file name strings and generated numeric arrays with the file stamps but then I still have to compare two large numeric arrays to each other with double loops etc.</p><p>That just takes up too much time (I have dozens of folders each containing thousands of files).</p><p>I was wondering if there is a quicker easier way to do it?</p><p>Thank you in advance</p>HRmatlab/matlabcentral/answers/contributors/122458-hrmatlabtag:mathworks.com,2005:Question/1432542014-07-24T21:38:45Z2014-07-24T21:38:45ZDefine Cylinder Radius in Vrml through Matlab code<p>Hello,i need to be able to change the Cylinder Radius in my Vrml through Matlab code.</p><p>For example to change the translation of an object i use:</p><p>fields(world.Car)
world.Car.translation=[x y z];</p><p>How can i change the Cylinder Radius?</p><p>I used world.Cylinder.children.Shape.geometry.Cylinder.radius = Radius_of_Tank; but it does not work.</p><p>Thank you</p>theocharisdrakos/matlabcentral/answers/contributors/3854548-theocharisdrakostag:mathworks.com,2005:Question/1432522014-07-24T21:30:29Z2014-07-24T21:30:29ZMEX command dropping me to gnome terminal inside MATLAB<p>Hi,
I am using MATLAB with R2014a. Whenever I am executing mex (with any input or flag) it is transferring me to the ubuntu terminal while keeping me inside the matlab GUI and I am completely clueless as to why such a thing can happen. Here, is a log of one such execution.</p><pre class="language-matlab">>> mex arrayProduct.c
bhokaal@jacobswks09:/scratch0/rcpn$ exit
</pre><pre class="language-matlab">exit
</pre><pre class="language-matlab">bhokaal@jacobswks09:/scratch0/rcpn$ exit
</pre><pre class="language-matlab">exit
Building with 'gcc'.
</pre><pre class="language-matlab">bhokaal@jacobswks09:/scratch0/rcpn$ exit
</pre><pre class="language-matlab">exit
</pre><pre class="language-matlab">bhokaal@jacobswks09:/scratch0/rcpn$ exit
</pre><pre class="language-matlab">exit
</pre><pre class="language-matlab">bhokaal@jacobswks09:/scratch0/rcpn$ exit
</pre><pre class="language-matlab">exit
</pre><pre class="language-matlab">bhokaal@jacobswks09:/scratch0/rcpn$ exit
</pre><pre class="language-matlab">exit
</pre><pre class="language-matlab">MEX completed successfully.
</pre><pre class="language-matlab">>>
</pre><p>Please note that the ONLY exit after executing exit command from me is the output of the terminal I am not typing exit twice.</p><p>When on linux terminal, I can use any of the terminal supported commands like grep, sed etc. The only way to get out of the gnome terminal and get back to MATLAB terminal(with ">>") is to keep executing exit a multiple times, till I land back to MATLAB terminal, otherwise, it keeps showing busy and sits idle.</p><p>Possible things tried -
1. Removed .matlab folder from home and then launched MATLAB again, which created .matlab folder again, but for no good.</p><p>I cannot re-install MATLAB because I am using a university machine, I can only make modifications to my machine. I checked on other machines without using my account the same thing and it worked perfectly. Any idea ?</p>Abhishek/matlabcentral/answers/contributors/5464041-abhishektag:mathworks.com,2005:Question/1432442014-07-24T20:16:28Z2014-07-24T21:22:31Zhow can i use sfta code to extract texture features<p>texture features</p>solomon adenew/matlabcentral/answers/contributors/4553211-solomon-adenewtag:mathworks.com,2005:Question/1430462014-07-23T14:58:02Z2014-07-24T21:14:27ZHow to input points and numbers into GUI<p>I am trying to write my first GUI, so please be patient!!! I need to know how to create a box or field or something that I can type numbers into that will then be used when the GUI runs.</p>Kneel Armstrong/matlabcentral/answers/contributors/5478553-kneel-armstrongtag:mathworks.com,2005:Question/1432002014-07-24T14:34:21Z2014-07-24T21:03:13Ztaking fft of .wav file<p>I am trying to get the fft of a specific part of the signal coming from a .wav file.</p><p>the wav file is a repetition of the signal every 0.6 seconds. I am trying to figure out how to get the repetition 10 times and compare to show that the results should be similar.</p><p>this is the code i have for now</p><pre class="language-matlab">Fs = 44100;
cj = sqrt(-1);
</pre><pre class="language-matlab">[test,fs]= wavread('3b healthy2.wav'); % File data name
</pre><pre class="language-matlab">dt = 1/Fs;
time = 45.6;
N = time/dt;
</pre><pre class="language-matlab">left=test(:,1);
right=test(:,2);
</pre><pre class="language-matlab">I = left;
Q = right;
</pre><pre class="language-matlab">t = 0:dt:(time-dt);
</pre><pre class="language-matlab">n = length(t);
</pre><pre class="language-matlab">f = -Fs/2:Fs/n:Fs/2-Fs/n;
</pre><pre class="language-matlab">s = I+cj.*Q;
</pre><pre class="language-matlab">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Smooth the signal
ss = smooth(s,201);
</pre><pre class="language-matlab">sf = fftshift(fft(ss(1:N))); % taking fft
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</pre><pre class="language-matlab">figure(2)
</pre><pre class="language-matlab">plot(f,(abs(sf))./max(abs(sf)))
</pre><p>so once i separate program i can find out the time domain and from there i found that one repetition is at 45.2 to 45.8.</p><p>after i run this program i get a graph but form what i can see is not including one repetition but all repetition combined up to 45.2</p><p>any help will be much appreciated :) Thanks</p>Fragkos Maragkou/matlabcentral/answers/contributors/4155894-fragkos-maragkoutag:mathworks.com,2005:Question/1432502014-07-24T21:02:10Z2014-07-24T21:02:10ZI want to add(or perform some other function 'fun') on the distinct blocks(sub image) of the full size image using my own myblockproc function(code is given below). Here I have used a small matrix of dim 5,5,4 for testing purpose, actually i have to <p>Subscripted assignment dimension mismatch.</p><p>Error in myblockproc (line 30)
blk(:,:,k)=tmp(tc : tc+a-1 , tr : tr+b-1);</p><p>Error in testmyblock (line 19)
CR = myblockproc(I,3,3);</p><p>ere is my code on my test matrix of dim 5,5,4. Block size is 2X2.</p><p>function [J] = fun(I)
J=I(:,:,1)+I(:,:,2)+I(:,:,3)+I(:,:,4);
end</p><p>function [J] = myblockproc(I,r,c)
[m,n,p]=size(I);
ro=ceil(m/r);
cl=ceil(n/c);
Rr=mod(m,r);
Rc=mod(n,c);
blk=zeros(r,c,p);
for i= 1:ro
a=r;
if i==ro
a=Rr;
end
tc=((i-1)*r)+1;
for j=1:cl
b=c;
if j==cl
b=Rc;
end
tr=((j-1)*c)+1;</p><pre> for k=1 : p
tmp=I(:,:,k)
blk(:,:,k)=tmp(tc : tc+a-1 , tr : tr+b-1);
end
J=fun(blk);
end
end</pre><p>function [CR] = testmyblock()</p><p>I(:,:,1)=[1 2 3 4 5 ;6 7 8 9 10 ;11 12 13 14 15; 16 17 18 19 20; 21 23 23 24 25];
I(:,:,2)=[1 2 3 4 5 ;6 7 8 9 10 ;11 12 13 14 15; 16 17 18 19 20; 21 23 23 24 25];
I(:,:,3)=[1 2 3 4 5 ;6 7 8 9 10 ;11 12 13 14 15; 16 17 18 19 20; 21 23 23 24 25];
I(:,:,4)=[1 2 3 4 5 ;6 7 8 9 10 ;11 12 13 14 15; 16 17 18 19 20; 21 23 23 24 25];</p><p>CR = myblockproc(I,3,3);
end</p>Fahad Ahmed/matlabcentral/answers/contributors/3227579-fahad-ahmedtag:mathworks.com,2005:Question/1432492014-07-24T20:58:20Z2014-07-24T20:59:58ZHow do I convert a vector of vertex coordinates and a list of edges to a DXF file?<p>I have a program that displays a design in a UI and outputs two vectors. One is a list of the XY coordinates of vertices and the other is a list of the edges connecting them. I have a program that converts simple X,Y,and Z values of a single curve to a DXF file, but I'm not sure how to convert my design that has multiple curves that are not connected to a DXF file.</p><p>Thanks!</p>Isabella/matlabcentral/answers/contributors/4584765-isabellatag:mathworks.com,2005:Question/1430382014-07-23T14:27:40Z2014-07-24T20:56:07ZCan 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:mathworks.com,2005:Question/1428722014-07-22T08:41:58Z2014-07-24T20:46:32ZMatlab GUI background color changing to black when using parallel computing<p>Hi.</p><p>I designed a GUI in Matlab that uses parallel computing in loops for accelerating speed. When I disable parallel computing every thing Is normal but when I active it background color of my GUI and axes change color to black and I can only see other things like buttons,texts,edit boxes and etc. What is the problem?</p><img src = "/matlabcentral/answers/uploaded_files/15696/black.jpg"><p>Thanks.</p>Jack/matlabcentral/answers/contributors/5193869-jacktag:mathworks.com,2005:Question/1431092014-07-23T23:12:59Z2014-07-24T20:42:10ZHow to do interpolation of an unevenly sampled matrix?<p>I have a data in the form of a matrix (88x3). It is not evenly sampled, how can I do interpolation on it so that it becomes evenly sampled. I need to perform low pass filtering on this data.
Any help would be greatly appreciated.</p>NIHARIKA/matlabcentral/answers/contributors/5453760-niharikatag:mathworks.com,2005:Question/1265602014-04-21T16:37:32Z2014-07-24T20:41:41ZHow to communicate/connect to SMC100CC controller (Newport Instr) using Matlab?<p>I have SMC100CC controller from Newport. They have supplied drivers for National Instruments also but it doesn't get recognized in NI MAX. I presumed that if its gets recognized in NI MAX I could communicate using MATLAB since I have to use with MATLAB for my research. Communication path is as follows: Computer to USB-RS232 adapter to RS232 cable to SMC100CC controller. Thanks in advance.</p>Jay/matlabcentral/answers/contributors/2767625-jaytag:mathworks.com,2005:Question/1428022014-07-21T18:38:34Z2014-07-24T20:34:01ZCalculations in table based on variable names<p>I am trying to find a better solution to calculation using data stored in table. I have a large table with many variables (100+) from which I select smaller sub-table with only two observations and their difference for smaller selection of variables. Thus, the resulting table looks for example similarly to this:</p><pre> AIR BBS BRI
_________ ________ _________</pre><pre> test1 12.451 0.549 3.6987
test2 10.2 0.47 3.99
difference 2.251 0.078999 -0.29132</pre><p>Now, I need to multiply the ‘difference’ row with various coefficients that differ between variables. I can get the same result with the following code:</p><pre class="language-matlab">T(4,:) = array2table([T.AIR(3)*0.2*0.25, T.BBS(3)*0.1*0.25, T.BRI(3)*0.7*0.6/2])
</pre><p>However, I need more flexible solution since the selection of variables will differ between applications. I was thinking that better solution might be using varfun and function with if elseif (applying coefficients based on variable names):</p><pre class="language-matlab">T(4,:) = varfun(func,T3(3,:),'InputVariables',{'AIR' 'BBS' 'BRI'})
</pre><p>But I was unable to figure out how to correctly express the function that would assign the proper equations based on variables names.
Any help would be appreciated. Thank you guys.</p>Jonas/matlabcentral/answers/contributors/5465924-jonastag:mathworks.com,2005:Question/1432412014-07-24T20:03:56Z2014-07-24T20:34:00ZLoading variables in GUI<p>Hi, I'm trying to make my first (successful) GUI here, and I'm getting close. I have all my callbacks working, functions do what they are supposed to, but I'm having a heck of a time getting MATLAB to load the input data correctly. What I'm trying to load is a 5000x4 table with columns <tt>Datestr/Number/Number/Number</tt>. However, I am having terrible luck.</p><p>When I used <tt>load</tt>, it read my Datestr as a number and only gave me the first digit.</p><p>When I use <tt>open</tt> it gives me a struct, which I can work with, but it's a tedious work around.</p><p>When I use <tt>uiopen</tt>, I don't know how to get the file to work with the rest of my GUI.</p><p>If I can make it work, using <tt>uiopen</tt> is ideal because it lets enduser just choose the file they want. However, if they don't choose the text string in my GUI, I dont' know how to read the file. Included below is my most recent attempts at coding it in, but I keep getting invalid file errors.</p><pre class="language-matlab">% --- Executes on button press in loadbutton.
function loadbutton_Callback(hObject, eventdata, handles)
</pre><pre class="language-matlab">[pathstr,name,ext] = fileparts(handles.filename);
uiopen(strcat(name,ext));
file=name; |<---- THIS LINE IS GIVING ME PROBLEMS! How do I fix it?|
if iscell(file)
handles.file=cell2table(file);
elseif istable(file)
handles.file=file;%This is good!
else
handles.file=array2table(file);
end
</pre><p>Basically, what I'm running into is rather than saving the variable named 'Name' as something, it's just saving the string as it. so I get <tt>file = 'March2011'</tt> not <tt>file = March2011 Table 5000x4</tt></p><p>Also, When I am trying to callback this later, I might be having problems there, but I don't think I am. That bit of code is</p><pre class="language-matlab">function calculatebutton_Callback(hObject, eventdata, handles)
% hObject handle to calculatebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">if isempty(handles.file)
error('File to load?')
else
handles.file=file;
end
guidata(hObject,handles);
</pre>Mike Beacham/matlabcentral/answers/contributors/5365313-mike-beachamtag:mathworks.com,2005:Question/1432192014-07-24T16:47:05Z2014-07-24T20:30:27ZUndefined function when successfully opening .fig<p>I am opening a new GUI window when a user clicks a button in an existing window. To do this, in the button callback I issue the command</p><pre class="language-matlab">gui2Handle = open('GuiWindow2.fig');
</pre><p>However, Matlab then prints the error</p><pre> Undefined function 'GuiWindow2' for input arguments of type 'char'.</pre><p>which is strange because I'm not giving any arguments at all. It seems like for some people this error results when there's an issue with the path, but when I type</p><pre> which GuiWindow2.fig</pre><p>into the command window, I get the correct directory. Additionally, after Matlab prints the error about input arguments of type 'char' a couple of times, it then goes on to open the figure, and so far I haven't found anything about it that doesn't work.</p><p>I've tried debugging with "if error" but although it stops as soon as it prints the undefined function error, it doesn't bring me to any line in the code, then if I step through, it might print the error once more and then the figure appears, but the debugger never highlights any lines of code.</p><p>Any ideas on why this error is appearing and how to remove it?</p>Forrest/matlabcentral/answers/contributors/5365331-forresttag:mathworks.com,2005:Question/1432462014-07-24T20:26:44Z2014-07-24T20:26:44Z3D Surface plot with spline interpolation<p>I am trying to plot 2d data in the 3d plane to create a surface that represents the effects of changing z.</p><p>Data: Each column of my data represents a X, Y, and a Z value respectively.</p><p>@ z=12 I have the data.</p><p>d =</p><pre> 0.3000 0 12.0000
0.2898 0.0776 12.0000
0.2598 0.1500 12.0000
0.2121 0.2121 12.0000
0.1500 0.2598 12.0000
0.0776 0.2898 12.0000
0.0000 0.3000 12.0000
-0.1165 0.4347 12.0000
-0.2250 0.3897 12.0000
-0.4243 0.4243 12.0000
-0.7794 0.4500 12.0000
-0.8693 0.2329 12.0000
-0.9000 0.0000 12.0000
-0.8693 -0.2329 12.0000
-0.7794 -0.4500 12.0000
-0.6364 -0.6364 12.0000
-0.4500 -0.7794 12.0000
-0.2329 -0.8693 12.0000
-0.0000 -0.9000 12.0000
0.2329 -0.8693 12.0000
0.4500 -0.7794 12.0000
0.5303 -0.5303 12.0000
0.3897 -0.2250 12.0000
0.4347 -0.1165 12.0000
0.3000 -0.0000 12.0000</pre><p>@ z=14 I have the data.</p><p>d =</p><pre> -0.2121 0.2121 14.0000
-0.6495 0.3750 14.0000
-0.8693 0.2329 14.0000
-0.9000 0.0000 14.0000
-0.8693 -0.2329 14.0000
-0.7794 -0.4500 14.0000
-0.6364 -0.6364 14.0000
-0.4500 -0.7794 14.0000
-0.2329 -0.8693 14.0000
-0.0000 -0.6000 14.0000
0.0388 -0.1449 14.0000</pre><p>@ z=16 I have the data.</p><p>d =</p><pre> -0.8693 0.2329 16.0000
-0.9000 0.0000 16.0000
-0.8693 -0.2329 16.0000
-0.7794 -0.4500 16.0000
-0.6364 -0.6364 16.0000</pre><p>In order to use Matlab's built in surface command I need to have the different levels of Z to be of equal dimensions. Therefor I am trying to interpolate the data so that each set of z values have 50 rows and give the surface a round effect. Unfortunately I am not able to successfully do this. I have looked throughout Matlab Central to find a similar problem with a solution and was not able to find anything. Could you guys help me out or point me in the right direction please?</p>Joseph/matlabcentral/answers/contributors/2682372-josephtag:mathworks.com,2005:Question/1432232014-07-24T17:36:21Z2014-07-24T20:09:06Znonlinear minimization with fminunc<p>Hi All:</p><p>I am doing parameterization by minimizing a nonlinear target function. However, after the iteration runs, it returns the following message. And returns with the initial values for the parameters that I set.</p><pre> *Iteration Func-count f(x) Step-size optimality
0 9 1.46536 7.77e+06
1 144 1.39431 1.57417e-14 5.47e+06 </pre><p>Local minimum possible.</p><p>fminunc stopped because the size of the current step is less than
the default value of the step size tolerance.*</p><p>There is no error in the code. What do you suggest to solve this issue?</p><p>Thank you!</p>Daniel/matlabcentral/answers/contributors/5465454-danieltag:mathworks.com,2005:Question/1431972014-07-24T14:17:12Z2014-07-24T20:07:55ZHow do I write a dynamic search path?<p>I'm working on a parsing file that will loop through several levels of folders to read a .csv file from within the lowest level. I am trying to write a dynamic search path to do this so that the script will rewrite the directory that I am searching for the .csv files in every time. So far my code to reset the search path and store the new search path in the directory variable looks something like this:</p><pre class="language-matlab">for j = 1:length(directory)
datapathf1 = 'C:\Users\puffypuffin\Desktop\DATA\j';
directory = dir(strcat(datapathf1,'\f130'))
end
</pre><p>I want j to represent the folder level in which there are several different folders, i.e. f130, c220, and t500. However, I don't believe that my code is doing this correctly. Is there a syntax for having a variable in a dynamic searchpath?
Thanks!</p>Katherine/matlabcentral/answers/contributors/5480294-katherinetag:mathworks.com,2005:Question/801362013-06-25T05:53:09Z2014-07-24T20:07:49Zhow to call and read input data from external port?<p>I have input data coming from external port DAQ and i have instilled the matlab driver to read the data in DAQ toolbox, now i want to know how call and read this data in the command window for further programming?</p><p>thanks,</p>Ahmed Fadhil Hassoney/matlabcentral/answers/contributors/4314352-ahmed-fadhil-hassoneytag:mathworks.com,2005:Question/1429832014-07-22T23:47:00Z2014-07-24T20:02:01ZHow can I delete an entire row in a matrix and shift the rest of the matrix below the deleted row up each time I delete??<p>I want to delete an entire row and shift the remaining matrix below the deleted row up by one, each time I delete a row.</p>Allan N/matlabcentral/answers/contributors/574658-allan-ntag:mathworks.com,2005:Question/1432172014-07-24T16:42:17Z2014-07-24T20:00:07ZHow can I display recognized digits on output?<p>I am using Neural Network from Matlab toolbox,My input to the classifier are dtmf digits pitch and intensities. The desired output digits should be any three digits of my inputs according to which rows of target should also be three digits and number of columns remain the same for input and outputs,Can you tell me please how will I know the output digits?</p><p>Moreover, is there any way that i could per testing on neural network just like we do on naivebayes classifier by giving test file, train file and target file?</p><p>Hope you will come with a clue to this. Thanks!</p><p>Soniya.</p>Soniya Rudani/matlabcentral/answers/contributors/4450971-soniya-rudanitag:mathworks.com,2005:Question/1426902014-07-21T00:25:50Z2014-07-24T19:54:05ZHow I can read variables from a .txt?<p>I have a GUI and I need to save some variables in a .txt to export to another platform while you can rerun the GUI with the same values at any time</p><p>My code is:</p><pre class="language-matlab">function Save_Callback(hObject, eventdata, handles)
global D F W
File=get(handles.edit1,'String');
save(File, 'D', '-ASCII','-append');
save(File, 'F', '-ASCII','-append');
save(File, 'W', '-ASCII','-append');
</pre><pre class="language-matlab">function Load_Callback(hObject, eventdata, handles)
global D F W
File=get(handles.edit2,'String');
</pre>Christian Fernando/matlabcentral/answers/contributors/4440094-christian-fernandotag:mathworks.com,2005:Question/1407722014-07-07T18:37:55Z2014-07-24T19:43:00ZThe traning is 100% but mistake in testing<p>Hi everybody...i traning my dataset ...i used surf algorithm to extract features
and i selected 10 features for everyclass..i have 5 classes..
the traning reaches to 100% but when enter image to test the result is not correct
for example when enter image of first class it classefy as second or thired
class...why this happen ...olz help me</p>primrose khaleed/matlabcentral/answers/contributors/5155066-primrose-khaleedtag:mathworks.com,2005:Question/1432402014-07-24T19:42:07Z2014-07-24T19:42:07ZLogarithmic spiral curve fitting in an image <pre> I have been tackling this problem from past 3 months, and I'm not able to find a solution for spiral curve fitting on an image. I have many spiral rgb image like a galaxy, cyclone, bisected conch and should fit a log-spiral on it.
Here is a sample image, please help.</pre><img src = "/matlabcentral/answers/uploaded_files/15791/203.jpg"><p>Thank you.</p>Tilak Devaraj/matlabcentral/answers/contributors/4813293-tilak-devarajtag:mathworks.com,2005:Question/1430552014-07-23T15:49:28Z2014-07-24T19:39:40ZSimulink Real Time target with softing CAN-AC2-PCI card<p>Hi everyone,</p><p>I am working with a CAN card (CAN-AC2-PCI by Softing) plugged to PCI 1, more precisely the BIOS(Core Version: 4.6.5.3 0.18.x64) by American Megatrends. I want to use the Simulink Real Time target environment, but when trying to download the Simulink model to Target PC, I get the following error:</p><p>--------------------------------------------------------------------------------
downloading CAN-AC2-PCI firmware on board 1
-->error in CANPC_reset_board_mbx:ErrorCode:-1 Error Text
--------------------------------------------------------------------------------</p><p>Could someone help with this issue?</p><p>More info:</p><p>CAN Card => Model: Softing CAN-AC2-PCI
Matlab => R2014a
Compiler => MICROSOFT Visual Studio 2010</p><p>Thanks in advance!</p>Ruigen/matlabcentral/answers/contributors/3533743-ruigentag:mathworks.com,2005:Question/1431822014-07-24T12:43:03Z2014-07-24T19:39:33ZHow to repeat a rectangular matrix in matlab?<p>How to repeat a rectangular matrix in matlab?</p><p><b>Not using loops, just matlab's build-in commands.</b></p><p>Thanks a lot!</p><img src = "/matlabcentral/answers/uploaded_files/15778/a1.jpg">rui/matlabcentral/answers/contributors/1078534-ruitag:mathworks.com,2005:Question/1432392014-07-24T19:36:13Z2014-07-24T19:38:41ZError using load - Can't read file<p>Trying to load a data file. There are a number of other files all made at the same time from the same folder but one of will not load. The file exists, as I tested, and is in the proper location but will not open. Any thoughts or ideas on where to go from here?</p><p>Error using load
Can't read file C:\ .... \xyz.mat.</p><p>EDU>> exist('xyz.mat')</p><p>ans =</p><pre> 2</pre>Melanie/matlabcentral/answers/contributors/5480971-melanietag:mathworks.com,2005:Question/1430822014-07-23T19:13:15Z2014-07-24T19:35:56ZNeed 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:mathworks.com,2005:Question/1431032014-07-23T21:31:30Z2014-07-24T19:29:27Z What is the fastest way to list all positive integer vectors whose sum of elements equals K.<p>For example I want to list all row vectors (1,5) whose elements are positive integers and sum of elements equals to 20. I am looking for a fast way which not use the loop-for for each elements.
Please help.</p>Vu Ha/matlabcentral/answers/contributors/5479157-vu-ha