http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-09-05T05:30:04Ztag:www.mathworks.com,2005:Question/2399022015-09-05T05:30:04Z2015-09-05T05:30:04ZHow can I solve three non-linear equations having 3 unknowns in MATLAB?<p>My non-linear equations are---
cos(a)-cos(b)+cos(c)=-27.27
cos(5a)-cos(5b)+cos(5c)=0.5
cos(7a)-cos(7b)+cos(7c)=0.5</p>Rishikesh Datarhttp://www.mathworks.com/matlabcentral/profile/authors/6878125-rishikesh-datartag:www.mathworks.com,2005:Question/2399012015-09-05T04:57:04Z2015-09-05T04:57:04ZHow to determine if the simulated result is matched?<p>Here is my code:
inputData = rand(5, 56);
targetData = eye(56);
simInput = [a;b;c;d;e]; %%assume the value match 1 of the column in inputData
net = feedforwardnet(5);
net = train(net, inputData, targetData);
y1 = sim(net, simInput);
y2 = find(max(y1));</p><p>y2 should return a value that tell me which column it matched in inputData. However it only return 1 regardless the simInput. So am I using it right?</p>Vishnu Rajenhttp://www.mathworks.com/matlabcentral/profile/authors/6838295-vishnu-rajentag:www.mathworks.com,2005:Question/2398942015-09-05T03:39:22Z2015-09-05T03:57:01Zthe image or output is not displaying ? if i remove function line it showing error like if max(max(R)) > 1.0 || max(max(G)) > 1.0 || max(max(B)) > 1.0<pre class="language-matlab">rgb = imread('street2.jpg'); %it is one of the MATLAB examples
[L, a, b] = RGB2Lab(rgb);
</pre><pre class="language-matlab">%the rest is for presentation, not part of how you use the routine
figure(1);
imagesc(L);
colormap(gray(256));
colorbar();
title('L plane');
figure(2);
imagesc(a);
colormap(gray(256));
colorbar();
title('a plane');
figure(3);
imagesc(b);
colormap(gray(256));
colorbar();
title('b plane');
</pre>venmal devihttp://www.mathworks.com/matlabcentral/profile/authors/6859304-venmal-devitag:www.mathworks.com,2005:Question/2398682015-09-05T02:22:59Z2015-09-05T03:44:42Zcan anyone please help me by saying how exactly can i convert my matlab code to a c code that could be dump into my processor which supports only c.please kindly help<p>when I generate I get multiple files like initialise.c terminate.c and many more. what exactly should I do to compile my file in c</p>vamsi dattadahttp://www.mathworks.com/matlabcentral/profile/authors/6045507-vamsi-dattadatag:www.mathworks.com,2005:Question/2362062015-08-25T08:57:24Z2015-09-05T03:40:26ZConvert Matlab script in C++ ?<p>Hello,</p><p>I have a Matlab script that I would like to convert in C++, is it possible to do that with Matlab Coder ? Because, when I add my script as an Entry-Point File, I get this message: "All Entry_Point Files must be functions".</p><p>Can Matlab Compiler do the conversion from the script to C++ ?</p><p>Thank you in advance for your answer.</p><p>Fanta C.</p>Fanta Camarahttp://www.mathworks.com/matlabcentral/profile/authors/6812316-fanta-camaratag:www.mathworks.com,2005:Question/2395732015-09-04T03:05:05Z2015-09-05T02:30:36ZNothing but errors when writing a function to perform an integration and a driver script that calls the function and prints the results.<p>I am trying to do an integration by using a function and a driver script that calls it.</p><p><b>func_integrate_viscdisc;</b></p><pre class="language-matlab">function sum = func_integrate_viscdisc(n, mu, h, omega, rmin, rmax)
sum = 0;
rlen = rmax - rmin;
dr = rlen/n;
for idx = 1:n;
r = rmin + dr*(idx - 0.5);
ig =
sum + sum +dr*ig;
end
end
</pre><p><b>driver_integrate_viscdisc.m</b></p><pre class="language-matlab">mu = 5.0E-3;
h = 2.0E-3;
omega = 100/60*2*pi;
rmin = 0.0;
rmax = 0.2;
for n = [10 100 1000];
moment = func_integrate_viscdisc(n, mu, h, omega, rmin, rmax);
fprintf('The moment computed with %4d steps is: %11.4e Nm\n', n, moment);
end
</pre><p>When I run it I get the error;</p><pre class="language-matlab">>> driver_integrate_viscdisc
Error: File: func_integrate_viscdisc.m Line: 7 Column: 10
Expression or statement is incomplete or incorrect.
</pre><pre class="language-matlab">Error in driver_integrate_viscdisc (line 8)
moment = func_integrate_viscdisc(n, mu, h, omega, rmin, rmax);
</pre><p>This code was copied directly from instructions provided by my professor so I have no idea what could be wrong with it.</p>Raxius Bloomhttp://www.mathworks.com/matlabcentral/profile/authors/6871962-raxius-bloomtag:www.mathworks.com,2005:Question/2398642015-09-05T02:01:58Z2015-09-05T02:25:15ZIs Bluetooth Low Energy (BLE) supported in Instrument Control Toolbox? How to read broadcasts without connections?<p>Is Bluetooth Low Energy (BLE) supported in Instrument Control Toolbox?</p><p>I'm trying to use Instrument Control Toolbox>Direct Interface Communication>Bluetooth Communication to collect data from BLE sensors to do some analysis. Would it work with BLE sensors?</p><p>The examples in help require a connection. How to read broadcasts without establishing a connection?</p>Minghttp://www.mathworks.com/matlabcentral/profile/authors/5826198-mingtag:www.mathworks.com,2005:Question/2398672015-09-05T02:22:13Z2015-09-05T02:22:13ZUseParallel parameter on elmann train makes only 1 worker "work"<p>Hi,</p><p>I'm training a ANN (Elmann) with the param 'useParallel'. However, out of 4 workers, 3 are unused. The training as it is takes too much time to finish.
My Matlab version is 2015a.</p><p>Computing Resources:
Parallel Workers:
Worker 1 on PA-PC, MEX on PCWIN64
Worker 2 on PA-PC, Unused
Worker 3 on PA-PC, Unused
Worker 4 on PA-PC, Unused</p><p>Can anyone help me?
Thanks in advance.</p>paulo ferreirahttp://www.mathworks.com/matlabcentral/profile/authors/6727772-paulo-ferreiratag:www.mathworks.com,2005:Question/2398572015-09-05T01:17:10Z2015-09-05T02:19:29ZLicense checkout failed? <p>Just downloaded MATLAB and got this message when I tried opening it. How do I fix this?</p><pre class="language-matlab">License checkout failed.
License Manager Error -9
Your username does not match the username in the license file.
To run MATLAB on this computer, you must run the Activation client to reactivate your license.
</pre><pre class="language-matlab">Troubleshoot this issue by selecting the button below or visiting:
http://www.mathworks.com/support/lme/R2015b/9
</pre><pre class="language-matlab">Diagnostic Information:
Feature: SR_MATLAB
License path: /Users/KCEvergreene/.matlab/R2015b_licenses:/Applications/MATLAB_R2015b.app/licenses/license.dat:/Applications/MATLAB_R2015b.app/licenses/license_Kylynns-MacBook-Pro_2445099_R2015b.lic
Licensing error: -9,57.
</pre>Kylynn Clarehttp://www.mathworks.com/matlabcentral/profile/authors/6877106-kylynn-claretag:www.mathworks.com,2005:Question/2396102015-09-04T05:46:03Z2015-09-05T00:53:05Zloadlibrary: Index exceeds matrix dimensions<p>I am trying to read TDMS (National Instrument data format) files from Matlab. I found a Matlab example provided by NI for reading and writing TDMS files. It consists of an extract of the TDM C DLL (library containing the necessary functions for reading and writing TDMS files in C) and an adapted C-header file (nilibddc_m.h) to be used in conjunction with the Matlab software.</p><p>In the 'Read' example the library is loaded thanks to 'loadlibrary' function. When I run the 'Read' program, I get the following error message:</p><p>====</p><p>Index exceeds matrix dimensions.</p><p>Error in loadlibrary>getLoadlibraryCompilerConfiguration (line 527)</p><p>Error in loadlibrary (line 263)</p><p>Error in ReadTDMS (line 34)</p><p>loadlibrary(DLL_Path,H_Path);</p><p>====</p><p>Any idea of what the source of the issue is?
Thanks</p><p>Francois</p>Francois Jeannerethttp://www.mathworks.com/matlabcentral/profile/authors/5915950-francois-jeannerettag:www.mathworks.com,2005:Question/2376972015-08-29T10:48:58Z2015-09-05T00:50:17ZHello, I'm new in MATLAB. I have math files and want to change in verilog, I tried other example in Google it's ok but in my math files generation i have errors "The function 'convenc' is not supported for standalone code generation. "Please help me<p>1
The function 'convenc' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.</p><p>2</p><p>convolution</p><p>54</p><p>Undefined function or variable 'coded_data'. The first assignment to a local variable determines its class.</p><p>61</p><p>The function 'vitdec' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.</p><p>66</p><p>Function 'display' is not supported for code generation. Consider adding coder.extrinsic('display') at the top of the function to bypass code generation</p>Arsen Nersisyanhttp://www.mathworks.com/matlabcentral/profile/authors/6825681-arsen-nersisyantag:www.mathworks.com,2005:Question/2382862015-08-31T10:35:32Z2015-09-05T00:46:07Zexport a 3D figure to pdf, such that it is rotatable etc. in the pdf<p>hello,</p><p>I would like to export a 3D figure to pdf, such that it is rotatable / scalable / moveable in the pdf.
I know there exist solutions, but can't get them to Work, because they are too old (I guess).</p><p>Can you help me there?</p><p>kind regards
Gerard</p>Gerardhttp://www.mathworks.com/matlabcentral/profile/authors/565737-gerardtag:www.mathworks.com,2005:Question/2392932015-09-02T20:36:23Z2015-09-05T00:45:04ZHow to write a table of into a binary file<p>Hi,</p><p>I have a table of many rows full of strings.
How to write the table into a binary file by fwrite.
I know how to write if it is numbers, but not if it is full of strings.</p><p>Thanks,</p><p>Jennifer</p>Jennifer Zhouhttp://www.mathworks.com/matlabcentral/profile/authors/6201072-jennifer-zhoutag:www.mathworks.com,2005:Question/2376902015-08-29T10:25:28Z2015-09-05T00:35:32Zhow to display the <1x19 cell> values in msgbox<p>I need to display the <1x19 cell> values in msgbox using GUI.</p>ajithhttp://www.mathworks.com/matlabcentral/profile/authors/3663085-ajithtag:www.mathworks.com,2005:Question/2338142015-08-13T19:28:49Z2015-09-05T00:29:26ZCan A = A + B'*B be sped up somehow? It is seriously bottlenecking my for-loop<p>I have a script where a very large matrix <tt>A</tt> (square, up to about <tt>10000 x 10000</tt> values) is initialized outside of a <tt>for-loop</tt> and is then overwritten many times within the loop like this:</p><pre class="language-matlab">A = zeros(6588,6588);
for i =1:1000
% B changes to a new value here and is a 27x6588 matrix
A = A + B' * B;
end
</pre><p>I wanted to remove the loop altogether but I think it’s impossible for me to calculate all instances of <tt>transpose(B)*B</tt> outside of the loop beforehand since I run out of memory.</p><p>Is there anything I could do to this code segment to speed it up? Computationally it’s just a few simple operations but they still take over 70% of my scripts runtime and I can’t figure out a way to improve this. Is it possible?</p>Petahttp://www.mathworks.com/matlabcentral/profile/authors/5582424-petatag:www.mathworks.com,2005:Question/2215922015-05-30T17:29:25Z2015-09-05T00:28:52ZCalculating the Jacobian -- How to Convert an Anonymous Function to a Symbolic Function<p>I am currently working on a complicated system of ~30 ODE's. To solve the system I have to use a stiff solver and calculate the jacobian of the system. I have written a successful series of functions that accomplishes this, however it requires that I define the ODE system in the "jacobian-calculating" function. Because of the complexity of my system I would prefer to create a stand-alone "model-function" that can be called by either my ode solver or my jacobian-calculating function.</p><p>I have included minimal examples of my code below. I believe my problem is with the line:</p><p>-----------------------------------------------------</p><pre class="language-matlab">%Convert the "Numeric" System to a Symbolic System
</pre><pre class="language-matlab">SymbolicSystem = sym(NumericSystem);
</pre><p>-----------------------------------------------------</p><p>where "NumericSystem" is the handle for the anonymous function of my ode system. This line is contained in my function "testjacobian".</p><p>Does anyone know how to convert an anonymous function into a symbolic function? Or is there a better strategy for what I'm trying to do?</p><p>I do know that my code seems a bit contrived for this simple system, but this is because I have tried to capture the essential elements of the code used to solve my more complex system.</p><p>Any help would be greatly appreciated,
Thanks in advance,</p><p>Laura</p><p>-----------------------------------------------------------------------------------</p><p>CODE:</p><p>-----------------------------------------------------------------------------------</p><pre class="language-matlab">function testdriver
</pre><pre class="language-matlab">%Parameters
</pre><pre class="language-matlab">a = 1;
</pre><pre class="language-matlab">b = 2;
</pre><pre class="language-matlab">c = 3;
</pre><pre class="language-matlab">d = 4;
</pre><pre class="language-matlab">param = [a b c d];
</pre><pre class="language-matlab">%Initial Conditions
</pre><pre class="language-matlab">start1 = 0;
</pre><pre class="language-matlab">start2 = 1;
</pre><pre class="language-matlab">init = [start1, start2];
</pre><pre class="language-matlab">%Calculate the solution
</pre><pre class="language-matlab">[t,x] = testsolver(param,init);
</pre><pre class="language-matlab">%Dynamics Plot
</pre><pre class="language-matlab">%Call a function that plots the data
</pre><pre class="language-matlab">% .... %
</pre><pre class="language-matlab">end
</pre><p>-----------------------------------------------------------------------------------</p><pre class="language-matlab">function [t,x]=testsolver(param,initial)
</pre><pre class="language-matlab">%Integration Domain
</pre><pre class="language-matlab">tspan = [0,10];
</pre><pre class="language-matlab">%Initial Conditions
</pre><pre class="language-matlab">x1init = initial(1);
</pre><pre class="language-matlab">x2init = initial(2);
</pre><pre class="language-matlab">xinit = [x1init,x2init];
</pre><pre class="language-matlab">%Construct the Scalar-Valued, Numeric, Jacobian Function
</pre><pre class="language-matlab">J = testjacobian(param);
</pre><pre class="language-matlab">%Convert the function to a Vector-Valued, Numeric Function
</pre><pre class="language-matlab">CalcJac = @(t,x) call_on(J,x);
</pre><pre class="language-matlab">%Define Integration Options -- Use the Jacobian
</pre><pre class="language-matlab">opts1 = odeset('Jacobian',CalcJac);
</pre><pre class="language-matlab">%Integrate the System
</pre><pre class="language-matlab">[t,x] = ode15s(@(t,x)testmodel(t,x,param),tspan,xinit,opts1);
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">function r = call_on(func, array)
</pre><pre class="language-matlab">%This Function Converts a Scalar-Valued Function to a Vector-Valued Function
</pre><pre> vector = num2cell(array);</pre><pre> r = func(vector{:});</pre><pre class="language-matlab">end
</pre><p>-----------------------------------------------------------------------------------</p><pre class="language-matlab">function xp = testmodel(t,x,param)
</pre><pre class="language-matlab">%Define Parameters
</pre><pre class="language-matlab">A = param(1);
</pre><pre class="language-matlab">B = param(2);
</pre><pre class="language-matlab">C = param(3);
</pre><pre class="language-matlab">D = param(4);
</pre><pre class="language-matlab">%Assign x values to Variable Names
</pre><pre class="language-matlab">thing1 = x(1);
</pre><pre class="language-matlab">thing2 = x(2);
</pre><pre class="language-matlab">%Initialize the Derivatives to Zero
</pre><pre class="language-matlab">xp = zeros(2,1);
</pre><pre class="language-matlab">%System of ODE's
</pre><pre class="language-matlab">xp(1) = A*thing1^2 + B*thing2;
</pre><pre class="language-matlab">xp(2) = C*thing1 + D;
</pre><pre class="language-matlab">end
</pre><p>-----------------------------------------------------------------------------------</p><pre class="language-matlab">function Jacob=testjacobian(param)
</pre><pre class="language-matlab">%Initialize Symbolic Variables
</pre><pre class="language-matlab">syms tsym y1 y2
</pre><pre class="language-matlab">y = [y1 y2];
</pre><pre class="language-matlab">%Using "param" Construct a (t,x)-Dependent System
</pre><pre class="language-matlab">NumericSystem = @(t,x)testmodel(t,x,param);
</pre><pre class="language-matlab">%Convert the "Numeric" System to a Symbolic System
</pre><pre class="language-matlab">SymbolicSystem = sym(NumericSystem);
</pre><pre class="language-matlab">%Calculate the Jacobian of the Symbolic System
</pre><pre class="language-matlab">SymbolicJacobian = jacobian(SymbolicSystem',y);
</pre><pre class="language-matlab">%Convert the Symbolic Function to a "Numeric" Function Dependent on y
</pre><pre class="language-matlab">Jacob = matlabFunction(SymbolicJacobian,'var',y);
</pre><pre class="language-matlab">end
</pre>Laurahttp://www.mathworks.com/matlabcentral/profile/authors/6565613-lauratag:www.mathworks.com,2005:Question/1799242015-02-23T20:10:43Z2015-09-05T00:20:08ZRefining a Jagged "Skeletonized" Line (Image)<img src = "/matlabcentral/answers/uploaded_files/26012/roughline.png"><p>Above is the basic image of the line I want to refine / smooth out.</p><p>Below is a mock-up I made in paint of what I want to line to look like.</p><img src = "/matlabcentral/answers/uploaded_files/26013/mockupline.png"><p>I'm extracting the center-line of fish using the <a href = "http://www.mathworks.com/matlabcentral/fileexchange/11123-better-skeletonization">better skeletonization method</a> and while it is much more refined then the basic bwmorph skel() function it isn't quite as smooth as desired.</p><p>I'm processing a couple of images but the problem is roughly the same in all of them (jagged bumps). Does anyone have any tips of how to go about this problem?</p><p>Thanks in advance.</p>Brian Vuhttp://www.mathworks.com/matlabcentral/profile/authors/6139104-brian-vutag:www.mathworks.com,2005:Question/2392942015-09-02T20:44:00Z2015-09-05T00:14:20ZMATLAB doesn't find my files I downloaded while the script is running<p>Hello,</p><p>My problem is as described. My script downloads files through an external call to cmd (using the system function and then .NET to make keypresses). The issue is that when it tries to fopen these files I downloaded (filenames from a text file I write as I download), it doesn't find them, causing an error. When I run the script again after seeing it fail, it works but only up to the point where it's trying to download/call new files again, where it runs into the same problem.</p><p>Are new files downloaded during when a script is running somehow not visible to the search path? Because the folder is most definitely in my search path (seeing as it works outside of during-script downloads). It's not that it isn't getting the files fast enough either, cause they appear in my folder almost instantly, and I've tried a delay to allow for it to recognize it, but that didn't work either.</p><p>I'm not sure if it's important to note that the script calls an external function which tries to read the files from the .txt list I create in the main script.</p><p>Any ideas?</p><p>Thank you,</p><p>Aaron</p>Aaron Andersonhttp://www.mathworks.com/matlabcentral/profile/authors/4243348-aaron-andersontag:www.mathworks.com,2005:Question/2395742015-09-04T03:05:57Z2015-09-05T00:09:29ZHow to normalize data which contain positive and negative numbers into 0 and 1? you can refer sample of my data below. I have tried but am getting an error which says data dimension must agree. Any suggestion, please. Thank you!<pre class="language-matlab">Datatraning = 100.*randn(300,1552)
minVal = min(Datatraning);
maxVal = max(Datatraning);
norm_data = (Datatraning - minVal) / ( maxVal - minVal )
</pre><pre> Datatraining=[-51.6266980068282 260.373726514691 -1040.96015167892 255 -52.6288579705138 95.7235349174854
-49.8245562897936 298.367268515596 -900.490111536352 255 -49.9703056795758 108.101521100263
-36.2057603415223 398.270463317273 -749.608432372270 255 -49.5514320195152 118.634907748186
-34.2981982381135 435.407482297911 -38.4773520065891 255 -39.5337029802548 176.756214679240]</pre>Adnan Ibrahimhttp://www.mathworks.com/matlabcentral/profile/authors/4224657-adnan-ibrahimtag:www.mathworks.com,2005:Question/2394422015-09-03T14:59:50Z2015-09-04T23:54:11ZThe generated code is it the same of the framwork ?<p>the question is in the title</p>Jameshttp://www.mathworks.com/matlabcentral/profile/authors/5637832-jamestag:www.mathworks.com,2005:Question/2398202015-09-04T17:32:10Z2015-09-04T23:50:59ZObtaining an optimized log likelihood value using 'fmincon'<p>According to the help file for 'aicbic' an optimized log likelihood can be obtained from 'fmincon', does this refer to the value of the objective function at the solution (i.e. fval)? If so, do I use fval or log(fval) as the input to 'aicbic'?</p><p>Thank you</p>Stephaniehttp://www.mathworks.com/matlabcentral/profile/authors/2144268-stephanietag:www.mathworks.com,2005:Question/2391512015-09-02T13:27:00Z2015-09-04T23:31:47ZAny way to get 2015a working with two environments?<p>This is kind of a silly question of convenience, but I'll ask anyway.</p><p>I have two large matlab projects that do not overlap in code base.
Matlab saves the status of your session, command history and open files and such.
Of course then when I go to work on the other project, I have to close all these files and open those...</p><p>Is there a way to save the current sessions status say with a project name?
So that I can open project A and work there. Close project A and then Open project B with a different set of open files and command history etc?</p><p>Thanks for all answers.</p>David Shorthttp://www.mathworks.com/matlabcentral/profile/authors/1310567-david-shorttag:www.mathworks.com,2005:Question/2396052015-09-04T05:28:10Z2015-09-04T23:23:40ZError using zeros, Size inputs must be scalar<pre class="language-matlab">train_data = zeros(num_train_data,1);
</pre><p>I get error on this line. I attached the screenshot of my <tt>num_train_data</tt> below.</p><p>PS Im new to matlab.</p><img src = "/matlabcentral/answers/uploaded_files/36615/Capture.PNG">Js Gohhttp://www.mathworks.com/matlabcentral/profile/authors/6873123-js-gohtag:www.mathworks.com,2005:Question/2395042015-09-03T21:04:58Z2015-09-04T22:49:58ZHow to store matrix data (Imaginary) from a loop<p>Hello,
In my project I have a loop and each iteration gives me a matrix with imaginary values:</p><pre> for fi = 0:10000:1100000
....
A1=[a11,a12;a21,a22]
end</pre><p>Output:</p><pre> A1 =
1.0e+02 *
-0.0934 + 0.0245i -9.0639 + 3.2366i
-0.0010 + 0.0002i -0.0934 + 0.0245i</pre><p>I need to store all this matrixes with relation to fi value.
I am going to use few similar loops and multiply output matrixes (for the same value of fi).</p><p>I try to use</p><pre> A1(fi)=[a11,a12;a21,a22]</pre><p>but have below error:</p><p>Subscript indices must either be real positive integers or logicals.</p><p>Can I please any ideas and tips? :)</p>Jaroslaw Netkowskihttp://www.mathworks.com/matlabcentral/profile/authors/6871060-jaroslaw-netkowskitag:www.mathworks.com,2005:Question/2395012015-09-03T20:46:29Z2015-09-04T22:45:40ZA problem with section of code days after entered<p>My code out of nowhere started malfunctioning. I tried everything I could think of. I found an old GUI and it started working making me realize it was the adjustment I made many runs and days ago. To confirm, I took this snippet out of the problematic GUIs and it started working again. Here is the code in question:</p><p>axis tight</p><p>camlight</p><p>shading interp</p><p>colormap(jet(256))</p><p>I used it after Surf(M) to give my surf plot better visuals and I took this code from a answer I found here on MatAnswers</p><p>My question is do I have to worry about this happening in the future now that I have changed the code to:</p><p>camlight left;</p><p>lighting phong</p><p>Has anyone found the code I entered problematic? I am worried because I am about to give this code to someone to use as a new program for them. So I won't be there if it goes wrong again. Thanks.</p>shannon stoffelhttp://www.mathworks.com/matlabcentral/profile/authors/6822172-shannon-stoffeltag:www.mathworks.com,2005:Question/2394802015-09-03T19:11:07Z2015-09-04T22:41:42Zhow to average time at every 5 intervals in matlab<p>Here is my data</p><pre class="language-matlab">02-Sep-2015 09:58:32: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:32: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
</pre><p>I have written some code</p><pre class="language-matlab">n=5;
A=arrayfun(@(i) mean(data(i:i+n-1)),1:n:length(numdata1)-n+1)';
</pre><p>But i find NaN as the output</p><p>can i have some suggestions</p>sushma gundehttp://www.mathworks.com/matlabcentral/profile/authors/6784818-sushma-gundetag:www.mathworks.com,2005:Question/2391722015-09-02T14:29:36Z2015-09-04T22:27:06Zreading data in xml format<pre> <xml>
<node1>
<val>5</val>
<val>7</val>
</node1>
</xml></pre><pre> xml_vals = node.item(0).getElementsByTagName('val');
values = zeros(1,xml_vals.getLength);
for iVal = 1:xml_vals.getLength-1
values(iVal+1) = str2num(xml_vals.item(iVal).getFirstChild.getData);
end</pre><p>Is there a simple way to use an XMLDom to get all the values directly into a vector? Currently I am looping through them but this is very slow.</p>Tom Wrighthttp://www.mathworks.com/matlabcentral/profile/authors/427912-tom-wrighttag:www.mathworks.com,2005:Question/2392722015-09-02T18:46:15Z2015-09-04T22:07:13Zhow you could adjust this script to guarantee that there is at least one letter and at least one digit?<pre> N=input('Give length of password to be generated: ');
characters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
[m,n]=size(characters);
for i=1:N
password(i)=characters(randi([1 n],1,1));
end
disp('Your password is: ')
disp(password)</pre>Nahid Hussainhttp://www.mathworks.com/matlabcentral/profile/authors/5837337-nahid-hussaintag:www.mathworks.com,2005:Question/2398322015-09-04T17:48:44Z2015-09-04T21:58:20ZProblem while counting cells<p>Hello chaps.</p><p>My problem is simple, I can't find a way to use matlab to count my cells. I'v tried many approach, the more reliable would be the one named <a href = "bw2%20=%20imfill(bw,'holes');%20bw3%20=%20imopen(bw2,%20ones(5,5));%20bw4%20=%20bwareaopen(bw3,%2040);%20bw4_perim%20=%20bwperim(bw4);%20overlay1%20=%20imoverlay(I_eq,%20bw4_perim,%20%5B.3%201%20.3%5D);%20imshow(overlay1)">Steve on Image Processing</a>.</p><p>I tried his code, and what happened is that my image would become black. Without further do, here are the images step by step. I'll include the code lines as well as the images.</p><p>We're beginning with this first image, the raw product take on a Zweiss microscope.</p><pre class="language-matlab">clear all; close all; clc
</pre><pre class="language-matlab">I = imread('test.jpg');
</pre><img src = "/matlabcentral/answers/uploaded_files/36641/test.jpg"><p>Applying the grey threshold.</p><pre class="language-matlab">bw = im2bw(I, graythresh(I));
</pre><p>As you can see, I'm already loosing some cells in the dark area.</p><img src = "/matlabcentral/answers/uploaded_files/36642/Gray_Tresh.jpg"><p>Now for the "filling of holes"</p><pre class="language-matlab">bw2 = imfill(bw,'holes');
</pre><img src = "/matlabcentral/answers/uploaded_files/36644/3rd_step.jpg"><p>So yeah, not much to work from. Here's the small portion of code related to this, it's not much, but it doesn't work anyway so.</p><pre class="language-matlab">I = imread('test.jpg');
bw = im2bw(I, graythresh(I));
bw2 = imfill(bw,'holes');
bw3 = imopen(bw2, ones(5,5));
bw4 = bwareaopen(bw3, 40);
bw4_perim = bwperim(bw4);
imshow(bw4_perim)
</pre><p>If anyone has a solution, or a better method, thank you, thank you so much. You'll save me countless hours of counting cells.</p><p>Regards,
Arthur</p>Arthurhttp://www.mathworks.com/matlabcentral/profile/authors/4614378-arthurtag:www.mathworks.com,2005:Question/2217492015-06-01T05:10:39Z2015-09-04T21:58:15ZProblem with GUIDE based app and R2015a<p>We have a GUIDE based application that required some work to get functional again with 2014b. Now with 2015a I'm getting the errors below on startup in the main GUIDE function. If I try to open the .fig file it hangs with most but not all of the [complex] dialog displayed. I've searched but can't find anything relevant.</p><p>The error message is</p><pre class="language-matlab">Undefined variable "matlab" or class "matlab.settings.Group".
</pre><pre class="language-matlab">Error in settings (line 35)
group = matlab.settings.Group(s, 'session');
</pre><pre class="language-matlab">Error in ligoDV_ligoDV_OpeningFcn (line 79)
setappdata(handles.main, 'settings', settings);
</pre><pre class="language-matlab">Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
</pre><pre class="language-matlab">Error in ligoDV (line 45)
gui_mainfcn(gui_State, varargin{:});
</pre><pre class="language-matlab">Error in ligoDV_start (line 164)
ligoDV;
</pre><p>ligoDV is the name of the app.</p><p>Any clues on how to figure this out would be greatly appreciated.</p>Joseph Areedahttp://www.mathworks.com/matlabcentral/profile/authors/4418095-joseph-areedatag:www.mathworks.com,2005:Question/14272011-02-16T09:53:30Z2015-09-04T21:57:43ZWhat frustrates you about MATLAB?<p>I love MATLAB. It is so quick and easy to write software to do what you want. It has excellent debugging and profiling tools. It is cross platform, making code easy to share (assuming the other people have forked out for the not-so-cheap license). It has interfaces to other software.</p>
<p>However, there are some things about it that irk me. I'd like to hear from other people what things annoy them about MATLAB.</p>Oliver Woodfordhttp://www.mathworks.com/matlabcentral/profile/authors/1073021-oliver-woodfordtag:www.mathworks.com,2005:Question/2398412015-09-04T20:11:41Z2015-09-04T21:39:23ZHow to start multiple analog output on Ni daq device?<p>Hello</p><p>I'm trying to use Ni daq device to output multiple signals. The signals are not started at same time, instead, some of them are sine wave signals which run for several seconds, while others are single pulses which triggered by external input. The sine wave signals keeps outputting throughout the session, while whenever there's a trigger signal, the ni daq device must give a short output.
I tried many ways to fulfill this function. Anyway, the problem is that I can't output other signals when the sine wave signal is outputting. Matlab warns the device has been reserved and the new output signal can't be start. Is there any way I can use to solve this problem?</p><p>Thank you</p>Simonhttp://www.mathworks.com/matlabcentral/profile/authors/4670831-simontag:www.mathworks.com,2005:Question/2392622015-09-02T18:04:48Z2015-09-04T21:38:05ZOpening csv file using text scan returns [0x1 double]<p>I originally had a code that opened text files so that I could read the data:
here is an example data file:</p><pre class="language-matlab">Frequency/Hz ZRe/Ohm ZIm/Ohm
25000 123.973 -55.621
22471.91 130.936 -58.299
20000 131.607 -61.111
17977.53 132.36 -66.828
16064.26 134.676 -70.063
14466.55 137.25 -75.438
12841.09 138.59 -82.377
11494.25 141.42 -83.387
10335.92 142.741 -96.216
9195.4 151.153 -100.342
8205.13 146.893 -111.375
7326.01 152.058 -121.697
6568.14 157.189 -133.012
5882.35 160.671 -145.992
5259.7 163.611 -160.421
4705.88 166.562 -176.182
4203.89 169.427 -193.571
3766.48 170.511 -212.774
3361.34 173.806 -235.36
3013.18 179.252 -258.61
</pre><p>and the beginning of the code:</p><pre class="language-matlab">function [zizr]= getdata3(filename)
currentfolder=pwd
PathStr=pwd;
textFiles=dir([PathStr '*.txt'])
MyData=zeros(100,22); %assume data has 100 rows
for k = 1:3;
length(textFiles)
textFilename = [filename num2str(k) '.txt']
%Open text file, 'rt' is for reading a text file only
fid=fopen(textFilename, 'rt')
%Read file into 3 seperate variables
Data = textscan(fid,'%f %f %f','Headerlines',1)
</pre><p>that code works fine, however now I would like to open csv files that have 5 headerlines:</p><pre class="language-matlab">Type:,FixedPotential
Date and time:,2015-09-02 08:56:49
Title:,CH1-090215SynthUrine-3
series:,0.060,0.029
freq / Hz,Z' / Ohm,Z'' / Ohm,
25000.00,123.973,-55.621,
22471.91,130.936,-58.299,
20000.00,131.607,-61.111,
17977.53,132.360,-66.828,
16064.26,134.676,-70.063,
14466.55,137.250,-75.438,
12841.09,138.590,-82.377,
11494.25,141.420,-83.387,
10335.92,142.741,-96.216,
9195.40,151.153,-100.342,
8205.13,146.893,-111.375,
7326.01,152.058,-121.697,
6568.14,157.189,-133.012,
5882.35,160.671,-145.992,
5259.70,163.611,-160.421,
4705.88,166.562,-176.182,
4203.89,169.427,-193.571,
3766.48,170.511,-212.774,
3361.34,173.806,-235.360,
3013.18,179.252,-258.610,
</pre><p>I would like to do the exact same thing as in my previous code, just with csv files. Here is what i have but it doesnt seem to work.</p><pre> function [zizr]= getdata3(filename)
currentfolder=pwd
PathStr=pwd;
textFiles=dir([PathStr '*.csv'])
MyData=zeros(100,22); %assume data has 100 rows
for k = 1:3;
length(textFiles)
textFilename = [filename num2str(k) '.csv']
%Open text file, 'rt' is for reading a text file only
%fid=fopen(textFilename, 'r')
fid=fopen(textFilename,'rt')
%Read file into 3 seperate variables
Data = textscan(fid,'%f %f %f','Delimiter',',','headerlines',5)</pre><p>I keep getting : Data =</p><pre> [0x1 double] [0x1 double] [0x1 double]</pre><p>I am mainly concerned with the textscan inputs I have and if something is wrong there.</p>Alano Ogatahttp://www.mathworks.com/matlabcentral/profile/authors/6545038-alano-ogatatag:www.mathworks.com,2005:Question/2398442015-09-04T21:09:47Z2015-09-04T21:38:00ZWhen I use the embedded coder and the HW-Support-Package to put a Simulink model on my Raspberry Pi, is the code compiled on the Pi or is it cross compiled on my PC an then transferred to the Pi?<p>I just want to understand the way it works. Is the code compiled on the target or on the host?</p>MikeShttp://www.mathworks.com/matlabcentral/profile/authors/6877035-mikestag:www.mathworks.com,2005:Question/2398102015-09-04T15:41:53Z2015-09-04T21:35:05ZThreshold for each column of a mxn matrix<p>Hi, if say I have a m x n matrix and I want to set a certain threshold for column 1 and certain threshold for column 2, how can I do this please?</p><p>For example, if I have</p><pre class="language-matlab">[1 11
2 12
3 13
4 14
5 15]
</pre><p>and I want to set column1>2 AND at the same time column2<15, which means at the end will left</p><pre class="language-matlab">[3 13
4 14]
</pre><p>how can i code this please? this is just an example as my data file is actually much bigger.
Thank you very much.</p>smohttp://www.mathworks.com/matlabcentral/profile/authors/5931615-smotag:www.mathworks.com,2005:Question/2398452015-09-04T21:21:30Z2015-09-04T21:35:46Zexecution of two programs at different time in everyday<p>i am doing image processing for automatic traffic control. thats why i need to run one program in day time and other in night time. how can i do it? please someone help</p>Tun rakhinehttp://www.mathworks.com/matlabcentral/profile/authors/6877056-tun-rakhinetag:www.mathworks.com,2005:Question/2398172015-09-04T16:41:53Z2015-09-04T21:22:31ZMATLAB's R2015b new JIT experiences a severe degradation in speed in the following example, but the documentation says it was significantly improved. Why would the following simple code run so much slower?<p>When I run the following code:</p><pre class="language-matlab">I = 1000;
J = 1000;
K = 1000;
</pre><pre class="language-matlab">A = rand(I,K);
B = rand(K,J);
C = zeros(I,J);
</pre><pre class="language-matlab">tic
for i=1:I
for j=1:J
for k=1:K
C(i,j) = C(i,j)+A(i,k)*B(k,j);
end
end
end
toc
</pre><p>it takes 7.7 seconds on R2015a and 26.1 seconds on R2015b, which is over a 3 times slowdown. I've emailed support, but they cannot determine why it runs slower, only that the new JIT should speed up code on average. However, this code seems very simple and I'd like to better understand when the new JIT will increase performance vs degrade performance. Thanks for any help.</p>Philiphttp://www.mathworks.com/matlabcentral/profile/authors/1089873-philiptag:www.mathworks.com,2005:Question/2398422015-09-04T20:28:44Z2015-09-04T21:12:10ZHow do I add space between vectors so that they line up with column headers?<p>The column titles are long so the vectors don't line up under the headers. Here's a picture of what I mean: <a href = "http://imgur.com/zVkObbO">http://imgur.com/zVkObbO</a></p><p>Is there a way to add each vector individually but with space between them so that everything lines up?</p><p>Thanks</p>Chris Birzerhttp://www.mathworks.com/matlabcentral/profile/authors/6876891-chris-birzertag:www.mathworks.com,2005:Question/2398242015-09-04T17:36:58Z2015-09-04T20:57:23ZDeploying protected executable or p-code (Taurus Software or similar)<p>Hello,</p><p>I am looking for a solution to protect my matlab codes when I deploy them either as pcodes or executable files. I was going to get Taurus from <a href = "http://www.algorithmprotection.com/">http://www.algorithmprotection.com/</a> but the site is not working anymore. is there another professional solution to my problem?</p>Kamuranhttp://www.mathworks.com/matlabcentral/profile/authors/1504443-kamurantag:www.mathworks.com,2005:Question/2398432015-09-04T20:52:54Z2015-09-04T20:52:54ZI am modulating a carrier wave with a BPSK data stream. When I select a carrier frequency of 1000 Hz and use 'sound(y)', I am measuring 50 Hz out of my audio jack. Why is this? It is always a lower frequency by about a factor of 20.<p>close all; clear all; clc;</p><p>% the binary generated base on AOSCII table</p><p>Ob= [0 1 1 0 1 1 1 1];
Ib= [0 1 1 0 1 0 0 1];
Tb= [0 1 1 1 0 1 0 0];</p><p>SIG=[Ob Ib Tb];
%SIG = repmat(SIG,10) % repeat signal 10 times</p><p>br = 200 ; % bit rate
Tb=1/br;
fs = 1600*br; % Sampling Frequency.
Ts = 1/fs; % Sampling Period.
t=0:Ts:Tb*length(SIG)-Ts;</p><p>N = 2^14;
f = fs/2*linspace(0,1,N/2+1);</p><p>SIG2= NRZ_Encode(SIG,br,fs); % NRZ coding</p><p>fc = 1500; % Carrier frequency
C1 = 4*sin(2*pi*fc*t); % Carrier</p><p>% modulatiion</p><p>BPSK = SIG2.*C1;</p><p>figure(1)
plot(t,BPSK);axis tight;box off; ylim([-5 5]);
title('BPSK MODULATED SIGNAL');
xlabel('time,s');ylabel('amplitude');</p><p>sound(BPSK);</p>Michael Ruehlehttp://www.mathworks.com/matlabcentral/profile/authors/6876890-michael-ruehle