http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-10-10T05:18:29Ztag:www.mathworks.com,2005:Question/2477992015-10-10T03:48:51Z2015-10-10T05:18:29ZPassing functions to functions<p>Hi, i am trying to write a code for Newton's Method, but before I can even get to where I am actually doing the method i can't get the function and its derivative to be defined
They're both supposed to be user-inputted, in a single variable in the function call, where we call another function to define it exactly as
[fx dfx]=f(x)</p><p>Here are the specific instructions regarding what I am confused about</p><pre class="language-matlab">f: a function handle; [fx,dfx]=f(x) must compute f(x) (fx) and f(x) (dfx).
</pre><p>but I don't under stand, nor can i get it to work. I've been passing the function 'myfunc' into Newton, and I've tried many different things, none work.
myfunc.m</p><pre class="language-matlab">function [fx dfx] = myfunc(x)
fx=cos(x) -x;
dfx=-sin(x)-1;
end
</pre><p>and Newton.m</p><pre class="language-matlab">function x= Newton(f,x0,pflag,Tol,ftol,maxit)
xold=x0
x=xold
</pre><pre class="language-matlab">[fx dfx]=f(x)
err= x0;
ferr= abs(f(xold));
maxit=0;
while err>tol && ferr>tol
xnew=xold-fx(xold)/dfx(xold);
err=xnew-xold;
ferr=abs(fx(xnew));
maxit=maxit+1;
end
</pre>Travis Melkahttp://www.mathworks.com/matlabcentral/profile/authors/4602390-travis-melkatag:www.mathworks.com,2005:Question/2477582015-10-09T20:42:31Z2015-10-10T05:16:30Z"Subscripted assignment dimension mismatch" when checking for signals in ventricles and outside of the brain<p>When I enter a command "m= extract_gray_white_csf(dat);" it returns the following error message:</p><pre class="language-matlab">Extracting from gray_matter_mask.img.
</pre><pre> Subscripted assignment dimension mismatch.</pre><pre> Error in image_vector/extract_gray_white_csf (line 36)
values(:, i) = nanmean(masked_obj.dat, 1)';</pre><p>The other questions I have read seem to indicate that the source and destination are not of the same dimensions, but how to I solve that issue? Does the "m" workspace need to be expanded or shortened, and how do I tell which needs to be adjust? What code should I use to solve this error?</p>Morgan Gianolahttp://www.mathworks.com/matlabcentral/profile/authors/6876440-morgan-gianolatag:www.mathworks.com,2005:Question/2478042015-10-10T04:53:25Z2015-10-10T05:14:40ZGenetic Algorithm (GA)<p>I would like to ask how can I use Genetic Algorithm toolbox in matlab and how it will be used for optimization or desired output..?</p>Waqar Waheedhttp://www.mathworks.com/matlabcentral/profile/authors/6489330-waqar-waheedtag:www.mathworks.com,2005:Question/2477352015-10-09T17:26:36Z2015-10-10T05:14:28ZI am using Matlab2014b ,I am trying to use simulink arduino interfacing , but Having problem in COM connectivity. Even in command window Arduino is detected but at the time of burning it does not detect. please help <p>The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
Could not connect to specified Arduino board.</p>Muhammad Yasir Sarwarhttp://www.mathworks.com/matlabcentral/profile/authors/5180324-muhammad-yasir-sarwartag:www.mathworks.com,2005:Question/2478022015-10-10T04:26:38Z2015-10-10T05:13:05ZFill the plot but it should not be closed by connecting first vertex to the last<p>I have a plot which consists of alternate layers of two species. I need to fill these layers with specified colors but it should not be closed by connecting last vertex to the first. When I use the fill command it connects the vertices and I do not want it that way. Please guide.</p>PRITESH GARGhttp://www.mathworks.com/matlabcentral/profile/authors/6208580-pritesh-gargtag:www.mathworks.com,2005:Question/2478012015-10-10T04:20:46Z2015-10-10T05:00:36ZRREF not giving reduced echelon form<p>Dear!</p><p>I am having a system of 5 linear equations, with 5 unknowns to be determined. When I use the command of rref (A) on the matrix A (Augmented matrix) then instead of reduced echelon form it gives all the entries in first row, and making remaining 4 rows as zero rows, could not understand why is happening so.</p><p>1) here I represent the part of program where I represented this operation</p><pre class="language-matlab">for i=2:1:length(O)
QQQ =[M1(i,1) M1(i,2) M1(i,3) M14(i,1) 0 b1(i,1);M2(i,1) M2(i,2) M2(i,3) M24(i,1) 0 b2(i,1);M3(i,1) M3(i,2) M3(i,3) 0 0 b3(i,1);M4(i,1) M4(i,2) M4(i,3) 0 M45(i,1) b4(i,1);M5(i,1) M5(i,2) M5(i,3) 0 M55(i,1) b5(i,1)];
RR=rref(QQQ)
II(i,:) =RR(1,6)
end
</pre><p>where each M is defined properly,</p><p>result for the value of i=2 are as follows</p><pre class="language-matlab">-3.6035e+050 -1.0331e+035i 3.2541e+021 +6.1677e+019i -5.1763e+020 -2.5318e+020i -2.3565e+019 0 7.2761e+018
0.12558 -8.6149e+014i -2.5881 - 0.024521i 0.24839 - 1.0585i -0.99606 0 0.86678
-2.1361e+049 +4.8846e+064i -1.2606e+021 -3.7042e+019i -6.8697e+019 +1.0156e+020i 0 0 7.1063e+048 +2.0718e+033i
-1.513e+017 + 1.038e+033i -2.1573e+005 - 6339i -7837.5 + 11586i 0 0.0050625 - 7.79e+013i -1.5087e+017 -9.9402e-015i
2.1361e+059 -4.8846e+074i 1.2606e+031 +3.7042e+029i 6.8697e+029 -1.0156e+030i 0 0.00021977 -3.0093e-036i -7.1063e+058 -2.0718e+043i
</pre><p>in command window it looks alike</p><pre class="language-matlab">1.0e+074 *
</pre><pre> Columns 1 through 5 </pre><pre> -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 0
0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 0
-0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0 0
-0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0 0.0000 - 0.0000i
0.0000 - 4.8846i 0.0000 + 0.0000i 0.0000 - 0.0000i 0 0.0000 - 0.0000i</pre><pre> Column 6 </pre><pre> 0.0000
0.0000
0.0000 + 0.0000i
-0.0000 - 0.0000i
-0.0000 - 0.0000i</pre><p>after applying rref(QQQ) I get</p><pre class="language-matlab">1 -7.5834e-046 +2.5808e-044i 2.0791e-045 +1.4064e-045i 0 1.9676e-094 +4.4992e-079i -2.1208e-032 -1.4548e-016i
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
</pre>Adnan Jahangirhttp://www.mathworks.com/matlabcentral/profile/authors/2042549-adnan-jahangirtag:www.mathworks.com,2005:Question/2478032015-10-10T04:43:04Z2015-10-10T04:43:04ZDenormalization output neural network <p>I used the equation of the neural network ("y = b2 + LW * tansig (b1 + IW * x)") to an Excel, so you can calculate the output values of two input values and one target of a network of two neurons and one layer, values generated by the equation "y = b2 + LW * tansig (IW + b1 * x)" (all done in excel) are normalize, give me exactly equal to the coefficient of determination delivered by Matlab but it gives me different values between output Excel and output Matlab because one is normalize (excel).</p><p>Someone can write the equation for me to denormalize my output values, I have sought "mapminmax" command but I can not understand how denormalize (the variables of the equation). Is there a website where explain the command mapminmax , but can not understand how denormalize (to do it in excel).</p><p>please help.</p>Mary Smithhttp://www.mathworks.com/matlabcentral/profile/authors/7033982-mary-smithtag:www.mathworks.com,2005:Question/2477672015-10-09T22:54:04Z2015-10-10T04:31:57Zhow to substitute an syms variable into known value and evaluate the result of the same equation that contain it?<p>i'm tying to generate a general equation for Bezier curve in polynomial form , differentiate it, then substitute the value of u by 0 or 1 in the general equation but i don't know how</p><pre class="language-matlab">% u incremental value
n=input('input the number of control points = ');
k= n-1
m=1;
for i=0:1:k;
w=1;
syms u
r(w,m)=factorial (k)/(factorial(i)*factorial(k-i))*u.^i*(1-u).^(k-i)
w=w+1
m=m+1
end;
syms u
d=diff (r)
syms u
f= diff(r,2)
for u=1
g1=(r)
end
</pre>fatima saadhttp://www.mathworks.com/matlabcentral/profile/authors/7084409-fatima-saadtag:www.mathworks.com,2005:Question/2477762015-10-10T00:51:40Z2015-10-10T04:28:21Zgraphics in R2015b ...<p>I have Matlab GUI code that runs perfectly under R2014a and since upgrading to R2015b I'm having some teething problems to get it run.</p><p>The problem is in the cursormode oncallback function where a subfunction is suppose give me the xy coordinates and index of the xy coordinates in a window. Since I have two figures open for reason the I use Tag to find the axes object, it cannot see it because it remains locked to the figure (lets call that A) that I'm not working on. There I see no results and there isn't any errors reported either.</p><p>This is the start of the code:</p><pre class="language-matlab">function Andy2Dcursormode_OnCallback(hObject, eventdata, handles)
</pre><pre class="language-matlab">% hObject handle to Andy2Dcursormode (see GCBO)
</pre><pre class="language-matlab">% eventdata reserved - to be defined in a future version of MATLAB
</pre><pre class="language-matlab">% handles structure with handles and user data (see GUIDATA)
dcm_obj = datacursormode;
</pre><pre class="language-matlab">set(dcm_obj,'UpdateFcn',@myfunction,'DisplayStyle','window');
</pre><pre class="language-matlab">%
</pre><pre class="language-matlab">function output_txt = myfunction(obj, event_obj)
</pre><pre class="language-matlab">% Display the position of the data cursor
</pre><pre class="language-matlab">% obj Currently not used (empty)
</pre><pre class="language-matlab">% event_obj Handle to event object
</pre><pre class="language-matlab">pos = event_obj.Position;
</pre><pre class="language-matlab">set(event_obj.Target,'LineStyle','--','LineWidth',2, 'Color',[0.3 0.8 0]); % Make selected line wider and avocado
</pre><pre class="language-matlab">h1 = findobj('Tag','andyplot2D');
</pre><pre class="language-matlab">data = get(h1,'UserData');...
</pre><p>So h1 is never found. On R2014a, there is no such problems and it runs perfectly. Figure A also has the same exact code for cursormode for its plots and that also works well under R2015b. What else do I need to specify under R2015b so that my code can start running like it should?</p>Oliver Chikumbohttp://www.mathworks.com/matlabcentral/profile/authors/214218-oliver-chikumbotag:www.mathworks.com,2005:Question/2477972015-10-10T03:42:35Z2015-10-10T04:21:12ZConnect oscilloscope via LAN, have installed Tekvisa4.0.4, but still "No Visa drivers detected"<p>I'd like to control oscillosope(TDS3054C) by MATLAB(R2010b) via LAN. So I installed Tekvisa4.0.4 as it required (it requires 3.3 version or above). But when I create instrument object, it still shows "no visa drivers detected". Is there any step I missed? like install Teckvisa into specific address or something? But the install address of Tekvisa is default.</p><p>picture Attached.</p><img src = "/matlabcentral/answers/uploaded_files/38223/VISAdriver.jpg"><p>..</p>Yuyao Zhouhttp://www.mathworks.com/matlabcentral/profile/authors/6987052-yuyao-zhoutag:www.mathworks.com,2005:Question/2477982015-10-10T03:44:54Z2015-10-10T04:19:34ZCONNECTOR ERROR Matlab 2015b<p>Dear all,</p><p>Would you please help me to fix this problem.It appeares whenever I want to open simulink tool.</p><pre class="language-matlab">Error using connector.ensureServiceOn
Error starting MATLAB Connector. Please check that port 31515 is available.
</pre><pre class="language-matlab">Error in slmsgviewer
</pre><pre class="language-matlab">Error in slmsgviewer/PersistentInstance
</pre><pre class="language-matlab">Error in slmsgviewer.processRecord
</pre><pre class="language-matlab">Error in openmdl (line 12)
evalin('base', ['open_system(''' strrep(filename, '''','''''') ''');'] );
</pre><pre class="language-matlab">Error in open (line 158)
feval(openAction,fullpath);
</pre><pre class="language-matlab">Error in uiopen (line 167)
open(fn);
</pre><pre class="language-matlab">Error using connector.ensureServiceOn
Error starting MATLAB Connector. Please check that port 31515 is available.
</pre><pre class="language-matlab">Error in slmsgviewer
</pre><pre class="language-matlab">Error in slmsgviewer/PersistentInstance
</pre><pre class="language-matlab">Error in slmsgviewer.processRecord
</pre><pre class="language-matlab">Error in matlabshared.scopes.visual.TimeDomainSLADisplay (line 32)
function this = TimeDomainSLADisplay(varargin)
</pre><pre class="language-matlab">Error in matlabshared.scopes.visual.TimeDomainVisual/deserializeLayoutGrid (line 32)
hDisplay = matlabshared.scopes.visual.TimeDomainSLADisplay(gridContainer, displayInd);
</pre><pre class="language-matlab">Error in matlabshared.scopes.visual.DisplayVisual/setup (line 48)
[this.LayoutGridContainer,this.Displays] = deserializeLayoutGrid(this, ...
</pre><pre class="language-matlab">Error in matlabshared.scopes.visual.TimeDomainVisual/renderWidgets (line 16)
setup(this, getVisualizationParent(hScope));
</pre><pre class="language-matlab">Error in Simulink.scopes.TimeScopeBlockExtensionSystem/renderWidgets (line 126)
renderWidgets(this.TimeDomain);
</pre><pre class="language-matlab">Error in matlabshared.scopes.UnifiedScope/renderWidgets (line 349)
renderWidgets(this.ExtDriver);
</pre><pre class="language-matlab">Error in Simulink.scopes.TimeScopeBlockCfg/launch (line 49)
renderWidgets(hFramework);
</pre><pre class="language-matlab">Error in Simulink.scopes.ScopeBlockSpecification/setVisible (line 130)
launch(this);
</pre><pre class="language-matlab">Error in Simulink.scopes.TimeScopeBlock/open (line 37)
setVisible(hScopeSpec,'on');
</pre><pre class="language-matlab">Error in Simulink.scopes.TimeScopeBlock/load>@()open(this,preShowCallBackExists) (line 37)
callBack = @() open(this, preShowCallBackExists);
</pre><pre class="language-matlab">Error in Simulink.BlockDiagram/addCallback>i_execute (line 47)
fcn();
</pre><pre class="language-matlab">Error in Simulink.BlockDiagram/addCallback (line 39)
i_execute(obj,type,id,fcn);
</pre><pre class="language-matlab">Error in Simulink.scopes.TimeScopeBlock/load (line 38)
mdlObj.addCallback('PreShow',['Scope',num2hex(block)],callBack);
</pre><pre class="language-matlab">Error in openmdl (line 12)
evalin('base', ['open_system(''' strrep(filename, '''','''''') ''');'] );
</pre><pre class="language-matlab">Error in open (line 158)
feval(openAction,fullpath);
</pre><pre class="language-matlab">Error in uiopen (line 167)
open(fn);
</pre>Afraa Alsereidihttp://www.mathworks.com/matlabcentral/profile/authors/6960857-afraa-alsereiditag:www.mathworks.com,2005:Question/2478002015-10-10T03:54:40Z2015-10-10T04:16:29ZMatLab to RaspberryPi connection cannot find "cameraboard" or other cited examples in the support documentation.<pre class="language-matlab">mypi =
</pre><pre> LinuxServices with properties:</pre><pre> HostName: '192.168.1.141'
UserName: 'pi'
Password: 'raspberry'
BuildDir: '/home/pi'</pre><pre class="language-matlab">>> mycam = cameraboard(mypi,'Resolution','1280x720')
Undefined function or variable 'cameraboard'.
</pre><pre class="language-matlab">>> img = snapshot(mycamera)
Undefined function or variable 'mycamera'.
</pre><p>And I am connected to the pi:</p><pre class="language-matlab">>> mypi
</pre><pre class="language-matlab">mypi =
</pre><pre> LinuxServices with properties:</pre><pre> HostName: '192.168.1.141'
UserName: 'pi'
Password: 'raspberry'
BuildDir: '/home/pi'</pre><pre class="language-matlab">>>
>> [status,msg] = mypi.execute('ls -ltr')
</pre><pre class="language-matlab">status =
</pre><pre> 0</pre><pre class="language-matlab">msg =
</pre><pre class="language-matlab">total 14716
drwxrwxr-x 2 pi pi 4096 Jan 27 2015 python_games
drwxr-xr-x 2 pi pi 4096 Feb 4 2015 Desktop
-rw-r--r-- 1 pi pi 2250521 Oct 3 02:59 image1.jpg
-rw-r--r-- 1 pi pi 2695314 Oct 5 01:10 mlpix.jpg
-rw-r--r-- 1 pi pi 2670367 Oct 5 01:12 mlpix1.jpg
-rw-r--r-- 1 pi pi 2557407 Oct 5 01:18 mlpix3.jpg
-rw-r--r-- 1 pi pi 2427223 Oct 7 00:06 test.jpg
-rw-r--r-- 1 pi pi 2422917 Oct 7 00:11 test1.jpg
</pre><p>The examples need to explain where I can look - either in the pi or in a MatLab directory to find out what is missing.</p><p>Please don't answer this question with a question, unless it is about an installed package or needed installed package that I might need to get.</p><p>I have accessed and tried all the examples in the MatLab Support Package for the RaspberryPi related to the camera board.</p><p>I a missing something - either the support package install is broken or something simple - like I don't have a part of the Linux Kernal support that is necessary. I can however, execute "raspistill -o filname.jpg" from MatLab and it works.</p><p>Again - please point me to some real help.</p><p>Thanks your time.</p>Camilla Aristizabalhttp://www.mathworks.com/matlabcentral/profile/authors/6784221-camilla-aristizabaltag:www.mathworks.com,2005:Question/1472612014-08-12T07:08:05Z2015-10-10T03:31:16ZHow to combine multiple nx1 size of matrix into one matrix <p>As topic mentioned, i want to combine a matrix from many nx1 size matrix, i would like to have a script</p><p>Many Thnkas,
Alex</p>NGhttp://www.mathworks.com/matlabcentral/profile/authors/5502860-ngtag:www.mathworks.com,2005:Question/2475982015-10-09T05:18:28Z2015-10-10T03:18:28ZHow to call the element in a unknown 2-dim matrix???^_^<p>This is my first time to use the Matlab. I want to do operations on each element(the index doesn't really matter). However I don't know how to call them if I don't now the size. I should use for or while, and how? （≧∇≦）
Btw, I also want to ensure , will the function return 6666 if I tap "disp(6666)"?
Thanks a lot~
:)</p>Manqiao Wanghttp://www.mathworks.com/matlabcentral/profile/authors/7082376-manqiao-wangtag:www.mathworks.com,2005:Question/2475922015-10-09T04:52:26Z2015-10-10T03:06:55ZWhere's the bug in the following codes?<pre class="language-matlab">fun=@(x,y)100*(y-x^2)^2+(1-x)^2;
x=-10:1:10;
y=-10:1:10;
[z,val]=fminsearch(fun,3,3);
</pre>Shawn Millerhttp://www.mathworks.com/matlabcentral/profile/authors/7030364-shawn-millertag:www.mathworks.com,2005:Question/1032172013-05-25T02:51:00Z2015-10-10T03:01:05ZWhy does daq.createSession('ni'), daq.getVendors and daq.getDevices fail in a deployed application using Data Acquisition Toolbox 3.2 (R2012b)?<p>I have MATLAB code that uses the Data Acquisition Toolbox session based interface to interact with instruments. The code runs fine in MATLAB R2012b.</p><p>Then I deploy this code into a standalone executable using MATLAB Compiler R2012b. When I run the standalone executable (on the same machine connected to the same instruments), I am receiving the following error:</p><pre class="error"> </pre><pre> The vendor 'ni' is not known. Use 'daq.getVendors()' for a list of vendors.</pre><p>It appears that the NI devices are not being detected, and the error message is thrown at any of the following code to obtain the device info:</p><pre class="language-matlab">daq.getVendors
</pre><pre class="language-matlab">daq.getDevices
</pre><pre class="language-matlab">s = daq.createSession('ni');
</pre>MathWorks Support Teamhttp://www.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:www.mathworks.com,2005:Question/2461742015-10-01T06:50:56Z2015-10-10T02:41:15Z[�Warning: Function image has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.]� how i can compromise the error<p>i am trying to interface both simulink and arduino and i am getting an error as, [�Warning: Function image has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.]� can i know how to remove this error.</p>meghanath danthojihttp://www.mathworks.com/matlabcentral/profile/authors/6256383-meghanath-danthojitag:www.mathworks.com,2005:Question/2477722015-10-10T00:24:54Z2015-10-10T02:37:44ZAre image morphological operations invalid for RGB images?<p>Most (if not all) of the morphological operations (e.g. imdilate, imerode, imtophat, imbothat) specify that the input image should be grayscale or binary. However, using an RGB image does not yield an error. Why is this? Is it ill-advised to use these functions with RGB (or other 3D) images?</p>Matt Eicholtzhttp://www.mathworks.com/matlabcentral/profile/authors/3529521-matt-eicholtztag:www.mathworks.com,2005:Question/2477862015-10-10T02:18:22Z2015-10-10T02:31:34ZHow to undo a delete?<p>How do I undo an accidental delete when using the editor for a .m file, or alternatively retrieve the .m file from before the accidental delete?</p>Don Brohaughhttp://www.mathworks.com/matlabcentral/profile/authors/4301563-don-brohaughtag:www.mathworks.com,2005:Question/2477632015-10-09T21:18:47Z2015-10-10T02:27:33Zhow can i Grey matter extraction with these algorithm:Filling the holes& Erosion for volume percentage?<p>in my case in a brain mri image To extract an informative part of grey matter, the fill-hole algorithm is applied first to brain volumes because in some cases WMH are found on gap edges. Then, i want to apply a special algorithm of volume/percentage, in order to eliminate a percentage of the volume external to the brain. please Guide me!</p>mari ahmadhttp://www.mathworks.com/matlabcentral/profile/authors/6966072-mari-ahmadtag:www.mathworks.com,2005:Question/2476852015-10-09T11:02:58Z2015-10-10T02:23:51Zwhy does probplot return negative/larger than 1 values ? <p>Hi,</p><pre class="language-matlab">h=probplot(Y);
</pre><p>is supposed to show the probability distrbution of the values in Y.
so probability cant be negative or larger than 1 but if i check</p><pre class="language-matlab">get(h,'ydata');
</pre><p>it has both negative values and values larger than 1. how is that possible ? perhaps i misunderstood something?</p>Itzik Ben Shabathttp://www.mathworks.com/matlabcentral/profile/authors/2386072-itzik-ben-shabattag:www.mathworks.com,2005:Question/2477652015-10-09T22:36:14Z2015-10-10T02:16:58ZWrite a function to add random noise to an image in matlab<p>How do I create a function to add random noise without using imnoise? I am trying to figure out how to do it without using the built-in matlab functions. I know I have to add a random integer to every pixel...</p><pre class="language-matlab">function output=randomnoise(current_img)
for current_img(n)
current_img(n)=current_img(n)+ randi([-255 255],1)
n=n+1
end
</pre><p>This is what I am coming up with right now, but I don't think my loop is visiting each value. How do I visit each pixel and how do I add random noise to it?</p>Krish Desaihttp://www.mathworks.com/matlabcentral/profile/authors/6522588-krish-desaitag:www.mathworks.com,2005:Question/2477822015-10-10T01:15:20Z2015-10-10T02:03:28ZWhy my program doesn't work?<pre class="language-matlab">names = {'Harry', 'Xavier', 'Sue'};
verbs = {'loves', 'eats'};
nouns = {'baseballs', 'rocks', 'sushi'};
a = names(randi(length(names)));
v = verbs(randi(length(verbs)));
o = nouns(randi(length(nouns)));
fprintf {'%s %s %s \n', a, v, o}
</pre><p>I can't print out the words. I keep getting the error "Error using fprintf. Function is not defined for 'cell' inputs."</p>Isaac Nghttp://www.mathworks.com/matlabcentral/profile/authors/6831233-isaac-ngtag:www.mathworks.com,2005:Question/2477022015-10-09T13:30:04Z2015-10-10T02:00:02Zmatrix of zeros and ones within number of zeros in each rows in-between a limit <p>want to have a 30x40 matrix of zeros and ones; however in each row total number of 'ones' must be within 10 to 20.</p>BISWANATH MAHANTYhttp://www.mathworks.com/matlabcentral/profile/authors/2754175-biswanath-mahantytag:www.mathworks.com,2005:Question/851922013-08-20T19:32:16Z2015-10-10T01:57:55Zhow to detect and count vehicle patterns in a image ?<p>hello everyone,</p><p>i am new to matlab and image processing. I am working on a traffic emulation project in witch i need to detect and count the number of vehicles in an images.
the images are from traffic cameras.. you can find examples of these images on this link:</p><p><a href = "http://www.az511.gov/adot/files/cameras">http://www.az511.gov/adot/files/cameras</a></p><p>i will be thankful if anyone could advise on a robust way to detect and count vehicles in images of this type.</p><p>Regards,</p><p>Salim</p>Salim http://www.mathworks.com/matlabcentral/profile/authors/4492619-salimtag:www.mathworks.com,2005:Question/2477702015-10-09T23:45:43Z2015-10-10T01:30:05Zhelp writing a script that tells the day of the week<p>I need help writing a code that tells me the day of the week as well as the number of the day relative to the year.
Ex: input form month/day/year: xx/xx/xxxx
output should say something like: The date 08/31/2011 is the 243 day of the year and is a wednesday.</p><p>I have tried so many different things from Mathworks with no luck.</p>Francois Ndiayehttp://www.mathworks.com/matlabcentral/profile/authors/6906548-francois-ndiayetag:www.mathworks.com,2005:Question/2477852015-10-10T01:22:32Z2015-10-10T01:23:19ZHow to use callback from GUI?<img src = "/matlabcentral/answers/uploaded_files/38222/Untitled.png"><p>I was trying to jump to the callback without pressing the pushbutton.</p>Ariel Cosephttp://www.mathworks.com/matlabcentral/profile/authors/6296030-ariel-coseptag:www.mathworks.com,2005:Question/2477812015-10-10T01:08:46Z2015-10-10T01:08:46ZHow to detect a case of a square wave?<p>Dear all,</p><p>I have a square wave signal that's obtained from Simulink. By referring to square wave's graph attached, I need to detect if amplitude of the square wave is being "1" for along time. In other word, I want to detect the period a-b, as shown in graph.</p><p>Any idea?</p><p>Thanks in advance.</p><img src = "/matlabcentral/answers/uploaded_files/38221/Terr.png">Joha Alkqhttp://www.mathworks.com/matlabcentral/profile/authors/3939208-joha-alkqtag:www.mathworks.com,2005:Question/2477692015-10-09T23:43:35Z2015-10-10T01:04:19ZHow can I divide the output's each value in the x-axis by 1.16*10^6<pre class="language-matlab">%%
clear
[filename, pathname] = uigetfile('*.raw;*.prc', 'Pick raw or processed data file');
N=str2double(filename(5:6));
</pre><pre> % load processed file
fid = fopen([pathname filename],'r','b');
A= fread(fid,inf,'*single')';
prcdata=reshape(A,N,[])';
plot(prcdata)
end
title(strrep(filename,'_','-'))
fclose(fid);
%% |</pre><p>I also tried the following steps</p><pre class="language-matlab">prcdata=reshape(A,N,[])/(1.16*10^6);
</pre>Annonymous Userhttp://www.mathworks.com/matlabcentral/profile/authors/3242801-annonymous-usertag:www.mathworks.com,2005:Question/2475952015-10-09T05:05:56Z2015-10-10T01:03:01ZHow do I plot 3-dimentional graph of the following function? Can Plot3 function do this?<pre class="language-matlab">fun=@(x,y)100*(y-x^2)^2+(1-x)^2;
</pre>Shawn Millerhttp://www.mathworks.com/matlabcentral/profile/authors/7030364-shawn-millertag:www.mathworks.com,2005:Question/2477542015-10-09T20:00:04Z2015-10-10T00:56:00ZHow to get each iteration to be outputted in a while loop?<p>In the attached document, I cant get each iteration of the taylor series to display until the difference is so close to zero where it stops. There are a series of sections in the equation, but i cant get each one to display. My 'estimate' variable is where the equation lies.</p>Nick Hauflerhttp://www.mathworks.com/matlabcentral/profile/authors/6807497-nick-hauflertag:www.mathworks.com,2005:Question/2477422015-10-09T18:19:07Z2015-10-09T23:55:06ZOut of Memory error<p>MATLAB script gives error "out of memory" for some files only. If it was a script issue all files should display out of memory. however only sometimes it is seen why so ? Script converts wav or raw audio file to data and generates coefficients using DTFT.</p>Priyanka Jantrehttp://www.mathworks.com/matlabcentral/profile/authors/5771876-priyanka-jantretag:www.mathworks.com,2005:Question/2477372015-10-09T17:43:25Z2015-10-09T23:20:22Zimporting an excel table with words<p>I got an excel table with text and numbers. The code below does not allow me to display the text properly in the matlab table. how can i import the file as cell array so words can be read as well?</p><pre class="language-matlab">fileToRead = fullfile('C:\Users\Untitled Spreadsheet.xlsx');
circa1 = xlsread(fileToRead);
</pre>AAhttp://www.mathworks.com/matlabcentral/profile/authors/5703029-aatag:www.mathworks.com,2005:Question/2473022015-10-07T15:28:27Z2015-10-09T23:19:14Zimport data into matlab<p>I have imported data into uitable in gui, but data are large and appear statement: Matlab is not responding.</p><p>Is uitable appropriate for importing large files?</p>Radoslav Vandzurahttp://www.mathworks.com/matlabcentral/profile/authors/7028162-radoslav-vandzuratag:www.mathworks.com,2005:Question/2477682015-10-09T23:10:49Z2015-10-09T23:10:49ZFormal Reference for Least Absolute Residuals (LAR) method in CurveFitting Toolbox<p>Is there a formal reference (a paper, particular book) for the least absolute residual (LAR) method used for robust regression in the CurveFitting toolbox? I checked the documents, but found no proper reference. I am looking for the reference that has detailed mathematical description of LAR and coefficient estimation.</p>Yanghui Kanghttp://www.mathworks.com/matlabcentral/profile/authors/3167291-yanghui-kangtag:www.mathworks.com,2005:Question/2477662015-10-09T22:44:43Z2015-10-09T23:09:24ZHow can I solve each element of an array symbolically?<p>I'm trying to find bifurcation points of a dynamical system.</p><p>I calculate the Jacobian of my system (which I call JJ), substitute in fixed points and find the eigenvalues (which I call L).</p><p>I would like to then solve each element of L, and find the smallest solution. This will give me the bifurcation value.</p><p>The solution may return 0, 1, or many solutions. How can I do this efficiently?</p>Demetri Pananoshttp://www.mathworks.com/matlabcentral/profile/authors/3982003-demetri-pananostag:www.mathworks.com,2005:Question/2477602015-10-09T21:00:17Z2015-10-09T22:55:41ZConverting cell components into strings for moving files <p>I am working on a code that helps me move files that i choose from one directory to another . The code that i have is as follows.</p><pre class="language-matlab">[filename, pathname,filterindex] = uigetfile('*.m', 'Select the Matlab files to move', 'MultiSelect', 'on')
source = strcat(pathname, filename)
destination = uigetdir
opt_choose = inputdlg('What do you want to do:/n 1. Move all files or 2. Move one file',...
'Specify your interest in the function', [1,30])
option = str2num(opt_choose{:});
if option < 1||option >2
%This is to make sure that the input is only 1 or 2.
errordlg('This is not an option. You have only 2 more attempts')
end
if option ==1
movefile(source,destination)
end
</pre><p>The error that i get is as follows :</p><p>Error using movefile
Argument must contain a string.</p><p>Error in move_it (line 13)
movefile(source,destination)</p><p>I believe it is because the files that i am selecting, which are multiple files, are being stored as cell components. When i check for the value of source in the workspace, it is as follows,</p><p>source =
'abcd. m' 'xyzd.m'</p><p>How could i change this to a string so that i could pass it into the if function as a source so that it wont give me an error.</p><p>Any help would be appreciated.</p>Sanwal Yousaf http://www.mathworks.com/matlabcentral/profile/authors/6424037-sanwal-yousaftag:www.mathworks.com,2005:Question/2475282015-10-08T21:12:28Z2015-10-09T22:48:15ZIs it possible to design a Matlab gui, with buttons that appear based on user input?<p>I am trying to design a GUI for a function that multiplies N-matrices, with each matrix containing elements that are defined by several variables unique to that matrix. I would like to prompt the user to input how many matrix elements he/she wishes to multiply, and then populate the GUI with N "Edit Text" fields so the user can input the necessary parameters to define each matrix. The difficulty is, N will be different each time, so N "Edit Text" fields must be created after N is set. Does anybody know how to do this?</p>crengr24http://www.mathworks.com/matlabcentral/profile/authors/7080852-crengr24tag:www.mathworks.com,2005:Question/2477642015-10-09T22:04:46Z2015-10-09T22:39:38Zhow to perform wavelet transform on an image?<p>in my case after3 phase wavelet transform i have an image(image1) like this:just changed the image size</p><p>but in this code: why i can't see the original image with the small size? i mean in 3 phase the image Totally broken!</p><p>this is my code:</p><pre class="language-matlab">clc;
clear;
close all;
img=im2double(imresize(imread('C:\Users\Pars\Desktop\maghaleh.bmp'),[256 256]));
</pre><pre class="language-matlab">wname='haar';
</pre><pre class="language-matlab">[C, S]=wavedec2(img,3,wname);
</pre><pre class="language-matlab">A{3}=appcoef2(C,S,wname,3);
[H{3}, V{3}, D{3}]=detcoef2('all',C,S,3);
A2=[A{3} H{3}; V{3} D{3}];
</pre><pre class="language-matlab">[H{2}, V{2}, D{2}]=detcoef2('all',C,S,2);
A1=[A2 H{2}; V{2} D{2}];
</pre><pre class="language-matlab">[H{1}, V{1}, D{1}]=detcoef2('all',C,S,1);
A0=[A1 H{1};V{1} D{1}];
</pre><pre class="language-matlab">figure;
subplot(1,2,1);
imshow(img);
subplot(1,2,2);
imshow(A0);
size A0;
</pre>mari ahmadhttp://www.mathworks.com/matlabcentral/profile/authors/6966072-mari-ahmadtag:www.mathworks.com,2005:Question/2477482015-10-09T18:56:32Z2015-10-09T22:21:08ZInput a range of numbers with strings as well<p>Here is what I use right now:</p><pre class="language-matlab">m = input('Number? ');
for ind = length(m):-1:1
filename = ['Data#' num2str(m(ind)) '.txt'];
Output Data{ind}= importfile(filename);
end
</pre><p>And this serves my purpose to input a range of numbers like [1:5] or [2,6,3,5]. But now I would like to be able to also use strings in the input along with the range such as [1:3,2R, 4 Word, 10] in order to input these text files: Data#1.txt, Data#2.txt, Data#3.txt, Data#2R.txt, Data#4 Word.txt, and Data#10.txt
I know that cells allow me to have mixed arrays but I cannot figure out away to allow the input of 1:3 to be {1, 2, 3}. Can anyone help me achieve what I am trying to do?</p>Jason R.http://www.mathworks.com/matlabcentral/profile/authors/6683562-jason-rtag:www.mathworks.com,2005:Question/2477142015-10-09T15:15:13Z2015-10-09T22:20:05ZProblem with non-linear fit<p>Hi
I am trying to fit the data and find the constant values. my code is...</p><pre class="language-matlab">[T]=xlsread('Matlab.xlsx','sheet2','C5:C2685')
</pre><pre class="language-matlab">[alpha]=xlsread('Matlab.xlsx','sheet2','I5:I2685')%time
</pre><pre class="language-matlab">[dalpha_dt]=xlsread('Matlab.xlsx','sheet2','J5:J2685')
</pre><pre> F=ones(size(alpha));
F=(1-alpha) </pre><pre> coeff0=[2.17E+22, 5] % initial guess
coeff=nlinfit([T,F],dalpha_dt,@model,coeff0);</pre><pre> A=coeff(:,1)
n=coeff(:,2)</pre><p>Function:</p><pre class="language-matlab">function dhat=model(coef,a)
% par_fit = [a b]
a=coef(1);
b=coef(2);
T=a(:,1);
F=a(:,2);
% predicted model
dhat=a.*exp(208000./(8.3147*(T+273))).*(F^b);
return
</pre><p>I need to find the new coefficient values, but it is showing following error..Please tell me how to resolve this.</p><pre class="language-matlab">Error using nlinfit (line 205)
Error evaluating model function 'model'.
Error in fitting (line 16)
coeff=nlinfit([T,F],dalpha_dt,@model,coeff0);
</pre><pre class="language-matlab">Caused by:
Attempted to access a(:,2); index out of bounds because numel(a)=1.
</pre><p>Thanks</p>R7 DRhttp://www.mathworks.com/matlabcentral/profile/authors/6121957-r7-drtag:www.mathworks.com,2005:Question/2477572015-10-09T20:41:26Z2015-10-09T22:00:52ZHow to get full day data from time sample<p>Hi if I have data like <tt>[1 2 3 4 5]</tt> at time <tt>[1 5 12 15 19]</tt> how can I get for example the data at time 2 or 3 or even 24. I tried to plot a graph but could not get the data out from the graph because the xdata and ydata will be similar to the input points. If you can help I would appreciate it.
Thank you,</p>rabih Alahmadiehhttp://www.mathworks.com/matlabcentral/profile/authors/7086203-rabih-alahmadiehtag:www.mathworks.com,2005:Question/2475542015-10-09T00:03:59Z2015-10-09T21:16:36ZSeeing gray pixels when plotting a binary image (> 1024 x 1024 pixels)<p>I have a few binary images (~ 1400x1500 and larger) and when I plot each of them using imshow it shows me some gray pixels. Well using data cursor the values of these pixels are either 0 or 1. So why do I get such an image? And how can I avoid this? I need to show the real binary image so I can apply further calculations (connecting and breaking structures) on the image manually.
I don't have this problem when plotting smaller portions of the same binary image (but I need the full scale image and will zoom in different parts of the next steps of my image processing).</p><p><b>The problem happens when width and/or length of the image are/is larger than 1024 pixels</b>.</p><p>Sample image of a part of big image (zoomed and saved):</p><img src = "/matlabcentral/answers/uploaded_files/38164/Untitled.jpg"><p>The same part of the image plotted separately (imshow(BW(x1:x2,y1:y2)). This is what I want. Real scales and each pixel on the shown image being representative of the exact same pixel in the actual image; and no gray pixel (just pure white or black).</p><img src = "/matlabcentral/answers/uploaded_files/38165/Untitled2.jpg">Ramin Dastanpourhttp://www.mathworks.com/matlabcentral/profile/authors/4546725-ramin-dastanpourtag:www.mathworks.com,2005:Question/2477612015-10-09T21:02:29Z2015-10-09T21:13:11ZGetting all points which are inside of the convexhull<p>I have an image in 3D. I'd like to get all points which are inside its convexhull, but don't belong to the image. So I'd like to do something like this:</p><pre class="language-matlab">[K, V] = convhull(image);
result= zeros(size(image));
result(K == 1 & granule == 0) = 2;
</pre><p>It doesn't work, because K is of size x (the number of rectangles which create the convex hull) by 3.</p><p>How can I do it properly?</p>user6567http://www.mathworks.com/matlabcentral/profile/authors/6905421-user6567tag:www.mathworks.com,2005:Question/2477622015-10-09T21:02:44Z2015-10-09T21:07:15Zhow to perform skull stripping with 3 stage?1-Object counting after labeling 2-Label storage 3-Skull separation on volume<p>i have a brain labeled image .i want to skull stripping it with 3 stage:1-Object counting
2-Label storage
3-Skull separation on volume(max volum selected and min volum eliminate)
in fact after this work i have 2 lobe of brain</p>mari ahmadhttp://www.mathworks.com/matlabcentral/profile/authors/6966072-mari-ahmadtag:www.mathworks.com,2005:Question/2440712015-09-20T11:13:43Z2015-10-09T20:53:43ZThe build failed with the following message: The system cannot find the path specified. what i should do?<p>i'll building and running a simulink model, but when i deploy to my hardware or run, arduino but keep getting this error message..</p><p>The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: The system cannot find the path specified.</p><p>The build process will terminate as a result.</p><p>The build failed with the following message: The system cannot find the path specified.</p><p>.........</p><p>i try "Troubleshoot Running Models on Arduino Hardware" in documentation but keep getting this message over and over again... what i should do???? please need help..</p>Van Allen Coronahttp://www.mathworks.com/matlabcentral/profile/authors/6937839-van-allen-coronatag:www.mathworks.com,2005:Question/2443502015-09-22T01:10:55Z2015-10-09T20:40:41ZHow to communicate via Arduino's SPI and Simulink?<p>Hi all,</p><p>Question: have you been able to communicate over SPI using an Arduino from Simulink?</p><p>I'm having a lot of trouble trying to get the Arduino Support for Simulink to communicate over SPI. I've downloaded the Support Package for Simulink and the Support Package comes up in the Simulink library, but no SPI blocks. Even though Mathworks' website says that it should be there. In addition, the SPI examples (arduino_SPI_EEPROM) don't work either when called from MATLAB's command window, but other examples do.</p><p>Any help would be appreciated.</p><p>P.S. I'm running MATLAB 2015a if that makes any difference.</p>Frazerhttp://www.mathworks.com/matlabcentral/profile/authors/208144-frazertag:www.mathworks.com,2005:Question/2477562015-10-09T20:24:56Z2015-10-09T20:24:56Zhow could i build a neural fuzzy system with two outputs?<p>I want to build a fuzzy system whose membership function parameters could be tuned using neuro-adaptive learning methods. The system has four inputs and two outputs. I tried neurofuzzydesigner and anfis method. But both of them could only have one output. so does anyone know other ways to build this kind of system?</p>Haishu Mahttp://www.mathworks.com/matlabcentral/profile/authors/5719058-haishu-matag:www.mathworks.com,2005:Question/2477392015-10-09T17:56:23Z2015-10-09T20:22:43ZFixing Error using plot Invalid first data argument - new to matlab<p>I am trying to plot the function y=cos(x)*sin(x^2) and its derivative from -pi to pi. Here is my code. Why do I keep getting errors? At first I tried linespace but that didn't work. What do I do? I am new to matlab.</p><pre class="language-matlab">x=-pi:100:pi;
y=cos(x)*sin(x^2);
dy=2*x*cos(x^2)*(cos(x))-sin(x^2)*sin(x);
clf
hold on
plot(x,y, 'r', 'LineWidth', 3);
xlabel('x');
ylabel('y');
hold on
grid on
plot(x,dy, 'b', 'o--', 'LineWidth', 1);
title(['Graph of y=sin(x^2)cos(x) and y' by Jay Gersten'])
legend('cos(x)*sin(x.^2)','2*x*cos(x.^2)*cos(x)-sin(x.^2)*sin(x)')
dbstop if error
</pre>Jay Gerstenhttp://www.mathworks.com/matlabcentral/profile/authors/6834268-jay-gerstentag:www.mathworks.com,2005:Question/798642013-06-21T17:44:09Z2015-10-09T20:21:06ZArduino - Simulnik serial data speed<p>Hi all,</p><p>I want to read data from incremental encoder using arduino and simulink. I have programmed the external interrupt zero in order to get thew pulses from the encoder and send them to simulink via serial communication. It works but, it's slow, I reduced the time on block sample time in serial receive block but it's still slow. When the motor turns one revolution, simulink is stil receiving data, and after some time I get all values. How can I improve the data communication in order to get a good response in real time?</p><p>PD: I set the baud rate till the maximum value (115200 bauds) but it's still slow.</p>Omar Perezhttp://www.mathworks.com/matlabcentral/profile/authors/3389918-omar-perez