http://www.mathworks.de/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-07-31T17:36:38Ztag:www.mathworks.de,2005:Question/1436292014-07-28T16:07:59Z2014-07-31T17:36:38Zi need change this to MATLAB CODE , its Necessary<p>i need change this to MATLAB CODE , its Necessary</p><img src = "/matlabcentral/answers/uploaded_files/15909/math1.JPG"><p>and</p><img src = "/matlabcentral/answers/uploaded_files/15910/Math.JPG"><p>I is Identity matrix</p>Martin/matlabcentral/answers/contributors/5486421-martintag:www.mathworks.de,2005:Question/1442402014-07-31T15:50:08Z2014-07-31T17:32:54ZHow can i perform lexicographic sorting on a cell ?<p>Hi,</p><p>As a part of may work i first divide an image into number of overlapping blocks and dct for each blocks are calculated.Then from each block 4 features are extracted and they are saved into a cell.Then that cell contains 4 columns and rows equal to number ob blocks.Then i want to perform lexicographic sorting on this feature vector cell,how can i perform that?</p>Aparna/matlabcentral/answers/contributors/5492520-aparnatag:www.mathworks.de,2005:Question/1419472014-07-15T16:09:56Z2014-07-31T17:29:08Zdata extraction with time points from a sensor device<p>I am using a body worn sensor to measure balance in patients, the sensor starts to measure from the time it is turned on. I am measuring a series of tests of 30 seconds intervals with breaks in between for the patients and i am using an android app to record the exact time (time of the day)the respective test has been measured. My question is how can i synchronize and extract the data only from those 30 seconds test measurements with the time i recorded in my android app. please help..</p>Surendar Devan/matlabcentral/answers/contributors/5448793-surendar-devantag:www.mathworks.de,2005:Question/1437692014-07-29T16:58:18Z2014-07-31T17:23:16ZMaximize minimum optimization problem <p>Hello!
I would like to ask for your help concerning the following optimization problem as I am trying to get familiar with such kind of optimization...</p><img src = "/matlabcentral/answers/uploaded_files/15966/opt.png"><p>Can someone help me about how to write down my objective function and the first inequality constraint (in order to include them in the <i>intlinprog</i> solver)? I mainly don't know how to describe the 'ε' as the obective function... The rest of the constraints can be easily formed in matrices.</p><p>Thank you in advance!</p><p>Regards,</p><p>Chris</p>Chris B/matlabcentral/answers/contributors/4829225-chris-btag:www.mathworks.de,2005:Question/1442392014-07-31T15:33:34Z2014-07-31T17:21:39ZScatter plot with only two colors<p>Hallo,</p><p>I am sorry to ask this silly question (I searched a lot, but i could find a way only to plot each values in different colours).</p><p>I would like to make a scatter plot with only two colours, i.e .. one colour represents the values of X-axis and another represents the value of y-axis.</p><p>Thanks in advance.</p><p>Regards,</p><p>Raja</p>eshwar kannan/matlabcentral/answers/contributors/2792053-eshwar-kannantag:www.mathworks.de,2005:Question/1442442014-07-31T16:32:47Z2014-07-31T17:21:02ZAdd new window to OpeningFcn of MATLAB gui goes to back of main window when running<p>I have a 'Main_window' in MATLAB guide. I want open a 'New_window' when I run 'Main_window', So I add this code in 'OpeningFcn' of 'Main_window' :</p><pre class="language-matlab">New_window();
</pre><p>When I run 'Main_window', 'New_window' goes to back of 'Main_window'. I want it in front of 'Main_window' after running.</p><p>What should I do?</p><p>Thanks.</p>Jack/matlabcentral/answers/contributors/5193869-jacktag:www.mathworks.de,2005:Question/1442462014-07-31T16:43:05Z2014-07-31T17:18:00ZHow can i write this in matlab?<p>Hi, I saw a question in this link <a href = "http://www.mathworks.com/matlabcentral/answers/144091-how-can-i-write-this-in-matlab-help-me-plz">http://www.mathworks.com/matlabcentral/answers/144091-how-can-i-write-this-in-matlab-help-me-plz</a> and i don't understand newton's method too. Can you give me a example solution script please?</p>Gökay/matlabcentral/answers/contributors/5492642-gokaytag:www.mathworks.de,2005:Question/1442422014-07-31T16:18:11Z2014-07-31T17:17:47ZHow to calculate sine angle<p>How to calculate two sin waveform's(with harmonics) angle difference? Is there any sentence can do that?</p>Frank/matlabcentral/answers/contributors/5034454-franktag:www.mathworks.de,2005:Question/1442492014-07-31T17:01:34Z2014-07-31T17:17:08ZHow to adapt a pc written program to a mac in matlab<p>I've been trying to run a program to analyze data, however the program was written on a pc and when I tried to run it on my mac and it keeps running into issues and popping up with error codes. Does anyone know how to fix this?</p>Kendall/matlabcentral/answers/contributors/5455726-kendalltag:www.mathworks.de,2005:Question/1441712014-07-31T04:33:24Z2014-07-31T17:14:03ZUsing sound function on Mac? r2014a<p>_</p>Doug/matlabcentral/answers/contributors/5443523-dougtag:www.mathworks.de,2005:Question/1442452014-07-31T16:43:04Z2014-07-31T17:03:05ZPlotting a polynomial problem<p>Trying to plot this polynomial for different values of A but no luck so far.</p><pre class="language-matlab">M=linspace(-10,10,100);
</pre><pre class="language-matlab">g=10;
</pre><pre class="language-matlab">for A=0.1:0.1:0.9
</pre><pre> D=-(A^2-A+1/3)*(((A-1/2)*M*g-0.25*A^2)/(2*M*((A-1/2)^2+1)+0.5*(A^2-A+1/3)))-0.5*A^2</pre><pre> plot(M,D)</pre><pre> hold all</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">legend('A=0.1','A=0.2','A=0.3','A=0.4','A=0.5','A=0.6','A=0.7','A=0.8','A=0.9')
</pre>Josie/matlabcentral/answers/contributors/4878464-josietag:www.mathworks.de,2005:Question/1441702014-07-31T03:53:42Z2014-07-31T17:02:55Zimage processing using Matlab<p>Hi</p><p>I have the following result of segmentation</p><p>How can I improve the results?</p><p>1) I want to improve the appearance to get the vessels more smooth.</p><p>2) I want to extract the oval-like part of the vessels in the middle of the image.</p><p>Any suggestions?</p><img src = "/matlabcentral/answers/uploaded_files/16055/seg_vessel.jpg"><p><b>*****************</b></p><p>Here is a link to the image</p><p>https://copy.com/GT6n8EF82BKw</p>rose rose/matlabcentral/answers/contributors/3612391-rose-rosetag:www.mathworks.de,2005:Question/1442482014-07-31T16:58:01Z2014-07-31T16:58:01ZHow to interpolate R3->R3 (i mean 3D to 3D) function in Matlab? I have found many methods to interpolate function R3->R1 (i mean 3D to 1D), but no possible way to accoplish my task. Except for Thin Plate Splines, they worked fine, but I want somethin<p>How to interpolate R3->R3 (i mean 3D to 3D) function in Matlab? I have found many methods to interpolate function R3->R1 (i mean 3D to 1D), but no possible way to accoplish my task. Except for Thin Plate Splines, they worked fine, but I want something new (if it is possible, Kriging).</p><p>"Vq = interp3(X,Y,Z,V,Xq,Yq,Zq) returns... X, Y, and Z contain the coordinates of the sample points. V contains the corresponding function values (SCALAR) at each sample point. Xq, Yq, and Zq contain the coordinates of the query points." This is just what I have mentioned at the beginning. interp3 operate with function (bijection, correspondence) from space with 3 coordinates (3D, triplet) to space with 1 coordinate (1D, scalar). I want to establish and operate with correspondence from 3D to 3D..</p><p>TPS solves such problems. <a href = "http://www.mathworks.com/matlabcentral/fileexchange/37576-3d-thin-plate-spline-warping-function">http://www.mathworks.com/matlabcentral/fileexchange/37576-3d-thin-plate-spline-warping-function</a> <a href = "http://www.mathworks.com/matlabcentral/fileexchange/22227-thin-plate-splines">http://www.mathworks.com/matlabcentral/fileexchange/22227-thin-plate-splines</a>
I used the first link. The interface is pretty straightforward. I marked: 1. points: old positions of control points; 2. ctrlpoints: new positions of control points; 3. object: source template.</p><p>But I want Kriging now.</p><p>Thank you very much.</p>Anatoliy/matlabcentral/answers/contributors/4838993-anatoliytag:www.mathworks.de,2005:Question/1441112014-07-30T17:12:13Z2014-07-31T16:56:25ZHow to set up a value limit to measure a waveform<p>I got one (sin) waveform which will attenuate and floating. And i want to know, for example, when will the peak to peak(or the whole waveform) magnitude is smaller than 100(or a certain value)?</p>Frank/matlabcentral/answers/contributors/5034454-franktag:www.mathworks.de,2005:Question/1442372014-07-31T15:21:54Z2014-07-31T16:43:27ZShading to indicate a condition on a time series plot<p>I have a long time series, let's say of water level in a stream, shown on a line plot. I would like to shade in periods when a certain condition is true, let's say when it was raining. This shading would appear as light gray vertical blocks for every rainy time period, for example using the fill command. What do I need to add to the code below?</p><pre class="language-matlab">% Make fake time series of water level
t = 0:0.1:10; % Time
w = sin(2*pi*t); % Water level
</pre><pre class="language-matlab">% Make fake logical condition indicating when it's raining
iRain = false(size(t));
iRain([5:10 20 40:42 50 60:75 90:95]) = true; % Periods when it's raining, some very short
</pre><pre class="language-matlab">% Make line plot of water level
plot(t, w);
hold on;
f = fill(??); % Add vertical bars/blocks to indicate periods when iRain is true
</pre>K E/matlabcentral/answers/contributors/1596298-k-etag:www.mathworks.de,2005:Question/984742013-05-01T19:59:00Z2014-07-31T16:39:08ZIs there a command in MATLAB for creating one overall legend when I have a figure with subplots?<p>Is there a command in MATLAB for creating one overall legend when I have a figure with subplots?</p><p>I have a figure with subplots and I would like to create one legend that refers to all of my subplots. Is there a way to do this?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.de,2005:Question/1420402014-07-16T08:15:00Z2014-07-31T16:36:33ZHow to labeling the tip of the head and the end of the tail of this fish image? Like how i did with the center of the fish using centroid.<p>i attach the image for reference if you do not understand. have problem putting a label on the head and tail.</p>Tommy/matlabcentral/answers/contributors/5396873-tommytag:www.mathworks.de,2005:Question/1441372014-07-30T23:22:58Z2014-07-31T16:33:23ZFor loop with moving window<p>Hi</p><p>I want to create a for-loop that calculates the weights of portfolios using a moving window for the period I am investigating. The moving window should move one day at a time and there are 1000 days in the window.</p><p>For example, compute the optimal weights on day1001 based on observations for period 1-1000days. Then you move on to day 1002, and re-calculate the weights, based on observations for period 2-1001days, etc.</p><p>I have a matrix of returns (Rets) that is 3740x6. The first column has the dates and the rest of the columns have daily returns for five different asset classes.</p><p>Thanks!</p>civs/matlabcentral/answers/contributors/5436101-civstag:www.mathworks.de,2005:Question/1442432014-07-31T16:26:35Z2014-07-31T16:26:35Zhow to get weight and bias from nftool <p>weiht and bias for find out the objective function</p>MNNIT/matlabcentral/answers/contributors/3955349-mnnittag:www.mathworks.de,2005:Question/1436662014-07-28T22:53:54Z2014-07-31T16:24:56ZHow i can embed. data in Alpha channel of an image ?<p>How i can embed data in Alpha channel of an image ?
i need a complete code in matlab if it possible
thank u all</p>Nawar Alseelawi/matlabcentral/answers/contributors/5263936-nawar-alseelawitag:www.mathworks.de,2005:Question/627702013-02-08T23:20:13Z2014-07-31T16:24:25Zhow to choose LQR<p>hello everyone
i am trying to use LQR controller
i simulate my system and have my A and B matrix ,, used theme in m-file and use the lqr function to control this system,,,
is there any way to know what is the right value for Q and R ??
i try a lot of values for them
but the results give me 2 positive values and that is wrong, all values must be negative depending on the choice of the Q and R.
so is there any way make me know what is the right values for them instead of try and error ?
please help</p>shahad/matlabcentral/answers/contributors/3945697-shahadtag:www.mathworks.de,2005:Question/1117932014-01-08T17:46:24Z2014-07-31T16:14:14ZHow can I isolate a faint gradient in an image using matlab?<p>I am trying to trace the border of a shockwave in a series of images as it advances in time.</p><p>For reference watch the video below at the 2:30 mark.</p><p><a href = "http://www.military.com/video/ammunition-and-explosives/explosives/shockwave-captured-on-high-speed/763995636001/">http://www.military.com/video/ammunition-and-explosives/explosives/shockwave-captured-on-high-speed/763995636001/</a></p><p>There is a thin almost translucent shock that moves faster than the debris. I have been converting the image to black and white so that I can use edge finding algorithms in matlab, the only trouble that I have is that I can't seem to isolate the shockwave. I have been using the graythresh() function, but it doesn't capture the wave. It captures the more obvious dirt, smoke, and debris instead of the more subtle wave.</p><p>I'm thinking that some sort of analysis of the gradient might be effective. Assuming a relatively static background would it be possible to examine two frames and detect the changes in them to isolate the shockwave?</p><p>I'm relatively new to image processing, so I'm open to any suggestions.</p><p>Thanks,
Chris N.</p><p>Here are two sample images for reference. They are screenshots of the video separated by a few seconds. The motion and location of the wave becomes apparent when comparing two images. Otherwise it is hard to find the shock location. That is why I feel that some sort of comparison between two frames may work.</p><img src = "/matlabcentral/answers/uploaded_files/6591/1.jpg"><img src = "/matlabcentral/answers/uploaded_files/6592/2.jpg">Chris/matlabcentral/answers/contributors/4927677-christag:www.mathworks.de,2005:Question/108322011-07-04T12:48:14Z2014-07-31T16:10:38ZHow can I get the GUI to browse for a specific file?<p>Hi.
I am new to this Matlab GUI and would love your help.</p><p>I have an m-file that runs perfectly but wish to put in into a GUI (using GUIDE) to make it more user-friendly.</p><p>In my m-file, I manually insert the pathname for the directory in which the necessary jpeg images are to be found. How do I execute this in the GUI? How can I get the user to be able to select the path/file in which the GUI can extract and use the JPEGs within the selected file? I think I need some kind of "browse the user's computer directory" function but am not sure how to achieve this? And how do I then put this path into the m-file?</p><p>Any help and advice would be greatly appreciated.</p><p>Sue x</p>Sue/matlabcentral/answers/contributors/2619603-suetag:www.mathworks.de,2005:Question/1441032014-07-30T15:40:59Z2014-07-31T16:02:34Zhow to manage radiobuttons?<p>i have 2 radiobuttons, when i click on radio 1 and i then click on radio 2, radio 1 stays checked and thats not what i want, i want when one of the two radiobuttons are clicked the other should be unchecked immediately
thanks</p>Jihad Chamseddine/matlabcentral/answers/contributors/5435815-jihad-chamseddinetag:www.mathworks.de,2005:Question/1442412013-10-24T04:00:00Z2014-07-31T16:00:21ZWhy do I get Java exception java.lang.NoSuchMethodError: javax.media.opengl.GLCapabilities when using CFTOOL in the Curve Fitting Toolbox 3.4 (R2013b)?<p>I'm trying to use cftool to fit a simple data set with a line. The App finds a fit but the plot window in the App is empty. Also, I get these error messages in my MATLAB command window:</p><pre> Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: javax.media.opengl.GLCapabilities.<init>(Ljavax/media/opengl/GLProfile;)V
at com.mathworks.hg.peer.JavaSceneServerPeer.getCaps(JavaSceneServerPeer.java:125)
at com.mathworks.hg.peer.JavaSceneServerPeer.doCreateCanvas(JavaSceneServerPeer.java:915)
at com.mathworks.hg.peer.JavaSceneServerPeer.access$200(JavaSceneServerPeer.java:44)
at com.mathworks.hg.peer.JavaSceneServerPeer$2.run(JavaSceneServerPeer.java:887)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)</pre>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.de,2005:Question/1442192014-07-31T12:59:01Z2014-07-31T15:55:09ZLookup values in a 6-D matrix using indices from columns of another matrix. <p>Trying to look for values in the v_tbl based on index provided by each column of quant_sysplus.</p><p>Problem: Runs too slow because I'm using two For loops. Is there a faster way of accessing the values?</p><p>v_tbl is a 6-D array that contains values of interest.
quant_sysplus is 3-D (1:6,1000,3) array with each column containing a set of indices (1:6) to a value in v_tbl.</p><p>The following is what I have so far and it works, but there are a lot of states (121x121x24x7x7x3) that I have to step through. The two For Loops makes it extremely slow when I have 3000 sets of indices to lookup in each state.</p><pre class="language-matlab">for ind_page=1:page %page=3
for ind_col=1:Np %Np=1000 lookup(1,ind_col,ind_page)=v_tbl(quant_sysplus(1,ind_col,ind_page),quant_sysplus(2,ind_col,ind_page),quant_sysplus(3,ind_col,ind_page),quant_sysplus(4,ind_col,ind_page),quant_sysplus(5,ind_col,ind_page),quant_sysplus(6,ind_col,ind_page)); % Returns the values for each sample
end
end
</pre><p>I've tried Parfor as well, but was slower probably because the comm overhead was high.</p><p>Any suggestions?? Thank you.</p><p>David</p>David Hung/matlabcentral/answers/contributors/5492165-david-hungtag:www.mathworks.de,2005:Question/1442002014-07-31T10:32:59Z2014-07-31T15:54:51ZDirectivity did not match our expectation<p>As we know, 1X16 linear antenna array arrangement should have larger peak directive gain than 4X4 square array, because the former's beamwidth is narrower which can consentrate beamforming resolution in a given direction.</p><p>However, in the phased array system toolbox, this truth cannot be proven... Here is our code,</p><pre class="language-matlab">if true
% code
figure
ha = phased.ULA('NumElements',16);
phased.ULA('Element',ha,'NumElements',16,'ElementSpacing',0.5 * lambda);
plotResponse(sArray,'RespCut','Az','Format','Polar','Unit','dbi');
hold on;
ha = phased.URA('Size',[4 4]);
phased.URA('Element',ha,'Size',[4 4],'ElementSpacing',0.5 * lambda);
plotResponse(sArray,'RespCut','Az','Format','Polar','Unit','dbi');
hold off;
end
</pre><p>if we find the peak values for 1X16 and 4X4 in the figure, 4X4 always has the higher gain value...</p><p>Thanks, Ralph</p>Ralph/matlabcentral/answers/contributors/5356168-ralphtag:www.mathworks.de,2005:Question/1441192014-07-30T20:09:51Z2014-07-31T15:46:38ZTurn off final Hessian calculation with fminunc or fmincon?<p>I'm using these functions to minimize a problem, with the default algorithm choice for no user-supplied Hessian. For these algorithms, fminunc/fmincon calculate the numerical Hessian at the solution (for other algorithms, it reports the next-to-last-iterate Hessian).</p><p>I would like to turn off the calculation of this final Hessian shorten runtime. It is not useful at this particular point in the code. Is it possible to do this?</p>Christopher/matlabcentral/answers/contributors/3440394-christophertag:www.mathworks.de,2005:Question/1442312014-07-31T14:40:13Z2014-07-31T15:45:16Zmap from value to colormap<p>I use pcolor to create a figure out of some matrix of data.</p><p>h=pcolor(X,Y,M);</p><p>Is it possible to receive for a specific index in the matrix in which color (RGB values) pcolor used (assuming a constant colormap)?</p><p>Or should i ask it - If I have a colormap and caxis - is there any function that will give me the color of a value (mapping from value to rgb value in the colormap)?</p><p>Thanks</p>Guy Eyal/matlabcentral/answers/contributors/2434449-guy-eyaltag:www.mathworks.de,2005:Question/1042402013-10-29T10:57:45Z2014-07-31T15:35:56ZHow to identify bad data in measurement set in power system?<p>Matlab code for identifying and elimination bad data from measurement set in power system state estimation</p>jyoti/matlabcentral/answers/contributors/4736948-jyotitag:www.mathworks.de,2005:Question/1442382014-07-31T15:32:41Z2014-07-31T15:32:41ZMatlab Equivalent to Labview Burst Export Mode<p>Hi,</p><p>I'm trying to work with Matlab's Data Aq. Toolbox using an Ni DIO-32HS card. The DIO-32HS will read in data on the rising edge of the clock (low –> high state). So the Active state should be set to HIGH and the idle state should be set LOW. I don't see any mention of clock polarity in the addClockConnection function. Also, in Labview the Burst Mode (Export Clock) means that the DIO-32HS will export the clock and the acquisition occurs on a logic level, not edge, basis.
The Pause When High tells the DIO-32HS that it won’t read in a scan if there’s no data to be read. Does matlab have an equivalent to Burst Export mode?</p><p>Is there such a way to implement this in matlab?</p><p>Thanks,</p><p>Charles</p>Senaasa/matlabcentral/answers/contributors/4211999-senaasatag:www.mathworks.de,2005:Question/1441992014-07-31T10:30:49Z2014-07-31T15:26:34ZHelp correcting my stochastic predator prey code so it will run<p>I am trying to write a stochastic function for the predator prey model from my differential model, following my textbook however I am unsure if the code below, both the function and the code to run this is correct (I get an error when I run this but not sure how to fix this). Not sure where to tweak the code and if I need to plot three lines or simply two?</p><p><b>Function</b></p><p>function [times,states]=simulate_lotkavolterra(t_final, B, F)</p><p>c1 =1; %initail rates</p><p>c2 =0.2;</p><p>c3 = 0.5;</p><p>B = 10; F =2; %initial population of rabbits (B) and foxes (F)</p><p>t =0;</p><p>states =[B, F];</p><p>times =[0];</p><p>rates =zeros(3,1) % vector for reaction rates</p><p>A = [1 0;</p><p>-1 1;</p><pre> 0 -1];</pre><p>while t <= t_final;</p><p>rates(1) = c1*B;</p><p>rates(2) = c2*B*F;</p><pre class="language-matlab">rates(3) = c3*F;
</pre><p>rate = sum(rates); % rate of leaving the state</p><p>tau = exprnd(1 / rate); % sojourn time</p><p>t = t + tau; % update time</p><p>if (rate == 0 t > t_final)</p><p>t = t_final;</p><p>states = [states; B, F];</p><p>times = [times, t];</p><p>break;</p><p>end</p><p>% vector that contains the reaction probabilities:</p><p>prob = rates / rate;</p><p>index = sample_categorical(prob);</p><p>B = B + A(index, 1); % update state</p><p>F = F + A(index, 2); % update state</p><p>states = [states; B, F];</p><p>times = [times, t];
end</p><p><b>Code to run the function</b></p><p>t_final = 60;</p><p>%%datapoints = 100; %different step sizes, allows for equally spaced data points</p><p>trajectories = 1;</p><p>sums = zeros(datapoints, 3);</p><p>for i = 1:trajectories</p><p>[t_traj, N_traj] = simulate_lotkavolterra(t_final);</p><p>[t, N] = time_series(t_traj, N_traj, data points);</p><p>sums = sums + N; %sums is zero originally, see line 5
end</p><p>averages = sums / trajectories; % scalar multiplication</p><p>plot(t, averages(:,1), '-og'); hold on</p><p>plot(t, averages(:,2), '-ob');</p><p>plot(t, averages(:,3), '-oc');</p>Sarah Macdonald/matlabcentral/answers/contributors/4638871-sarah-macdonaldtag:www.mathworks.de,2005:Question/1442362014-07-31T15:21:32Z2014-07-31T15:21:32ZCurve fitting with a custom function<p>Hey guys,
I am trying to do curve fitting in MATLAB with a custom function that I created with a script file. What I am precisely trying to do is to determine the term d from the following expression:
C1=1+ 4/π ∑_(n=1)^1000▒〖〖(-1)〗^n/((2n-1)) cos[(n-1/2)π((-1)/2)×e^[-〖(n-1/2)〗^2×π^2×d/4 t] ] 〗.
So basically, I have the values that correspond to C1, the time points and I am trying to determine d; As you can see I have a summation and an exponent term.
The script I wrote in Matlab is the following one:
function C1=Conc(t,D)
C1=zeros(1,16);%make a table in order to save C1 values for each one of the time points
C0=0;%Initiation of the summation term
z=2;%Contact interface cartilage-bath
h=2;%Cartilage height
%D is the diffusion coefficient that we are looking for
%t corresponds to the different time points
for j=1:16
for i=1:1000
C=((-1)^i)/(2*i-1)*(cos((i-0.5)*pi*(-0.5)))*(exp(-((i-0.5)^2)*pi^2)*(D/4)*t);
C=C0+C;
end
C1(j)=1+((4/pi)*C);
end
I defined two loops; the first one for the 16 different time points that I have and the other one for the summation term.
I am getting a mistake concerning the dimensions of the arrays that I am using.
Could you please give me some feedback with respect to the validity of the script that I am writing in order to fit the specific equation?
Thanks in advance,
Asimina</p>Asimina Glynou/matlabcentral/answers/contributors/5458503-asimina-glynoutag:www.mathworks.de,2005:Question/1440732014-07-30T12:50:20Z2014-07-31T15:20:39ZFind limits of known integral<p>Dear all,</p><p>I would like to find the limits ( -a and +a) of a known integral.That means the integral is known (e.g. I=45) but the limits -a and +a are unkown. How can I find these limits?</p><p>This my example:</p><p>.......</p><p>.......</p><p>.......</p><p>xx=linspace(x(1);</p><p>x(end),8000);</p><p>pp=spline(x,y);</p><p>yy=ppval(pp,xx);</p><p>%%integral over [-a,+a] is known</p><p>I=quad(@ppval,-a,+a,[],[],pp)</p><p>.....</p><p>.....</p><p>....</p><p>Your help is highly welcome and aprreciated</p><p>Cheers</p>Adam/matlabcentral/answers/contributors/2220267-adamtag:www.mathworks.de,2005:Question/1442332014-07-31T14:57:13Z2014-07-31T15:05:04ZCan canyone tell me to use fminunc for determining the minimum value of coefficient in polynomial?<p>I have a polynomial:</p><p>P(z) = a0 + (-0.5+a0)*z^2 + z^3 + (-0.5+a0)*z^4 + a0 * z^6</p><p>I need to determine the minimum value of a0 (not z) using fminunc. Plz. describe me as I'm not getting it from the MATLAB help section.</p>Soubhagya/matlabcentral/answers/contributors/1454750-soubhagyatag:www.mathworks.de,2005:Question/1442342014-07-31T15:02:30Z2014-07-31T15:02:30Zorientation of imported models<p>I have a model of a bearing that was exported from Creo. When I open it in Simulink it's flat surfaces are aligned with the y-z plane and it's axis of rotation is about the x-axis. What is the best way to reorient the whole assembly so that the bearing sits on the x-y plane and rotates about the z-axis?</p>Edward/matlabcentral/answers/contributors/5300727-edwardtag:www.mathworks.de,2005:Question/1016312013-02-27T16:39:00Z2014-07-31T14:58:48ZWhy do I receive an error (error code: 0x800A03EC) when using XLSWRITE in MATLAB?<p>When I use XLSWRITE I get the following error:</p><pre class="error"> ??? Error using ==> xlswrite
Error: Object returned error code: 0x800A03EC</pre>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.de,2005:Question/1442292014-07-31T14:30:49Z2014-07-31T14:55:51ZIndex exceeds matrix dimensions when saving the data?<p>I have tried to save matlab arrays in a file data_tables.mat as follows:
save('data_tables','N1amprighthp','P2amprighthp','N1latrighthp','P2latrighthp','MEGchannels','subjects');</p><p>but get an error:
??? Index exceeds matrix dimensions.</p><p>Could you please let me know what I am doing wrong?</p><p>Thanks,
Maria</p>Maria/matlabcentral/answers/contributors/2960701-mariatag:www.mathworks.de,2005:Question/1437082014-07-29T09:50:08Z2014-07-31T14:45:55ZSort Stocks into Portfolios based on their return<p>Hallo everybody,</p><p>I have a question regarding a code i am currently working on.</p><p>I have a matrix containing stock returns for a universe of stocks for different days.
Now, i would like to sort the stocks depending on their return on the first day into ten different portfolios.</p><p>Currently i am using those functions:</p><pre> announcement_returns_quantiles = quantile(announcement_returns_vol_sig_adj, 0.1:0.1:0.9, 2);</pre><pre> [~,idx] = histc(announcement_returns_vol_sig_adj(a, :).',[-inf ... announcement_returns_quantiles(a,:) inf]);</pre><pre> nonNaN = idx ~= 0;</pre><pre> return_ew(r,:) = accumarray(idx(nonNaN), stock_returns(r, nonNaN), [], @nanmean);</pre><p>I obtained this code from the following post: <a href = "http://www.mathworks.com/matlabcentral/answers/3094-sort-stocks-into-portolios-based-on-stock-characteristics">http://www.mathworks.com/matlabcentral/answers/3094-sort-stocks-into-portolios-based-on-stock-characteristics</a></p><p>However, as i have several stocks with a return of zero on this day, the result of the quantile-function sometimes looks like this with more than one boarder equal to zero.
(-0.045 -0.034 -0.03 -0.01 0 0 0.01 0.023 0.03).</p><p>If I now use the histc command the resulting portfolios are unbalanced as one portfolio contains all the stocks with a return equal to zero and the other portfolio which also has 0 as its quantile boarder does not contain any stocks at all.</p><p>Does anyone know a solution to this problem ?</p><p>Thanks in advance,
Maximilain</p>Maximilian/matlabcentral/answers/contributors/5387227-maximiliantag:www.mathworks.de,2005:Question/1442322014-07-31T14:45:47Z2014-07-31T14:48:42ZContext menu rotate3d works once !<p>Hello,</p><p>I'm working with MatlabR2012b and uicontrols.</p><p>I'm trying to activate a contextual menu into an axe to</p><ul><li>swap between rotate3d / zoom / save picture</li><li>Axe is into a figure (that will contain uicontrols).</li></ul><p>- For FUNCTION (here: ctx_save) and ZOOM : everything is correct</p><p>- For ROTATE3D : it works only ONCE !!!</p><p>(code is below)</p><p><b>Scenario :</b>
run my function context_menu_rotate_zoom</p><p>(other function ctx_save, ctx_rotate, ctx_zoom will be in seperate files)</p><ul><li>right button into the fig : context menu appears (Rotation/zoom/save)</li><li>right button into the axe : context menu appears (Rotation/zoom/save)</li><li>right button on the surface : nothing but it's ok as hittest is on</li></ul><p>== 1/ right button and select context menu zoom : (pop up window+zoom on) : it's OK</p><p>You can zoom using left button</p><p>You can click on right button context menu to zoom and save several times.. it's OK</p><p>right button into the figure : Nothing !</p><p><b>QUESTION 1</b> >> Does "ZOOM ON" desactivate context menu for parent ?</p><p>== 2.1/ right button and select in context menu ROTATION: (pop up window+rotate on) : it's OK
you can rotate the picture</p><p>== 2.2/ right button and select a second time on context menu ROTATION: (pop up window+rotate on) : it's OK</p><p>== 2.3/ right button... The rotate3d context menu appears with :reset to original view/Goto X-Z...</p><p><b>QUESTION 2</b> >> How can I overwrite Context menu for ROTATE3D the same way it works for ZOOM ?</p><p>Thank you for your help !
Alain</p><p>==============================================================</p><pre> % -------------------------------
function context_menu_rotate_zoom
% -------------------------------
% Creation of axe into figure</pre><pre> myfig=figure('MenuBar','None');</pre><pre> myaxe = axes;</pre><pre> % Plot something
axes(myaxe);
axis vis3d;
[X,Y] = meshgrid(-5:0.1:5,-5:0.1:5);
pp=plot3(X,Y,X.*X+Y.*Y);</pre><pre> % creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(myaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(myaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(myaxe,'%.16f'),');');
%
% Creation of context menu for the fig
cmenu_fig = uicontextmenu;
uimenu(cmenu_fig,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_fig,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_fig,'label','Save','Callback',var_Save);
set(myfig,'uicontextmenu',cmenu_fig);</pre><pre> % Creation of context menu for the axe...
cmenu_axe = uicontextmenu;
uimenu(cmenu_axe,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_axe,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_axe,'label','Save','Callback',var_Save);
set(myaxe,'uicontextmenu',cmenu_axe);
end</pre><pre> % ----------------------------
function ctx_Zoom(monaxe)
% ----------------------------
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(monaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(monaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(monaxe,'%.16f'),');');</pre><pre> % Creation contextuel menu for zoom
cmenu_zoom = uicontextmenu;
uimenu(cmenu_zoom,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_zoom,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_zoom,'label','Save','Callback',var_Save);
%set(monaxe,'uicontextmenu',cmenu);</pre><pre> % overwrite context menu for zoom
hZoom = zoom;
zoom('off') % cannot change context if zoom on !
set(hZoom,'UIContextMenu',cmenu_zoom);
zoom('on')</pre><pre> msgbox('Context menu in Zoom');
end</pre><pre> % ----------------------------
function ctx_Rotation(monaxe)
% ----------------------------
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(monaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(monaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(monaxe,'%.16f'),');');</pre><pre> % Creation of contextuel menu
cmenu_rot = uicontextmenu;
uimenu(cmenu_rot,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_rot,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_rot,'label','Save','Callback',var_Save);</pre><pre> % overwrite context menu for rotate3d
hrotate = rotate3d;
rotate3d('off')
set(hrotate,'UIContextMenu',cmenu_rot);
rotate3d('on')
msgbox('Context menu in Rotation');
end</pre><pre> % ----------------------------
function ctx_Save(monaxe)
% ----------------------------
% creation of callback
var_Rotation = strcat('ctx_Rotation(',num2str(monaxe,'%.16f'),');');
var_Zoom = strcat('ctx_Zoom(',num2str(monaxe,'%.16f'),');');
var_Save = strcat('ctx_Save(',num2str(monaxe,'%.16f'),');');</pre><pre> % Creation contextuel menu for axe
cmenu_axe = uicontextmenu;
uimenu(cmenu_axe,'label','Rotation','Callback',var_Rotation);
uimenu(cmenu_axe,'label','Zoom','Callback',var_Zoom);
uimenu(cmenu_axe,'label','Save','Callback',var_Save);</pre><pre> set(monaxe,'uicontextmenu',cmenu_axe);</pre><pre> msgbox('Context menu in save the image');
end
end</pre>Alain/matlabcentral/answers/contributors/1590762-alaintag:www.mathworks.de,2005:Question/1441012014-07-30T15:36:44Z2014-07-31T14:40:23ZFace recognition using IP, computer vision toolbox, NN toolbox and statistics toolbox<p>Hi,
I wanted to know how i can make use of IP, computer vision, NN and statistics toolboxes to develop a face recognition system. Can anyone help me with this. I came across few methods for face recognition, but since i've the above mentioned toolboxes, i want to know how to use all of them for my project.</p>Namratha/matlabcentral/answers/contributors/3522719-namrathatag:www.mathworks.de,2005:Question/1425282014-07-19T10:30:15Z2014-07-31T14:39:20ZHow to mark 95% confidence interval with single bar line - example image<p>Hello</p><p>I'm using the pwelch method of power spectral density estimate, and would like to indicate the confidence interval like as one single bar - just like in the example image attached. At the moment I just plot the pxxc confidence interval array obtained when calling it in the pwelch function, and its looks very confusing (a lot of noise!). Would much prefer to have something like in the image shown...</p><p>Thanks!</p>Harry/matlabcentral/answers/contributors/5446139-harrytag:www.mathworks.de,2005:Question/1441362014-07-30T23:01:30Z2014-07-31T14:37:26ZHow to I get this Kalman filter to work for my data?<p>The cj.csv works, but the EvanRocketDrop_final.csv does not... Don't know if this is against any forum rules, but I can give $20 via Paypal to anyone who figures this out. We're kind of running low on time, and it's not a huge priority, but it would be very very nice to have for our project. It's important to know that the .csv files that the Kalmanfilter.m works with are sampled at 1000 Hz while ours is about 160 Hz.</p>Thomas/matlabcentral/answers/contributors/4721191-thomastag:www.mathworks.de,2005:Question/1442282014-07-31T04:00:00Z2014-07-31T14:27:39ZTEST WILLBE DELETED<p>Test</p><img src = "https://mathworks--c.na15.content.force.com/servlet/rtaImage?eid=ka0i0000000Xzbv&feoid=00Ni00000072prq&refid=0EMi000000014ww">MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.de,2005:Question/1433652014-07-25T18:04:38Z2014-07-31T14:21:55ZCompiling Code Dependent on External Files<p>The script I am trying to compile modifies existing external files (i.e. Excel files). When I compile the script and add the external files to "Files required for your application to run," how are these files stored in the compiled program? The reason I am asking is that these external files reference each other based on location, so the script wouldn't work if their relative locations change in the compilation.</p><p>The obvious alternative is to distribute the compiled script and the external files as separate attachments, and then use uigetfile to have the user retrieve them manually, but this is less convenient.</p>Kevin/matlabcentral/answers/contributors/3741898-kevintag:www.mathworks.de,2005:Question/1442162014-07-31T12:49:36Z2014-07-31T14:19:44Zhow can i cut data from a plot?<p>hello, goodmorning folks</p><p>how can i cut a data clicking on a plotted data? i want to cut the data from where i click untill the end</p><p>anyone has this code?</p><p>thx :)</p>lucas/matlabcentral/answers/contributors/4721057-lucastag:www.mathworks.de,2005:Question/1442272014-07-31T14:18:56Z2014-07-31T14:18:56ZHow can I sum two periods of time in Simulink?<p>I want to calculate the sum of two periods in simulink. The picture explains better what is really my objective. The periods can be of the same time. So what I would like is just break the simulation time into two different sums. Is this possible?</p>Angelos Kampanakis/matlabcentral/answers/contributors/4956791-angelos-kampanakistag:www.mathworks.de,2005:Question/1442262014-07-31T14:17:58Z2014-07-31T14:17:58ZCan Matlab 2011b dsolve command solve the 4th order beam deflection equation?<p>I am looking for some help using dsolve to come up with a solution to the attached equation.</p><p>The newer versions of symbolic toolbox can use the diff() command within dsolve. What I'd like to do is something like this but in the syntax used in 2011b:</p><p>u1(x)=dsolve(diff(diff(bending_stiffness,2),2)=w)</p><p>Could somebody please help me out with the syntax I need?</p>Seth/matlabcentral/answers/contributors/3638154-sethtag:www.mathworks.de,2005:Question/1442252014-07-31T14:16:11Z2014-07-31T14:16:24Zcalculations from power spectrum density<p>Hello,</p><p>I want to get some more information from the PSD plot that was obtained using periodogram as illustrated here <a href = "http://www.mathworks.se/matlabcentral/answers/143654-need-an-example-for-calculating-power-spectrum-density">PSD implementation</a></p><p>Can I know how to get the below after calculating periodogram like this[Pxx,F] = periodogram(bps,[],numel(bps),1);</p><p>1) Using this <i>Freq= bandpower(Pxx,F,[0 0.04],'psd')</i> gives the units in sec^2.But how to get the units in msec^2
2)How to get the frequency corresponding to maximum power in a each particular band(for example how to get the peak freq in the VLF band of 0 to 0.04Hz)</p><p>Thanks.</p>Stefan/matlabcentral/answers/contributors/4846169-stefantag:www.mathworks.de,2005:Question/1442242014-07-31T14:15:33Z2014-07-31T14:15:33ZMemory block alternative that ISN'T fixed in minor time step?<p>I have a model with some inputs that are fed into a CMEX S-Function via the Memory block, and the S-Function provides outputs based on these inputs, and those inputs are fed back into the S-Function. Classic algebraic loop scenario. I was using a memory block to prevent this because our solver is usually variable-time step</p><p>According to the Mathworks documentation the Memory Block, and the Unit Delay block also, are fixed in minor time step in terms of their outputs. I realize that the inputs can be either discrete or continuous, but the output will only be continuous in the major time step, and fixed in the minor one.</p><p>Now, for various reasons, it is important to us that everything in the model get updated in the minor and major time steps. I came up with a way of using the PWork vector to store the previous value of state points and forward them to the CMEX S-Function that we use. This prevents algebraic loops from occuring and also ensures continuous in minor time step, but is not as elegant as I would like.</p><p>Does anyone have any alternative suggestions?</p><p><i>PS: As an aside, I believe that it is better to use the Memory block regardless of if my solver is Fixed Step or Variable Step, because it will internally just become a Unit Delay block for Fixed Step solvers. Is this assumption correct?</i></p>Viren/matlabcentral/answers/contributors/4590495-viren