http://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-04-30T05:18:51Ztag:nl.mathworks.com,2005:Question/2817392016-04-29T17:20:24Z2016-04-30T05:18:51ZSame Value with any parameter change<p>There 2 important parameter in my script, "alpha(0.90-0.99)" and "N",
the VaR result produce same number for any alpha number(from 0.90 to 0.99) and with N (from 100-1000).</p><p>why vectPrice(k,1)=produce same result (i thought this was simulation result)</p><p>and why if i use manual like</p><pre class="language-matlab">VaR=(InitialPrice-vectPrice(floor(0.99/100*10000)));
</pre><p>the result was problem with integer</p><pre> alpha=0.93;
N=1000;
k=1:N;
InitialPrice=11000;
PortfolioPrice=12000;</pre><pre> vectPrice(k,1)= PortfolioPrice;
vectPrice=sort(vectPrice);
VaR=(InitialPrice-vectPrice(floor(alpha/100*N)));</pre>Gerenimohttp://nl.mathworks.com/matlabcentral/profile/authors/4394929-gerenimotag:nl.mathworks.com,2005:Question/2814852016-04-28T11:42:32Z2016-04-30T04:59:05ZHow to stack .mat files?<p>Suppose in one of my data set, i have 20 .mat files.</p><p>Now, i want to stack all 20 .mat files together.</p><p>The issue is though they are in the same data set, size of each .mat file differs (not a huge variation though). As my final objective is to create a 3D model, how can i stack those .mat files together in order to open in another visualization software?
Kindly (atleast) send me a link/documentation which help me to resolve this issue.</p>Chathuhttp://nl.mathworks.com/matlabcentral/profile/authors/4838921-chathutag:nl.mathworks.com,2005:Question/2818042016-04-30T04:51:17Z2016-04-30T04:53:46Zhow can I declare variables and make an object function?<p>I'm studying optimization problem using matlab for genetic algorithm.</p><p>for example, objective function is</p><img src = "/matlabcentral/answers/uploaded_files/51104/1.JPG"><p>h is constant and j is index. j=1,2,...,J.
R, I is variables. t is also index. j=1,2,...,J , t=1,2,...T.</p><p>my code is</p><p>function C = ojtmin (x)
Rjt = x(1);
Ijt = x(2);
H1 = 1;
H2 = 2;</p><p>C = symsum(symsum((1/2*Hj*(Rjt+Ijt),j,1,1),t,1,2);</p><p>what is wrong? show me the right code.</p>younghyeon yanghttp://nl.mathworks.com/matlabcentral/profile/authors/7898943-younghyeon-yangtag:nl.mathworks.com,2005:Question/2816282016-04-29T06:23:54Z2016-04-30T04:50:49ZI want to tsolve the attached problem<img src = "/matlabcentral/answers/uploaded_files/51027/Untitled.jpg">Shebihttp://nl.mathworks.com/matlabcentral/profile/authors/8117475-shebitag:nl.mathworks.com,2005:Question/2818032016-04-30T04:44:28Z2016-04-30T04:44:28Zi am new to matlab. I am trying to solve implicit equation in matlab using fsolve and and fzero command but getting error. Please guide<pre class="language-matlab">syms x, L % x and L both are variables
detr=2*x*cos(L*x) - x - x*cos(L*x)^2 - x*sin(L*x)^2 + L*x^2*sin(L*x)
sol1=fzero(detr, 0)
sol2 = fsolve(detr,0)
</pre><p>Error: If FUN is a MATLAB object, it must have an feval method.</p>Anees khanhttp://nl.mathworks.com/matlabcentral/profile/authors/2567040-anees-khantag:nl.mathworks.com,2005:Question/2807772016-04-25T04:17:47Z2016-04-30T04:44:15ZHow can I remove all the small terms in multiple matrices transformation? It's too hard to read.<p>End-effector z position:</p><pre> -16
cos(th4) l4 sin(th2) cos(th3) + 0.61232 10 cos(th4) l4 sin(th3)</pre><pre> -16
+ 0.61232 10 cos(th4) l4 sin(th3) cos(th2)</pre><pre> -16
- 0.61232 10 sin(th4) l4 sin(th2) sin(th3)</pre><pre> -32
+ 0.37494 10 sin(th4) l4 cos(th3)</pre><pre> -32
+ 0.37494 10 sin(th4) l4 cos(th3) cos(th2)</pre><pre> -32 -32
+ 0.37494 10 sin(th4) l4 - sin(th4) l4 cos(th2) + 0.37494 10 l3</pre><pre> - l3 cos(th2) + l1</pre>yong lihttp://nl.mathworks.com/matlabcentral/profile/authors/6149300-yong-litag:nl.mathworks.com,2005:Question/2818022016-04-30T04:28:54Z2016-04-30T04:28:54ZI am writing a code to apply A star algorithm on an image. For that i have made the image into a grid format by directly manipulating pixels. My problem now is how to pass these grid blocks as a set of nodes to the A star algorithm module<pre class="language-matlab">if true
img = imread(' '); % Binary Image
S = input('enter the Size of the grid:');
for i = 1 : S : m
img(i,:) = 0;
end
for j = 1 : S : n
img(:,j) = 0;
end
figure, imshow(img);
end
</pre>jaganath hhttp://nl.mathworks.com/matlabcentral/profile/authors/8121808-jaganath-htag:nl.mathworks.com,2005:Question/2817502016-04-29T18:33:02Z2016-04-30T04:06:53ZHow can I create a surface plot of a function of 3 variables?<p>I have the following function that describes a quadric surface:</p><pre class="language-matlab">syms f(x, y, z)
f(x, y, z) = -x^2 - (y^2 / 4) + (z^2 / 4) == 1
</pre><p>I'm trying to understand how to plot it. I've tried a few things, like solving the equation for z, and then filling in a matrix containing z values. e.g.</p><pre class="language-matlab">syms g(x, y);
g(x, y) = solve(f(x, y, z), z); % matrix([[-(4*x^2 + y^2 + 4)^(1/2)], [(4*x^2 + y^2 + 4)^(1/2)]])
</pre><pre class="language-matlab">xrange = -10:10;
yrange = -10:10;
zrange = zeros(numel(xrange), numel(yrange));
for i = 1:numel(xrange)
for j = 1:numel(yrange)
zrange(i, j) = g(xrange(i), yrange(j));
end
end
</pre><p>Unfortunately, this code does not because z can take on multiple values for a given (x, y) value. MATLAB rightly complains:</p><pre class="language-matlab">Assignment has more non-singleton rhs dimensions than non-singleton subscripts
</pre><p>Any tips? Do I need to make xrange and yrange into matrix values? If so, then what should they look like? If not, then what are some other things I can look into?</p><p>Thanks.</p>Kamil Jiwahttp://nl.mathworks.com/matlabcentral/profile/authors/7696490-kamil-jiwatag:nl.mathworks.com,2005:Question/2816752016-04-29T12:14:20Z2016-04-30T03:36:28ZMay I ask how to get the value of amplitude from one wav. file?<p>May I ask how to get the value of amplitude from one wav. file? Because I want to do distortion wav. file..</p>loong seow lihttp://nl.mathworks.com/matlabcentral/profile/authors/7820955-loong-seow-litag:nl.mathworks.com,2005:Question/2817732016-04-29T21:31:47Z2016-04-30T03:35:02ZNearly identical code, hugely different runtimes<p>Hi all,</p><p>I've got a weird situation going on. I have the following code:</p><pre class="language-matlab">if true
for ii = 2:natom
tcheck = 1;
while tcheck ~= 0
tcheck = 0;
lx = rand*lxmax;
ly = rand*lymax;
lz = rand*lzmax;
</pre><pre> for jj = 1:ii-1</pre><pre> x12 = lx-x(jj);
y12 = ly-y(jj);
z12 = lz-z(jj);
%
x12 = x12-lxmax* round(x12/lxmax);
y12 = y12-lymax* round(y12/lymax);
z12 = z12-lzmax* round(y12/lzmax);
%
dist = sqrt(x12^2 +y12^2 + z12^2);
if dist <= rmax
tcheck =tcheck +1;
break
end
end
end
x(ii) = lx;
y(ii) = ly;
z(ii) = lz;
ii
endif true </pre><p>natom=4000 and x,y,z are vectors of length 4000. lxmax, lymax, and lzmax are all equal at 40.5 which is what I have "cubesize" set to in the next code. In general you can assume the parameters controlling the iteration process are the same for both.</p><p>I am trying to incorporate this code into another program and rewrote it as such:</p><pre class="language-matlab">if true
for i=2:natoms
while flag ~= 0
flag=0;
xtemp=rand*cubesize;
ytemp=rand*cubesize;
ztemp=rand*cubesize;
</pre><pre> for j=1:i-1
xvec=xtemp-store(j,3);
yvec=ytemp-store(j,4);
zvec=ztemp-store(j,5);</pre><pre> xvec = xvec-cubesize* round(xvec/cubesize);
yvec = zvec-cubesize* round(yvec/cubesize);
zvec = zvec-cubesize* round(zvec/cubesize);</pre><pre> dist=sqrt(xvec^2+yvec^2+zvec^2);</pre><pre> if dist <= moldia
flag=1;
break;
end
end
end
store(i,2)=i;
store(i,3)=xtemp;
store(i,4)=ytemp;
store(i,5)=ztemp;
flag=1;
i
end</pre><pre class="language-matlab">endif true
</pre><p>This code takes a HUGE amount more time to run. What gives? One speeds its way to i=3500 or so in a matter of seconds. The other craws to i=700 or so and then bogs. I even tried swapping out and storing everything in single vectors first with no effect.</p><p>The first code was inside a function, so I tried putting my entire new script inside a dummy function to no effect.</p><p>Thanks,
Nathan</p>Nathan Phelpshttp://nl.mathworks.com/matlabcentral/profile/authors/6905671-nathan-phelpstag:nl.mathworks.com,2005:Question/2817022016-04-29T14:18:04Z2016-04-30T03:30:19ZCan anybody help me by providing me Continuum Removal code for reflectance spectrum?<p>I am trying to design an algorithm for continuum removal since many days, but I could not get a suitable result. Please help me for the same.</p>vivek chudasamahttp://nl.mathworks.com/matlabcentral/profile/authors/7046266-vivek-chudasamatag:nl.mathworks.com,2005:Question/2037542015-04-15T22:06:33Z2016-04-30T03:29:55ZMinimum value,row and column<p>I want to find the minimum value of a matrix,the row and the column of it</p>Giannakis Stoukashttp://nl.mathworks.com/matlabcentral/profile/authors/6307629-giannakis-stoukastag:nl.mathworks.com,2005:Question/1005452010-06-28T16:30:00Z2016-04-30T03:27:53ZHow can I programmatically control mouse motion and clicks with MATLAB?<p>I am creating a demo using MATLAB and I would like to programmatically move and click the mouse to demonstrate my application.</p>MathWorks Support Teamhttp://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/2818002016-04-30T03:24:35Z2016-04-30T03:27:19Zthe data read from txt file is not the same as the txt file<p>hello everyone, I have a txt file which consists of only 1 and 0 data.
when I read the txt file and send the data to a memory in a device through serial port.
I noticed that the memory consists of not only 1 0 data but also few other data.
the ASCII code of 1 and 0 are 49 and 48 respectively,but there exists other ASCII code....</p><img src = "/matlabcentral/answers/uploaded_files/51103/%E6%93%B7%E5%8F%96.JPG">jzy FGGFhttp://nl.mathworks.com/matlabcentral/profile/authors/7995150-jzy-fggftag:nl.mathworks.com,2005:Question/2818012016-04-30T03:25:32Z2016-04-30T03:25:32Zhow can I access to pixels of objects produced by connected componenets function?<p>when I use built-in function "bwconncomp" in matlab, I don't know which objects black and white it is produced as an target objects of this function? Also, I need to access pixels of these objects to remove some of them.</p>Abdelrahiem Hashemhttp://nl.mathworks.com/matlabcentral/profile/authors/8121700-abdelrahiem-hashemtag:nl.mathworks.com,2005:Question/2817142016-04-29T15:29:22Z2016-04-30T03:24:33ZHow do you make a 2D graphs with levels of colour?<p>Hello, I can't find how to plot 2D graphs with levels of colours like the 7 first graphs that one can find on the folowing adress :</p><p><a href = "http://fr.mathworks.com/help/signal/ref/spectrogram.html">http://fr.mathworks.com/help/signal/ref/spectrogram.html</a></p><p>Thanks in advance!</p>Fervavhttp://nl.mathworks.com/matlabcentral/profile/authors/8119823-fervavtag:nl.mathworks.com,2005:Question/2324832015-08-05T04:00:00Z2016-04-30T03:24:15ZWhy do I get a get a regexprep error when running the Support Package Installer?<p>When I run the Support Package Installer by running "supportPackageInstaller" in the MATLAB Command Window or by going to "Resources>Add-Ons>Get Hardware Support Packages" on the tool strip I get the following error message before the user interface opens:</p><p> </p><pre class="error"> Error using regexprep</pre>MathWorks Support Teamhttp://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/2817992016-04-30T03:23:51Z2016-04-30T03:23:51ZDoes the discrete cosine transform (dct command) in MatLab use the FFT algorithm?<p>Hi, I am using the Chebyshev transform and want to utilize and want to use the efficiency of FFT algorithm.
But the Chebyshev transform is actually a cosine transform. So should I use "dct" command directly or use the "fft" command in order to do a fast transform as FFT? Is the FFT algorithm included in the MatLab "dct" command? Thanks in advance for any help!</p>David W.http://nl.mathworks.com/matlabcentral/profile/authors/5382463-david-wtag:nl.mathworks.com,2005:Question/2816922016-04-29T13:49:14Z2016-04-30T03:23:06Zhow many machine can i install MATLAB ?<p>:)</p>Manh Dung Nguyenhttp://nl.mathworks.com/matlabcentral/profile/authors/7789924-manh-dung-nguyentag:nl.mathworks.com,2005:Question/2817172016-04-29T15:48:10Z2016-04-30T03:19:15ZExtract data by shapefile<p>How to extract data from nc file by using shape file in matlab. I am sending a sample .nc file of resolution 1*1 degree and shapefile of India.</p>Tanmoyee Bhattacharyahttp://nl.mathworks.com/matlabcentral/profile/authors/5313618-tanmoyee-bhattacharyatag:nl.mathworks.com,2005:Question/2817192016-04-29T15:50:37Z2016-04-30T03:18:54Zhow can i let a user fill a table in GUI? <p>i just added a table in GUI layout but i didn't know how to write a program that allow the user to enter data in the table.</p>Ahmad Baydounhttp://nl.mathworks.com/matlabcentral/profile/authors/8119746-ahmad-baydountag:nl.mathworks.com,2005:Question/2815982016-04-29T00:18:36Z2016-04-30T03:17:07ZCan I take the derivative of a complex expression?<p>I am trying to find the maximum point of the ratio of Complex polynomials. The derivative of 1/(s^2 + .4s + 1) should be zero at about w=.96 (where s=j*w). My code to find this is</p><pre class="language-matlab">syms w zz xx aa bb
aa = (w*i)^2+.4*(w*i)+1;
bb = abs(1/aa);
xx = diff(bb,w);
eval(solve(xx==0,w))
</pre><p>but it produces an incorrect answer. In an attempt get it to work, I stubbed the abs function as</p><pre class="language-matlab">syms w zz xx aa bb
aa = real((w*i)^2+.4*(w*i)+1)
bb = imag((w*i)^2+.4*(w*i)+1)
zz = 1/(sqrt(aa^2+bb^2))
xx = diff(zz,w)
eval(solve(xx==0,w))
</pre><p>Still no luck. What am I doing wrong??</p><p>If I replace one line above</p><pre> zz = 1/(sqrt(aa^2+(.4*w)^2)) </pre><p>I get the right answer. Is there a better way to get the magnitude of a complex number when working symbolically?</p>Mark Mearshttp://nl.mathworks.com/matlabcentral/profile/authors/7508930-mark-mearstag:nl.mathworks.com,2005:Question/1825902015-03-11T10:37:18Z2016-04-30T03:16:01ZForce Simulink Coder to regenerate code and rebuild a model<p>Hi,</p><p>is it possible to force the <i>Simulink Coder</i> to regenerate code and rebuild a model?
I look for a similar setting like the <b>"Rebuild"</b> option for the model references.
I would like to activate this option
and always rebuild the model independent on the changes.
It would be great if this would be available programmatically as a <b>set_param(...)</b> API command.</p><p>Thanks</p>Wojciech Przystashttp://nl.mathworks.com/matlabcentral/profile/authors/2344109-wojciech-przystastag:nl.mathworks.com,2005:Question/2817212016-04-29T16:01:51Z2016-04-30T03:15:01Zmex.h location<p>I run Matlab in RedHat Linux 6.7 64-bit.</p><p>I write a lot of C mex files that compile with
'-I/<location of Matlab>/extern/include' in the compiler options and
'#include <mex.h>' in the C code.</p><p>Now I am starting to share this with other users with their installations in different places, so the '-I' option has to be different in different labs. I am looking for some way to automate this so a common make file can be shared with all users and hopefully will not need updating when Matlab is updated to a new version. [I understand the code may sometimes need revision, but here I am only talking about the include file changing location.]</p><p>Do you have any advice how to do this? Of course I can supply a -D option from the command line when running 'make', but this is undesirable for other users to have to bother with. Or I can install an environment variable in each user's shell startup, but that would require maintenance when there is a new version of Matlab.</p><p>Ideally, Matlab would install a link to its include directory somewhere like in /usr/local/include when it installs a link to itself in /usr/local/bin.</p><p>If you have no present solution to this problem, may I ask that you transfer this question into a feature request.</p><p>Thanks,</p><p>George Reeke</p>George Reekehttp://nl.mathworks.com/matlabcentral/profile/authors/14318-george-reeketag:nl.mathworks.com,2005:Question/2817662016-04-29T19:53:01Z2016-04-30T03:09:52ZHow can I find optimum values for nonlinear system of equations?<p>I have a set of differential equations, which I already managed to solve and convert into a function handle using matlabFunction.
Now I want to find the values for k1, k2, k3 and k4 using least square method with multiple sets of data containing t, ca, cb, cc and cd (t1, ca1, cb1, cc1, cd1; t2, ca2, cb2, cc2, cd2,...) and would be grateful for some hints.</p><pre class="language-matlab">gl1='Da=-k1*a-k4*a'; gl2='Db=k1*a-k2*b'; gl3='Dc=k2*b-k3*c';gl4='Dd=k3*c+k4*a';
[ca,cb,cc,cd]=dsolve(gl1,gl2,gl3,gl4,'a(0)=a0','b(0)=b0','c(0)=c0','d(0)=d0');
a0=1; b0=0; c0=0; d0=0;
</pre><p>I already tried fsolve for only one set of values but couldn't figure it out.</p><pre class="language-matlab">t=8; cEE=[0.7; 0.05; 0.05; 0.2];
</pre><pre class="language-matlab">c=[subs(ca); subs(cb); subs(cc); subs(cd)];
</pre><pre class="language-matlab">chom=c-cEE;
chomF=matlabFunction(chom);
</pre><pre class="language-matlab">x0=[0.1 0.1 0.1 0.1]; C=fsolve(chomF,x0)
</pre><pre class="language-matlab">Not enough input arguments.
</pre><pre class="language-matlab">Error in
symengine>@(k1,k2,k3,k4)[exp(k1.*-8.0-k4.*8.0)-7.0./1.0e1;(k1.*exp(k2.*-8.0))./(k1-k2+k4)-(k1.*exp(k1.*-8.0-k4.*8.0))./(k1-k2+k4)-1.0./2.0e1;(k1.*k2.*exp(k1.*-8.0-k4.*8.0))./((k1-k2+k4).*(k1-k3+k4))-(k1.*k2.*exp(k2.*-8.0))./((k2-k3).*(k1-k2+k4))+(k1.*k2.*exp(k3.*-8.0))./((k2-k3).*(k1-k3+k4))-1.0./2.0e1;-(exp(k1.*-8.0-k4.*8.0).*(k1.*k4+k2.*k3-k2.*k4-k3.*k4+k4.^2))./((k1-k2+k4).*(k1-k3+k4))+(k1.*k3.*exp(k2.*-8.0))./((k2-k3).*(k1-k2+k4))-(k1.*k2.*exp(k3.*-8.0))./((k2-k3).*(k1-k3+k4))+4.0./5.0]
</pre><pre class="language-matlab">Error in fsolve (line 230)
fuser = feval(funfcn{3},x,varargin{:});
</pre><pre class="language-matlab">Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
</pre><p>Besides this error, I want to insert more than one set of t, ca, cb... to find k1, k2, k3, k4 that fits best.</p><p>Does anyone have an idea how to solve this problem?
Thank you!</p>Teresa Schuberthttp://nl.mathworks.com/matlabcentral/profile/authors/6596793-teresa-schuberttag:nl.mathworks.com,2005:Question/2817982016-04-30T03:05:39Z2016-04-30T03:05:39ZHow to find all possible small boxes e.g. 2x2x2 and their overlaps within a bigger NxNxN cube?<p>Given an NxNxN cube (image), how can I find all the 2x2x2 boxes within the NxNxN cube? of course if N is even, we can find 2x2x2 boxes without overlapping, but when the N is odd, there is overlapping between some of the 2x2x2 boxes found in the bigger cube.</p><p>So,</p><p>1- How can I find all the non-overlapped 2x2x2 boxes in a bigger NxNxN cube where <b>N</b> is <b>even</b>?</p><p><b>input</b>: NxNxN cube <b>output</b>: all the possible non-overlapped 2x2x2 cubes.</p><p>2- How can I find all the overlapped 2x2x2 boxes in a bigger NxNxN cube where <b>N</b> is <b>odd</b>? This time, the overlapped areas in the 2x2x2 boxes should be zero in <b>second</b> (or more) visits; i.e. each overlapped area should be visited (counted) once not more.</p><p><b>input</b>: NxNxN cube <b>output</b>: all the possible overlapped 2x2x2 cubes with zero values for the overlapped voxels in 2nd or more visits.</p>MLhttp://nl.mathworks.com/matlabcentral/profile/authors/6799604-mltag:nl.mathworks.com,2005:Question/2817972016-04-30T02:57:46Z2016-04-30T02:57:46ZWhy am I getting 2 solutions for this ODE with one set of initial values?<p>Note: I am a beginner in math and in Matlab, any additional wisdom is gratefully received.</p><p>So, I'm getting two solutions for this singular ODE, Wolfram A gets one. My y vector in</p><pre class="language-matlab">[t,y] = ode15s(...)
</pre><p>is giving me a size(t) by 2 matrix. And resulting in a plot that looks like:</p><img src = "/matlabcentral/answers/uploaded_files/51099/mWfigure.bmp"><p>Here's the equation: xy''+ y' + xy = x . My code attempt to solve it:</p><pre class="language-matlab">tspan = [1e-4 50];
[x,y] = ode15s('p2ODE',tspan,[0 1]);
plot(x,y);
</pre><p>function:</p><pre class="language-matlab">function dxdt = p2ODE( t , x )
</pre><pre class="language-matlab">y = x(1);
yPrime = x(2);
</pre><pre class="language-matlab">dy = yPrime;
dyPrime = (-1/t)*yPrime - y + 1;
</pre><pre class="language-matlab">dxdt = zeros(2,1);
dxdt(1) = dy;
dxdt(2) = dyPrime;
</pre><pre class="language-matlab">end
</pre><p>But here's Wolfram A solution samples:</p><img src = "/matlabcentral/answers/uploaded_files/51100/mWfigure1.png">Zachary Duffhttp://nl.mathworks.com/matlabcentral/profile/authors/7826342-zachary-dufftag:nl.mathworks.com,2005:Question/2817962016-04-30T02:54:22Z2016-04-30T02:55:27ZMay I ask can I change the value of the maximum amplitude of wav file and save as new wav file?<p>May I ask can I change the value of the maximum amplitude of wav file and save as new wav file? For example I want to change max1 and max2 to other value and save as other wav file after change it.</p><pre> [y,Fs] = audioread('test4.wav');
amplitudes = abs(y);
left=y(:,1);
max1 = max(abs(left));
right=y(:,2);
max2 = max(abs(right));
disp(max1);
disp(max2);</pre>loong seow lihttp://nl.mathworks.com/matlabcentral/profile/authors/7820955-loong-seow-litag:nl.mathworks.com,2005:Question/2817952016-04-30T02:53:04Z2016-04-30T02:53:04Zhow to read bytes using fread or in a matrix<p>I am using fread to open'.dat' files. The file has variables with its values displayed in matrix. Every column in assigned a variable and each column is of different length(1st column 4 bytes, 2nd column 2 bytes etc) I have tried opening 1st column but unable to open 2nd column. I would like to know how to all columns.</p>Thrinath kumar raj pandugahttp://nl.mathworks.com/matlabcentral/profile/authors/8121660-thrinath-kumar-raj-pandugatag:nl.mathworks.com,2005:Question/2817772016-04-29T21:54:59Z2016-04-30T02:51:20ZHow to find out the number of outer boundary inflexion points for a character(array)?. <p>I am performing text detection from image. I have a logical array(mxn) of a Character(letter).
How to find out the number of outer boundary inflexion points for that character?.</p>Bency Tadankihttp://nl.mathworks.com/matlabcentral/profile/authors/7936571-bency-tadankitag:nl.mathworks.com,2005:Question/1352852014-06-18T04:00:00Z2016-04-30T02:49:09ZHow do I use SAVE with a PARFOR loop using Parallel Computing Toolbox?<p>I would like to save some variables to MAT files from inside a PARFOR loop. However I get an error:</p><pre class="error"> ??? Error using ==> parallel_function at 598
Error in ==> parallel_function>make_general_channel/channel_general at 894
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency.</pre>MathWorks Support Teamhttp://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/2816062016-04-29T01:46:15Z2016-04-30T02:43:45Zuse MATLAB to transmit/receive a picture to/from FPGA<p>hello guys,
i want to transmit a picture to FPGA with a serial port and then receive the picture from FPGA.
RS232 is implemented.
the transmitter and receiver part are two PCs.
i need to write down matlab code for both transmitter and receiver.
how could i accomplish the goal?
thx for your view and hope anyone can help me</p>jzy FGGFhttp://nl.mathworks.com/matlabcentral/profile/authors/7995150-jzy-fggftag:nl.mathworks.com,2005:Question/2817922016-04-30T02:14:15Z2016-04-30T02:43:09ZHow can I read text file with number of elements in each line is different?<p>I have an input text file:</p><p>result.txt:</p><pre class="language-matlab">0
[0
0
0
3,19,24,44,47
0.17221,0.26928,0.1476,0.2485,0.16241]
</pre><p>I used load function in matlab to read it (load('result.txt')), but I couldn't. How do I read this file?</p><p>Thank for your help!</p>Yen Haihttp://nl.mathworks.com/matlabcentral/profile/authors/7720218-yen-haitag:nl.mathworks.com,2005:Question/2817652016-04-29T19:50:55Z2016-04-30T02:22:03Zhow can I plot struct <p>I have a struct that I want to convert to graph
is there any way to plot struct?</p><p>thank you</p>Meshaiel Mhttp://nl.mathworks.com/matlabcentral/profile/authors/8120789-meshaiel-mtag:nl.mathworks.com,2005:Question/2817832016-04-29T22:33:07Z2016-04-30T02:18:39ZProblems with interp3 <p>Hi everybody!:</p><p>I have a matrix whose dimensions are 512x512x56(Cube_CT), every image have a voxel whose dimensions are 0.97x0.97 (mm) and the SliceThickness is 3mm, and I need that every image has a voxel with dimensions: 0.97x0.97(mm) and the SliceThickness 1mm. My code is the following:</p><pre> [m,n,p]=size(Cube_CT);
[X,Y,Z]=meshgrid(1:m,1:n,1:p);</pre><pre> voxel_x_in=InfoCT_ord{1,1}.PixelSpacing(1);
voxel_y_in=InfoCT_ord{1,1}.PixelSpacing(2);
voxel_z_in=InfoCT_ord{1,1}.SliceThickness;</pre><pre> voxel_x_out=InfoCT_ord{1,1}.PixelSpacing(1);
voxel_y_out=InfoCT_ord{1,1}.PixelSpacing(2);
voxel_z_out=1;</pre><pre> xx=(voxel_x_out/voxel_x_in:voxel_x_out/voxel_x_in:m);
yy=(voxel_y_out/voxel_y_in:voxel_y_out/voxel_y_in:n);
zz=(voxel_z_out/voxel_z_in:voxel_z_out/voxel_z_in:p);</pre><pre> [Xq,Yq,Zq]=meshgrid(xx,yy,zz);</pre><pre> CubeCT_inter=interp3(X,Y,Z,Cube_CT,Xq,Yq,Zq,'cubic');</pre><p>But when I execute this code, all components of the first image and second image are NaN. I don't understand where is the problem.</p><p>Thanks!</p>Francisco Javier Vilchez Torralbahttp://nl.mathworks.com/matlabcentral/profile/authors/7736093-francisco-javier-vilchez-torralbatag:nl.mathworks.com,2005:Question/2311842015-07-25T19:21:54Z2016-04-30T02:13:36ZDisplay default value in the edit box in MATLAB GUI<p>Hello,</p><p>I have a MATLAB GUI which contains the edit box.The value to this edit box is entered by the user .
If the value is not entered by the user the default value has to be displayed or the previously set value has to be displayed in the edit box.
Let me know how to set the default value to the edit box and display it if no value is entered ,
also how to store the value that is set .
Previously set value has to be accessed and displayed if new value is not entered by the user.</p><p>It would be grateful if you let me know how this is done.</p><p>Looking forward to hear from you at the earliest.</p><p>Thanks</p><p>Pankaja</p>Pankaja Tanjorehttp://nl.mathworks.com/matlabcentral/profile/authors/5880940-pankaja-tanjoretag:nl.mathworks.com,2005:Question/2817912016-04-30T01:15:32Z2016-04-30T02:12:38ZHow can I solve a differential equation in which a function of time is measured and not given analytically?<p>I have to solve this differential equation: dy(t)/dt=a+by(t)+z(t). I am measuring z(t) at certain times ti and I need y(t) at the same times ti. I do not have an analytical expression for z(t). I know how to use ode45, but it does not seem to fit my needs, because ode45 requires to have an expression of z(t). Other ode-type functions seem to have the same problem to me.</p><p>Thanks</p>Walter Palearihttp://nl.mathworks.com/matlabcentral/profile/authors/8121448-walter-palearitag:nl.mathworks.com,2005:Question/2817492016-04-29T18:25:52Z2016-04-30T01:54:16Zhow to split and transpose a cell array?<p>Hi !!
I have the next cell composition (30*1 size)</p><img src = "/matlabcentral/answers/uploaded_files/51074/foto3.jpg"><p>What I want to do is to split it first, according to the "," so each different number has to occupy a diffierent column. Like this:</p><img src = "/matlabcentral/answers/uploaded_files/51075/foto1.jpg"><p>After this, I want to transpose all the numbers, so I want to have a final matrix size (7*30)</p><img src = "/matlabcentral/answers/uploaded_files/51076/foto2.jpg"><p>Can anyone help me to solve this?</p><p>Thanks in advance!</p>Viridiana Torreshttp://nl.mathworks.com/matlabcentral/profile/authors/8096132-viridiana-torrestag:nl.mathworks.com,2005:Question/2817612016-04-29T19:44:04Z2016-04-30T01:51:51ZTo RESHAPE the the number of elements must not change<p>Hello Everybody;</p><p>I am trying to convert an image which is in the form of txt file into an image</p><p>the text file is attached with this message</p><p>I am using this Matlab code for converting but still getting the problem in Reshaping,The error message is as follow ('To RESHAPE the number of elements must not change.') and i am sure the dimension is of 320*240 or 640 * 480 .</p><p>the code is</p><pre class="language-matlab">A=fopen('new1.txt','r');
I=fscanf(A,'%d ,',[1 inf]);
I=I'
format hex
X=uint8(I);
Y=typecast(X,'uint16')
Z=reshape(Y,320,240)
Z=Z';
imgR = uint8((255/31)*bitshift(bitand(Z,63488),-11)); %# Red component
imgG = uint8((255/63)*bitshift(bitand(Z,2016),-5)); %# Green component
imgB = uint8((255/31)*bitand(Z,31)); %#Blue Component
imgRGB = cat(3,imgR,imgG,imgB); %# Concatenate along the third dimension
imgfinal(:,1:192,:)=imgRGB(:,129:320,:);
imgfinal(:,193:320,:)=imgRGB(:,1:128,:);
imshow(imgfinal);
fid1=fopen('image.raw','w+');
cnt=fwrite(fid1,imgfinal,'uint8');
fclose(A);
</pre>ABDULRAHMAN ALHARAZIhttp://nl.mathworks.com/matlabcentral/profile/authors/7748480-abdulrahman-alharazitag:nl.mathworks.com,2005:Question/2817882016-04-29T23:43:45Z2016-04-30T00:20:54ZHi please any one know how to calculate Hu's Moment Invariant to compare tow images Iuse this function but I don't know if it's true or no?? and thank you<pre class="language-matlab">if true
function inv_moments = Hu_Moments(eta)
inv_moments(1) = eta(3,1) + eta(1,3);
inv_moments(2) = (eta(3,1) - eta(1,3))^2 + (4*eta(2,2)^2);
inv_moments(3) = (eta(4,1) - 3*eta(2,3))^2 + (3*eta(3,2) - eta(1,4))^2;
inv_moments(4) = (eta(4,1) + eta(2,3))^2 + (eta(3,1) + eta(1,4))^2;
inv_moments(5) = (eta(4,1) - 3*eta(2,3))*(eta(4,1) + eta(2,3))*((eta(4,1) + eta(2,3))^2 - 3*((eta(3,2) + eta(1,4))^2)) + (3*(eta(3,2) - eta(1,4)))*(eta(3,2) + eta(1,4))*(3*(eta(4,1) + eta(2,3))^2 - (eta(3,2) + eta(1,4))^2);
inv_moments(6) = (eta(3,1) - eta(1,3))*((eta(4,1)+eta(2,3))^2 - (eta(3,2)+ eta(1,4))^2) + 4*eta(2,2)*((eta(4,1) + eta(2,3))*(eta(3,2) + eta(1,4)));
inv_moments(7) = (3*eta(3,2) - eta(1,4))*(eta(4,1) + eta(2,3))*((eta(4,1) + eta(2,3))^2 - 3*(eta(3,2)-eta(1,4))^2) - (eta(4,1) - 3*eta(2,3))*(eta(3,2) + eta(1,4))*(3*(eta(4,1) + eta(2,3))^2 - (eta(3,2) + eta(1,4))^2);
M=[inv_moments(1) inv_moments(2) inv_moments(3) inv_moments(4) inv_moments(5) inv_moments(6) inv_moments(7)]';
end
</pre>olfa abdalahhttp://nl.mathworks.com/matlabcentral/profile/authors/7612176-olfa-abdalahtag:nl.mathworks.com,2005:Question/2817892016-04-30T00:03:16Z2016-04-30T00:18:27Zselecting columns by their name<p>Hi,
I use the attached test.xlsx file as an example to explain my problem.
Assume that I have the test.xlsx in excel and I want to use this to do operations on its columns. But this operation just needs to be performed on specific columns. For example I need my code to first select the numerical values in columns that have "AUD AUD_EOD" with "Zero 1d" and "AUD AUD_EOD" with "Zero9m" in their titles to be saved in a matrix A. Then do the same thing for columns with "CAD CAD_EOD" with "Zero 1d" and "CAD CAD_EOD" with "Zero9m" in their titles
and save them in matrix B and then do the operation on matrix A and B. So my problems is that, how can I do this selection without using for loops. Again as I said the test.xlxs is just a sample and I basically have a huge file that this needs to be done for it.</p><p>I appreciate any comments to solve this problem.</p><p>Thanks,</p>Lolakhttp://nl.mathworks.com/matlabcentral/profile/authors/7980095-lolaktag:nl.mathworks.com,2005:Question/2817902016-04-30T00:09:15Z2016-04-30T00:09:15Zboost::filesystem::canonical error ?<p>Hi all,</p><p>I am using matlab R2015a and I am using different codes in different paths, so I used addpath. However, when it comes to the next iteration or the path changes, Matlab gives me an error "boost::filesystem::canonical"</p><p>I was looking in the forum, but I can not find a solution yet.</p><p>Thanks</p>Nils Murrugarrahttp://nl.mathworks.com/matlabcentral/profile/authors/6140785-nils-murrugarratag:nl.mathworks.com,2005:Question/2817872016-04-29T23:29:37Z2016-04-29T23:39:16ZAverage Values in a matrix <p>I have a 100X225 matrix- I want to average [4,4] (or other) chunks of the matrix, and place that value in a new matrix: of a smaller dimension -> 100/4,225/4 etc</p><p>I can't seem to get the looping right.</p>Philip Hoskinsonhttp://nl.mathworks.com/matlabcentral/profile/authors/6716294-philip-hoskinsontag:nl.mathworks.com,2005:Question/2817712016-04-29T21:18:56Z2016-04-29T23:36:44ZHow to create a function that computes its (initialized) parameters only once?<p>What is the general technique to perform pre-computation (to compute some fixed parameters) only once?
In my instance, for example, I am solving a large Mixed Integer Linear using intlinprog, but I do not want to "construct" the "non-changing" parts of the optimization problem <tt>(some part of f,intcon,A,b,Aeq,beq,lb,ub,options)</tt>. That is, I want to write a function that calls a intlinprog but I don't want to each time construct the parts of the parameters that do not depend on the input parameter.</p><p>Saving those parameters in a mat file and loading them is a work-around. But I am wondering whether there are better systematic ways, like using function handles, or object oriented programming can do better. Thanks!</p>Armanhttp://nl.mathworks.com/matlabcentral/profile/authors/6656728-armantag:nl.mathworks.com,2005:Question/2817862016-04-29T23:22:33Z2016-04-29T23:22:33ZHow can I use the smooth function a specified number of times on a dataset?<p>So I have some really noisy data and I am trying to smooth it, however just using the smooth function once or at least 30 times isn't doing the trick. I am trying to write a function that smooths the data and then smooths that data and so on however many times I ask it to. Can anyone help?</p>Peter Burlingamehttp://nl.mathworks.com/matlabcentral/profile/authors/7552173-peter-burlingametag:nl.mathworks.com,2005:Question/2583742015-12-01T12:44:10Z2016-04-29T23:22:21ZSimcoupler with Matlab/Simulink <pre> I run simcoupler in matlab, i have this eror
'Cannot find an exact (case-sensitive) match for 'PsimDialog'</pre><p>The closest match is: PSimDialog in C:\Program
Files\MATLAB\R2013a\toolbox\simulink\SimCoupler\PSimDialog.m</p><p>Error using struct2handle
Error while evaluating uicontrol CreateFcn</p><p>Cannot find an exact (case-sensitive) match for 'PsimDialog'</p><p>The closest match is: PSimDialog in C:\Program
Files\MATLAB\R2013a\toolbox\simulink\SimCoupler\PSimDialog.m</p><p>Error using struct2handle
Error while evaluating uicontrol CreateFcn'</p>Mehdi Ouadahttp://nl.mathworks.com/matlabcentral/profile/authors/3560117-mehdi-ouadatag:nl.mathworks.com,2005:Question/2817852016-04-29T23:13:13Z2016-04-29T23:13:13ZHow to import C++ library CGAL On Simulink S-Function Builder?<p>I need to perform a real-time optimization in Simulink. This optimization will be a quadratic programming that will use data collected from an electromechanical system.</p><p>From what I found in the documentation, the only way is to use a C / C ++ S-Function, and for that I will need external libraries that perform optimization and other mathematical operations between arrays. Basically matrix multiplication.</p><p>I found the CGAL and Armadillo libraries that suit that need.</p><p>CGAL installed the library by using the steps in the documentation (<http://www.cgal.org/download/windows.html)>. She ran for Visual Studio and managed to compile the final .dll files. But when using the include (#include <a href = "CGAL">/ QP_models.h</a>) in the s-function builder the library is not found:</p><p> </p><pre class="language-matlab">CGAL / QP_models.h: No such file or directory
#include <CGAL / QP_models.h>
^
compilation terminated.
</pre><p>I also added the path to the library in the "custom code" of Simulink, Simulink but is not able to find.</p><p>As such inclusion is made?</p>Erbet Costahttp://nl.mathworks.com/matlabcentral/profile/authors/1679815-erbet-costatag:nl.mathworks.com,2005:Question/2817842016-04-29T23:04:46Z2016-04-29T23:04:46ZProblem with fitting exponential using lsqnonlin<p>I am trying to fit some data (attached) using an equation of the form</p><p>y = t(1)*exp(-x/t(2)) + t(3)</p><p>However, my code:</p><pre> ub = [inf 1 inf ];
lb = [-inf 1e-5 -inf ];
t0 = [1/2 1/2 40 ];
fun_lsq = @(t)(t(1)*exp(-x/t(2)) + t(3) - y);
fun = @(t)(t(1)*exp(-x/t(2)) + t(3) );
t = lsqnonlin(fun_lsq,t0, lb, ub);</pre><p>Doesn't seem to fit the data very well, and I think this is because the lsqnonlin function doesn't change the inital guess for the time constant term t(2) very much:</p><pre> initialguess: [0.5000 0.5000 40]
fitparam: [7.5671e-10 0.4700 -5.4190e-10]</pre><p>Does anyone have a way to produce a better fit?</p>Suzanne Sotohttp://nl.mathworks.com/matlabcentral/profile/authors/5721363-suzanne-sototag:nl.mathworks.com,2005:Question/2817702016-04-29T21:05:16Z2016-04-29T23:01:07ZHow to extract human contrast out of any given image?<p>Hi, Im trying to extract a human contrast out of any given image. That is, to recieve an image from the user and to create a new image of the silhouette only. I have used some of the tools from the image processing tools, but I have not managed to write something that will work for more then one image. Do you have any suggestions for a good strategy?
Ben</p>Ben Titlehttp://nl.mathworks.com/matlabcentral/profile/authors/7490250-ben-titletag:nl.mathworks.com,2005:Question/2817312016-04-29T17:00:42Z2016-04-29T22:47:48ZUsing a method size in a Class without making class objects it into an array<p>Hi!</p><p>I'm working with a class with a property data and want to construct a method that checks the size of the data: NewClassObject.size. However when I implement this the object becomes an 'array', which seems to change how my subsref indexing () works:</p><p>without size():</p><pre> NewClassObject = </pre><pre> NewClass with properties:
...</pre><p>with size():</p><pre> NewClassObject = </pre><pre> 5x1 NewClass array with properties:
...</pre><p>Is there anyway to name a method size without anything else changing?</p><p>The class is too big to post here and I have no good way of reducing it at the moment. But maybe some of you might have an answer anyway?</p><p>Thanks!</p><p>Cecilia</p>Ceciliahttp://nl.mathworks.com/matlabcentral/profile/authors/3281074-cecilia