http://www.mathworks.de/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-10-23T07:59:44Ztag:www.mathworks.de,2005:Question/1597832014-10-23T07:59:44Z2014-10-23T07:59:44ZHow to delete specific lines from a txt file?<p>Hello, this is my problem:
Background: I am comparing 2 files that should match in the first column but one of the files skips some numbers, suppose (12,12), (13,13), (14,15)*, so until now I have use a code to find and display the mismatches on the screen and I manually delete the excess rows in the complete file and rerun the code until everything matchs.
Problem: Now usually I have used this with small files not correcting more than 10 mismatches, the problem is that I have a big data set with over 1000 of mismatches, so I need a way to delete the complete row of the "leftovers" in the txt file. Next is shown my coding:</p><p>%r is the number of total rows
%the first part is made for fileA and fileB storing in E and G matrices
fid = fopen('fileA.txt');
num_ints = 23;
num_rows = r;
format = [repmat('%f ', 1, num_ints)];
G = textscan(fid, format, num_rows);
G = [G{1:num_ints}];
fclose(fid);</p><p>for a = 1:1:r
if (E(a,1)~=G(a,1));
disp(E(a,1));
break
end
end
disp ('End of search');</p><p>As always thank you for your help!</p>Mario/matlabcentral/answers/contributors/4238010-mariotag:www.mathworks.de,2005:Question/1591052014-10-18T07:55:12Z2014-10-23T07:58:00ZI have a time domain signal.I want to calculate energy of my signal......<p>Suppose my signal is X(t)
then I want to get Fourier Transform >>> X(f)
and then I want to calculate energy of my signal...</p><p>Can anyone help me?
Thank you so much</p>vahid torabi/matlabcentral/answers/contributors/5483934-vahid-torabitag:www.mathworks.de,2005:Question/1595292014-10-21T14:49:43Z2014-10-23T07:42:52ZError installung Peak CAN Support Package<p>While installing I get the following error:</p><pre class="language-matlab">Error installing third party software PEAK-System PCAN-Basic:
Error executing command
"vnt.supportpackages.peaksystem.setup.installdll('C:\MATLAB\SupportPackages\R2014a\downloads\peaksystem_download', 'pcan-basic', 'pcan-basic.zip')"
</pre><pre class="language-matlab">Access denied
</pre><p>And on the matlab console</p><p>Warning: File 'C:\Windows\SysWOW64\PCANBasic.dll' not found.</p><pre class="language-matlab">> In C:\MATLAB\SupportPackages\R2014a\peaksystem\+vnt\+supportpackages\+peaksystem\+setup\removedll.p>removedll at 12
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+util\evaluateCmd.p>evaluateCmd at 58
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.uninstallThirdPartyPackage at 2125
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.uninstallTpPkgs at 1433
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.install at 1176
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.installRecursiveImp at 742
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.installRecursive at 599
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>installFromFolder at 278
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>installWorkflow at 204
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>executeConfirm at 68
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\Step.p>Step.next at 169
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>@(varargin)hStep.next(varargin{:}) at 35
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+util\+download\MWDownloadManager.p>MWDownloadManager.fireMethod at 388
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+util\+download\MWDownloadManager.p>MWDownloadManager.initCallback/serviceCallback at 363
In hgfeval at 62
In uitools\private\javaaddlistener>cbBridge at 52
In uitools\private\javaaddlistener>@(o,e)cbBridge(o,e,response) at 47
Warning: File 'C:\Windows\System32\PCANBasic.dll' not found.
> In C:\MATLAB\SupportPackages\R2014a\peaksystem\+vnt\+supportpackages\+peaksystem\+setup\removedll.p>removedll at 14
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+util\evaluateCmd.p>evaluateCmd at 58
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.uninstallThirdPartyPackage at 2125
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.uninstallTpPkgs at 1433
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.install at 1176
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.installRecursiveImp at 742
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\PackageInstaller.p>PackageInstaller.installRecursive at 599
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>installFromFolder at 278
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>installWorkflow at 204
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>executeConfirm at 68
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\Step.p>Step.next at 169
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+internal\executeConfirm.p>@(varargin)hStep.next(varargin{:}) at 35
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+util\+download\MWDownloadManager.p>MWDownloadManager.fireMethod at 388
In C:\Program Files\MATLAB\R2014a\toolbox\shared\hwconnectinstaller\+hwconnectinstaller\+util\+download\MWDownloadManager.p>MWDownloadManager.initCallback/serviceCallback at 363
In hgfeval at 62
In uitools\private\javaaddlistener>cbBridge at 52
In uitools\private\javaaddlistener>@(o,e)cbBridge(o,e,response) at 47
</pre><p>How do I fix this?</p>Nico/matlabcentral/answers/contributors/5048109-nicotag:www.mathworks.de,2005:Question/1597702014-10-23T04:36:26Z2014-10-23T07:42:06ZHelp vectors size doesn't match...why?<p>This is my code to evaluate Lagrange where x_in are the given interpolation points and x_out is suppose to be f(x_in), but it keeps saying x_in and x_out don;t have the same vector length</p><p>x = -1:50;
y = 1.0 ./ (1+9*x.^2);
x_in=linspace(-1,1,100);
x_out=(1.0) ./ (1+9*(x_in).^2);
y_out=make_Ln(x,x_in,x_out);
plot(x,y,':',x_in,y_out,'*');
title('Lagrange Interpolation:x_in=linspace(-1,1,100)')
legend('y','Interpolation');
figure;</p>cakey/matlabcentral/answers/contributors/5481550-cakeytag:www.mathworks.de,2005:Question/1597792014-10-23T07:18:44Z2014-10-23T07:38:24Zhow do i find a mean value from a 10X10 matrix ?<p>hi can any one help me on how to fine the mean value from a 10x10 matrix ?</p>philip/matlabcentral/answers/contributors/5726200-philiptag:www.mathworks.de,2005:Question/1597812014-10-23T07:30:59Z2014-10-23T07:30:59ZHow can I do a Simple Object detection?<pre> 0 down vote favorite
</pre><p>I have a very simple problem I need to solve: my input will be a picture of an object, with a white background (keep in mind that the object may be of any color, including white). The only thing I need to do is to determine if this object is in fact a bottle. Note that it has to be of the shape of a limited kind of bottles, I have my image set of accepted shapes, it does not matter what kind of label it has or any other detail, as long as it has the shape of a bottle.</p><p>I have been looking into various algorithms, such as the Generalized Hough Transform for arbitrary shapes, Template matching, Bag of Features, etc. All of these seem to complicated it for my problem.</p><p>Basically, all I need is my algorithm to be able to tell me if the input image is a bottle or not, based on my set of possible shapes.</p><p>My main problem for using another sort of solution such as template matching is because the bottle could be of many different shapes, like in Bag of Features (<http://www.mathworks.com/help/vision/examples/image-category-classification-using-bag-of-features.html>) where the set is trained to recognize when you find an specific object according to the existing image sets, however I have no need to create multiple categories because I only have one. I don't think it would be efficient to implement such a robust solution as Bag of Features if I will only have one category.</p><p>Is anyone familiar with another simple training algorithm that could help me?</p>Cdz/matlabcentral/answers/contributors/5756722-cdztag:www.mathworks.de,2005:Question/1597802014-10-23T07:30:20Z2014-10-23T07:32:40ZParameters estimation in a probabiility function<p>Hi,</p><p>I have a pdf function f(x,a), where x in {x1, x2} represents coordinates and a in {a1,a2} represents two parameters. By changing the parameters it´s possible to change the shape of the function. This function doesn't have any analytic form, so consider it numerical</p><p>I have furthermore 45 experimental data lets say xe={xe1,xe2} which can be described by a known pdf, let's say fe(xe,ae), where xe in {xe1, xe2} represents coordinates and ae in {ae1,ae2} represents two parameters. The parameters can be estimated by known methods.</p><p>I'm trying to find the following:</p><ol><li>Item one an estimation of {a1,a2} based on the experimental data xe, and as a consequence f(x,a)</li><li>Item two comparison of f(x,a) with fe(xe,ae) and see the differences</li></ol><p>I don't know where to start from. Could anybody give me some directions? Books, links etc are very welcome.</p>Symeon Mattes/matlabcentral/answers/contributors/3273590-symeon-mattestag:www.mathworks.de,2005:Question/1527162014-08-29T02:24:53Z2014-10-23T07:26:29ZExtract a sphere out of a cube<p>Hello,
I have been working with points with specific distances and angles between them, because this properties are constants I can reproduce a large bulk of points, the problem is that so far I can only generate cuboids.
What I need is to extract a sphere of a cube maintaining the location of the points, the easiest way that I can think of is something like define a sphere and cut-off the points outside of it, but I have no idea how to do that, any hint is very welcome.</p><p>Thank you</p>Mario/matlabcentral/answers/contributors/4238010-mariotag:www.mathworks.de,2005:Question/1597382014-10-22T21:33:12Z2014-10-23T06:57:41ZHow to find something that you're not looking for?!<p>Hey everyone!</p><p>So I haven written a couple matlab codes to predict the future values of some time series. Within those codes i need the following command:</p><pre> start=datenum(2011,01,01,0,0,0);
finish=datenum(2011,31,12,23,0,0);
a=find(date==start);
b=find(date==finish);</pre><p>The vector "date" contains dates and I want to find the exact position of the dates that I have assigned to the variables start and finish.
However depending on the data I am using, sometimes there are some gaps within the dates in vector "date". For example vector "date" contains all dates from 01-01-2009 until 12-31-2013 but the dates from 12-28-2011 to 01-05-2012 are missing. Consequently if I ran this code, I would get the index of my start date (assigned to variable a) but the index of my finish date (assigned to variable b) is empty.</p><p>Is there any way to determine the closest match to the date I am looking for? For example in this case I would want matlab to tell me the exact position of the date 12-28-2011 within the vector "date" if it cannot tell me the position the the date "finish".</p><p>I would be grateful for any ideas how to work around this. Restructuring the vector "date" and filling it with the missing dates is no solution for me at the moment...</p><p>Thank you so much!!</p>MC3105/matlabcentral/answers/contributors/5543488-mc3105tag:www.mathworks.de,2005:Question/1597782014-10-23T06:55:17Z2014-10-23T06:55:17Z block diagram of doubly fed induction machine(DFIM)<p>please give me some reference for DOUBLY FED INDUCTION MACHINE</p>stalin samuel/matlabcentral/answers/contributors/5200170-stalin-samueltag:www.mathworks.de,2005:Question/1595812014-10-21T22:10:18Z2014-10-23T06:54:59ZStateflow DEMO license problem<p>For a period of time I ran a DEMO license of the Stateflow tool kit. I came to the conclusion that I did not use it extensively enough to decide to purchase the tool kit. So prior to the DEMO license running out, I replaced all of the Stateflow blocks with simple matlab functions that accomplished the same task of simple state transitions. The idea was to remove the need for the Stateflow tool kit. When the DEMO license finally expired, I started getting errors that stated a Stateflow license could not be checked out. I know for sure the models do not use any of the Stateflow blocks, but there seems to be some "Stateflow residue" in in the model requiring the license. Has anyone else experienced this problem? The only work around I have right now is to completely start over with a new model which completely unexceptionable.</p>Eric/matlabcentral/answers/contributors/5037957-erictag:www.mathworks.de,2005:Question/1597522014-10-23T00:25:59Z2014-10-23T06:53:19Z为什么我在Yosemite上安装MatlabR2011a Student 时，提示我To view this web content, you need to install the Java Runtime Environment.<p>如题，但是我明明已经安装了JRE 8，请问该如何解决</p>Anqi/matlabcentral/answers/contributors/2854209-anqitag:www.mathworks.de,2005:Question/1597732014-10-23T05:16:59Z2014-10-23T06:47:48ZCalculator by matlab sin, cos, tan<p>Hi I have made a new GUI in matlab for a calculator.
The calculator is fully working exept there is an error with the sin, cos and tan buttons.
If i click one of them i get this error:</p><p>Error in
@(hObject,eventdata)calculator('pushbutton13_Callback',hObject,eventdata,guidata(hObject))</p><p>Error while evaluating uicontrol Callback</p><p>I think i made an error in the pushbutton code, just not sure whats the error</p><p>I have attached the m file for the calculator pluss the figure.</p>Gry/matlabcentral/answers/contributors/4949822-grytag:www.mathworks.de,2005:Question/1596452014-10-22T11:33:18Z2014-10-23T06:43:14ZThe variable g in a parfor cannot be classified..<p>Can anyone help me with this?</p><pre> parfor j=1:N
z1r=normrnd(Z1(1),Z1(2)); %Random sample from distribution of Z1
z2r=normrnd(Z2(1),Z2(2)); %Random sample from distribution of Z2
for i=1:size(T,2)
g(i)=Threshold-M(i,1)-(sqrt(lambda1)*V1(i)*z1r)-(sqrt(lambda2)*V2(i)*z2r);
if g(i)>0 %safe
IND(i,j)=0;
else %failure
IND(i,j)=1;
end
end
end</pre>theodor/matlabcentral/answers/contributors/847279-theodortag:www.mathworks.de,2005:Question/1595402014-10-21T16:15:08Z2014-10-23T06:41:47ZHow to solve the problem of errors autocorrelation in ARMA model? What is the fastest way to find the best fit ARMA model?<p>Hey I am writing thesis on time series, but the ARMA model that I created seems doesn't work perfectly. For example I got an ARMA(1,1) model for Nikkei 225, however when I test the model errors, it still have auto-correlation for the 1st lag.</p><p>Does anyone know how to solve the problem of errors autocorrelation in ARMA model? What is the fastest way to find the best fit ARMA model?</p><p>Thanks a lot!</p>Zihao/matlabcentral/answers/contributors/5796037-zihaotag:www.mathworks.de,2005:Question/1597772014-10-23T06:35:10Z2014-10-23T07:39:20ZWhy does legend patch turn black when using saveas?<p>Hi, I have a problem with the function <tt>saveas</tt> in matlab. The problem appears when I create a legend for more than one graph (eg 2 line graphs) in an image and then uses <tt>saveas</tt> on the figure. The problem is that when I try to use <tt>saveas</tt> (or <tt>publish</tt>, which uses <tt>saveas</tt>) on the image and the legend patch (the object named rectangle) is set to white, the patch turns black in the image (for me a .png image).</p><p>What I think problem is that since I wanted to set the rectangle in the legend object to semi-transparent I had to remove the box and this causes some problems. The details will be seen in the example code. I am not sure whether there is a problem for all types of images, but I know it is at least a problem for .png images.</p><p><b>Example code:</b></p><pre class="language-matlab">publish('testScript');
</pre><pre class="language-matlab">function testScript()
figure;
plot(1:10,2:11,1:10,1:10,'r','LineW',2);
legend({'leg1','leg2'});
setLegendAlpha(0.9);
</pre><pre class="language-matlab">function setLegendAlpha( alphaValue )
hleg=findall(gcf,'tag','legend');
set(hleg,'box','off');
ch=findall(hleg,'type','axes');
ah=annotation('rectangle',get(ch,'position'));
set(ah,'facecolor','w','facealpha',alphaValue);
uistack(hleg,'top');
</pre><p>I am not sure if this problem is due to some error in the code in the function <tt>setLegendAlpha</tt> or if it is a bug. Also, if someone knows a workaround that does not cause the legend background to turn black when saving with <tt>saveas</tt> I would be happy. I can add that this problem cannot be seen in the figure and if I save it using <b>file->save</b> this problem is not seen either.</p><p>Matlab 2014a, windows 7</p>Patrik Ek/matlabcentral/answers/contributors/4360637-patrik-ektag:www.mathworks.de,2005:Question/1597762014-10-23T06:30:17Z2014-10-23T06:30:17ZDifference twi blocks of images?<p>How can I extract a block of pixels from an image and subtract it with another block of different image with using blockproc? my block size is 8. How do I proceed with this?</p>Emmanuel/matlabcentral/answers/contributors/4160343-emmanueltag:www.mathworks.de,2005:Question/1596232014-10-22T08:26:27Z2014-10-23T06:22:19ZHow to sort even and odds elements in an array or vector recursively?<p>Hi,</p><p>I am trying to sort an array of 1xN in different odd and even arrays till the length last array =4
for example:
X=1:32;
N=length(X)
m=log2(N);</p><p>for i=1:m</p><p>A=X(1,1:2:end); %for odd bits
B=X(1,2:2:end); %for even bits
X=A;</p><p>if l=4
break
end</p><p>a=B(1,1:2:end); %for odd bits
b=B(1,2:2:end); %for even bits
B=a;
end</p><p>i m getting output for X=1:16 but if I increase length of X to N then its is not working; for X=1:32, I am getting only odd values</p><p>i want the o/p as
[1 9 17 25 5 13 21 29 3 11 19 27 7 15 23 31 2 10 18 26 6 14 22 30 4 12 20 28 8 16 24 32]</p><p>In my code it is considering odd bits only. I want to do this for N bit but my loop is not working in that case. Please help me out</p><p>Thanks in advance</p>sachin gawande/matlabcentral/answers/contributors/5804179-sachin-gawandetag:www.mathworks.de,2005:Question/1597742014-10-23T05:44:37Z2014-10-23T06:16:29Zhow to compare two matrix by hamming distance?<p>hello -
i have two matrix A&B,both are (60*40), i have calculated hamming distance for each, and i want to compare the hamming distance for both of them and exchange the rows which have smaller hamming distance form A with the rows which have higher hamming distance.
how to do this?</p>janny/matlabcentral/answers/contributors/5787430-jannytag:www.mathworks.de,2005:Question/1597752014-10-23T05:53:00Z2014-10-23T06:15:04ZHow will i solve this problem? "Index exceeds matrix dimensions". My code is given below<pre> H = zeros(nfft21,1);
A = zeros(Q,1);
aq2bq = zeros(Q,2*fband+1);
for q = 1:Q
aq2bq(q,:) = q*(f0bin-1)+1-fband : q*(f0bin-1)+1+fband;
numerator = sum( Y(aq2bq(q,:)).'.*conj(E(aq2bq(q,:))) );
denominator = sum( abs(E(aq2bq(q,:))).^2 );
A(q) = numerator/denominator;
H(aq2bq(q,:)) = A(q)*ones(2*fband+1,1);
end</pre>Santhiya Durai/matlabcentral/answers/contributors/5777938-santhiya-duraitag:www.mathworks.de,2005:Question/1583632014-10-12T18:52:35Z2014-10-23T06:13:24ZCalculating div(grad(u)) and a line integral from pde solution<p>Dear experts,</p><p>I imported a solution of -div(grad(u))=f(u) from the pde app. I would like to do 2 things:</p><p>1. re-calculate d^2u/dx^2+d^2u/dy^2 for checking the solution</p><p>2. calculate an integral of form int g(u,du/dx,du/dy) dy along a line where x=0.</p><p>For both of these tasks, the (brute force) solutions I came up with utilizes pdegrad, tri2grid and pdeprtni a lot.</p><p>For 1. I calculate the derivatives with pdegrad, map solution to nodes with pdeprtni and pdegrad again.</p><p>For 2. I calculate derivatives with pdegrad, map to square mesh with tri2grid and integrate with trapz.</p><p>Unfortunately, all this estimation introduces error. Can anyone suggest a more straightforward & accurate way of doing this?</p><p>Thanks!</p><pre> Can anyone suggest a more strayou suggest</pre>Hanne/matlabcentral/answers/contributors/3402644-hannetag:www.mathworks.de,2005:Question/1597692014-10-23T04:18:56Z2014-10-23T06:11:28ZHow to plot certain columns and rows from matrix<p>if I have a matrix that is 33x120,
how would you plot the first 3 rows vs. columns 25-35?</p><p>I'm having trouble figuring out how to come out with the coding</p><p>thanks</p>Joshua/matlabcentral/answers/contributors/5682718-joshuatag:www.mathworks.de,2005:Question/1223192014-03-20T02:40:07Z2014-10-23T05:55:39ZI have image processing toolbox 8.3 but still "imfindcircles" don't work. What can I do ?<p>I need to detect circles in real time video for my project.</p><p>But every time I am trying to run "imfindcircles" function on my PC, I have encountered the following error.
I have <b>tried MATLAB 2012a, 2012b & 2013a</b> for only this function but no result.</p><p><b>Even the example in the MATLAB help don't run!</b>.</p><p>The error is:</p><p>Undefined function 'chaccum' for input arguments of type 'double'.</p><p>Error in imfindcircles (line 170)
[accumMatrix, gradientImg] = chaccum(A, radiusRange,
'Method',method,'ObjectPolarity', ...</p><p><b>Please help me out</b></p>Khairul Bashar Syed/matlabcentral/answers/contributors/5165935-khairul-bashar-syedtag:www.mathworks.de,2005:Question/1420752014-07-16T12:25:31Z2014-10-23T05:46:19ZHow to plot a trapezoidal pulse in Matlab?<p>I want to plot a trapezoidal pulse that has user defined rise time and fall time i.e. slope of the edges of the trapezoid can be set by me.</p>ANWESHA/matlabcentral/answers/contributors/5337265-anweshatag:www.mathworks.de,2005:Question/1592162014-10-19T13:02:57Z2014-10-23T05:40:11Zhow to calculate hamming distance between vectors in matrix<p>i try this code as:</p><pre class="language-matlab">a = [1 0 1 0 1;
0 1 1 1 0;
1 1 0 0 1];
</pre><pre> D = pdist(a,'minkowski',1)</pre><p>the answer came as: 4 2 4
while it should be : 0 4 4
how to solve it?
and to make run for bigger matrix as (50x30)</p>utm/matlabcentral/answers/contributors/5786784-utmtag:www.mathworks.de,2005:Question/1591322014-10-18T14:40:06Z2014-10-23T05:07:24ZPrediction Problem using NARX neural network <p>I would like to conduct the multistep prediction by using NARX network. The network is trained. However, I am confused how to use it to predict the next values.</p><p>For example, output y(t+1) can be predicted by the trained network. However, in order to predict y(t+2), I need y(t+1) and u(t+1) (external input). But I did not know u(t+1) either. Should I predict u(t+1) first of all?</p><p>Thanks for answering</p>Cong/matlabcentral/answers/contributors/4659513-congtag:www.mathworks.de,2005:Question/1597062014-10-22T17:20:33Z2014-10-23T04:51:48Z I need the code for Contourlet transform to find contours in images<p>I am doing project in medical image processing. i need matlab code to detect contours in image using contourlet transform. if anyone knows help me....</p>anees/matlabcentral/answers/contributors/4693502-aneestag:www.mathworks.de,2005:Question/1596482014-10-22T11:41:26Z2014-10-23T04:35:47ZConvert Hexadecimal value to signed integer<p>Hi,
I have a .bin file in which data is stored in hexadecimal format. I want to do the following:</p><p>1. Read the hexadecimal data from the .bin file.</p><p>2. Convert the data into signed integer. For instance, if we have FF5C in the file, I want to read it and convert it into its corresponding signed integer representation which is -164.</p><p>Could anyone please show me the code to do so. Thank you in advance.</p>Aresh Dadlani/matlabcentral/answers/contributors/5715616-aresh-dadlanitag:www.mathworks.de,2005:Question/1594842014-10-21T10:03:43Z2014-10-23T04:33:21ZInput data structure for classification NN<p>Hi, I am trying to perform image classification with a neural network. I have troubles formatting my input and I would like your advice :
My input consists of pixel clusters in an image. There are 3 clusters from every sample and each of them consists of a matrix with their coordinates. (each cluster is a collection of edges from my original image) It is a multiclass classification problem with 8 target classes.
I am trying to understand how to format them so they could be used as my input vectors but looking at examples has not helped very much. Any advice? (Perhaps represent these areas as a bitmap? like in the character recognition example? <a href = "http://www.mathworks.com/help/nnet/examples/character-recognition.html">here</a> )</p>S/matlabcentral/answers/contributors/3455863-stag:www.mathworks.de,2005:Question/1592762014-10-19T22:42:58Z2014-10-23T04:27:20Zhow to forecast with nonlinear autoregressive neural networks<p>Hello,</p><p>I am trying to generate an n-step ahead out of sample forecast for a NAR-ANN.</p><p>I used ntstool, Matlab GUI based interface for neural networks, to create a non-linear auto-regressive (NAR) model. I choose this model because I wanted to forecast a series based upon its own past values. Also, ANNs supposed to have better predictive accuracy than ARIMA models.</p><p>I imported data for my yt1 variable.</p><p>When I opened the ntstool, I choose NAR, i imported my data, I used the default training, testing and validation settings, i specifed 1 delay and 10 neurons.</p><p>My code in the script file was as follows.
targetSeries = tonndata(yt,true,false);
feedbackDelays = 1:1;
hiddenLayerSize = 10;
net = narnet(feedbackDelays,hiddenLayerSize);
[inputs,inputStates,layerStates,targets] = preparets(net,{},{},targetSeries);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
view(net)</p><p>I am satisfied with my results, but I want to generate a 20 step ahead forecast. Does any one know how this is done for NAR-ANNs?</p>Don Charles/matlabcentral/answers/contributors/5792818-don-charlestag:www.mathworks.de,2005:Question/1597192014-10-22T18:30:33Z2014-10-23T04:19:30Zhow to normalize a matrix?????<p>hello everyone...
i need a code to normalize( between 0 and 1) a matrix 7*50. the normalization process should be for each column not row**. in other words, the program should seek for the largest value in each column and divide all the elements in that column by it.
can anybody help plzz</p>abdulkader helwan/matlabcentral/answers/contributors/4753564-abdulkader-helwantag:www.mathworks.de,2005:Question/1592232014-10-19T14:34:51Z2014-10-23T04:19:07ZIs there a maximum number of delays?<p>Hi, May i know whether there is any maximum number of delays i can have for neuron networks time series tools?</p>WT/matlabcentral/answers/contributors/5646906-wttag:www.mathworks.de,2005:Question/1594882014-10-21T11:01:21Z2014-10-23T04:07:59Zproblem with cellular automata code?<p>i found this code here, and i try to initialize it with [1 0 1 1 0 1 1] but it didn't work.</p><p><a href = "http://www.mathworks.com/matlabcentral/fileexchange/39492-ca-code-for-matlab/content/wolfram.m">http://www.mathworks.com/matlabcentral/fileexchange/39492-ca-code-for-matlab/content/wolfram.m</a></p><p>the code is long to paste it here.
and how to locate the image?</p>sara/matlabcentral/answers/contributors/5790085-saratag:www.mathworks.de,2005:Question/1597682014-10-23T04:02:29Z2014-10-23T04:07:03ZWhat loop should I use for this? A stepsize as an input of a function<p>My current function is:</p><p>.
.</p><img src = "/matlabcentral/answers/uploaded_files/19884/fucntion.jpg"><p>.</p><p>x is supposely to run from 765 to 805 with myself individually keying in the step size</p><p>X Eg. 765 -> 770 -> 775 -> 780 .... (step size: 5)</p><pre> 765 -> 767 -> 769 -> 771 .... (step size:2)
.
.
.
765 -> 765.1 -> 765.2 -> 765.3 (step size:0.1)</pre><p>.</p><p>is repetitive procedure.</p><p>So Im thinking of changing X as the input of step size and 765 to 805 already implemented in the function. But Im foreign to the command of loops.</p><p>Anyone can help? Will greatly appreciate it!
Thanks!</p>ZONG YI Ng/matlabcentral/answers/contributors/5751907-zong-yi-ngtag:www.mathworks.de,2005:Question/1597672014-10-23T03:53:05Z2014-10-23T03:53:05ZHow do I find the intersection area of two bathymetry grid?<p>Hi,</p><p>I have two bathymetry with different sizes.</p><p>My task is to</p><p>FIRST, find the intersected area of these two bathymetry.</p><p>p/s: Please find attached image for the illustration of my task in case I'm bad at describing it. I need to find the minimum and maximum x and y values that intersected, and from there, I've got values to define my range. Next, the shaded area in the picture contains z-values from both files that I need to subtract in order to see the difference in water level.</p><p>SECOND, define a new range and spacing</p><p>THIRD, subtract my z-values within the intersected area.</p><p>FOURTH, plot</p><p>So, I'm stuck at the subtraction part because I have different size matrices.</p><p>The following is my code</p><p>a=load('com_2014.txt');</p><p>b=load('com_2011test2.txt');</p><p>% FIND THE XY MIN AND MAX VALUES OF EACH VARIABLE</p><p>xminmin=[min(a(:,1));min(b(:,1))];</p><p>xmin=max(xminmin);</p><p>% X MAX</p><p>xmaxmax=[max(a(:,1));max(b(:,1))];</p><p>xmax=min(xmaxmax);</p><p>% Y MIN</p><p>yminmin=[min(a(:,2));min(b(:,2))];</p><p>ymin=max(yminmin);</p><p>% Y MAX</p><p>ymaxmax=[max(a(:,2));max(b(:,2))];</p><p>ymax=max(ymaxmax);</p><p>% FIND THE INDICES BETWEEN XY MIN AND MAX</p><p>% FOR MATRIX a</p><p>aInd=find((a(:,1)>=xmin) & (a(:,1)<=xmax) & (a(:,2)>=ymin) & (a(:,2)<=ymax));</p><p>xa=a(aInd,1);</p><p>ya=a(aInd,2);</p><p>za=a(aInd,3);</p><p>% FOR MATRIX b</p><p>bInd=find((b(:,1)>=xmin) & (b(:,1)<=xmax) & (b(:,2)>=ymin) & (a(:,2)<=ymax));</p><p>xb=b(bInd,1);</p><p>yb=b(bInd,2);</p><p>zb=b(bInd,3);</p><p>And I'm stuck after this. HELP! URGENT!!!</p><p>Thanks!!!!!!!!</p>eevee/matlabcentral/answers/contributors/3069006-eeveetag:www.mathworks.de,2005:Question/1597662014-10-23T03:42:44Z2014-10-23T03:42:44Zcapacitance for different geometries of conductors<p>Hi...I wanna calculate capacitance for single electron transistor in which my model is like there is a dot (circular conductor) between two rectangular conductors (left, right) and one rectangular conductor on top of that dot. Is there any easy way to get capacitance matrix for such system in matllab? All of conductors are of size in range of nm. can anybody help me?
thanks</p>Maria/matlabcentral/answers/contributors/5678935-mariatag:www.mathworks.de,2005:Question/1597652014-10-23T03:30:26Z2014-10-23T03:30:26ZHow to run multiple programs<p>Hi,</p><p>Anybody know a code to run (say) 3 programs one after another without having to give a command to run each program please?</p><p>What I want is something like the following</p><p>For i=1:3</p><p>test(i).m;</p><p>end</p><p>Thanks</p>dav/matlabcentral/answers/contributors/3693465-davtag:www.mathworks.de,2005:Question/1597642014-10-23T03:28:55Z2014-10-23T03:52:34ZHow to determine equation of curves through points in a script?<p>Hi everyone,</p><p>I have a lot of arrays of x-y coordinates of points which curves pass through. I want to determine the point of tangency between a line and a curve. So I need to specify the equation of curves. The number of the curves is not specified, so I can't use Curve Fitting Tool box.</p><p>To smooth the curve I also use interp1('pchip') to make interpolated points. In another way, could I save the interpolated results by interp1 as an equation?</p><p>Could someone tell me how to do it in a script?</p><p>X-Y Coordinates: (1st row is Y coordinate, 2nd is X coordinates)</p><pre class="language-matlab">curve1=[515 525 561 600 632 700 761 800 900 1000 1014 1750;
0 150 300 394 450 540 600 631 696 745 750 865];
</pre><pre class="language-matlab">curve 2=[442 452 484 500 547 600 658 700 800 856 900 1000 1337 1750;
0 150 300 347 450 532 600 640 716 750 773 816 900 928];
</pre><p>Thanks.</p>Khanh/matlabcentral/answers/contributors/5599261-khanhtag:www.mathworks.de,2005:Question/1597622014-10-23T02:39:01Z2014-10-23T03:27:57ZHow to create a for loop in function with a step size as input?<p>My current function is:</p><p>.
.</p><img src = "/matlabcentral/answers/uploaded_files/19884/fucntion.jpg"><p>.</p><p>x is supposely to run from 765 to 805 with myself individually keying in the step size</p><p>X Eg. 765 -> 770 -> 775 -> 780 .... (step size: 5)</p><pre> 765 -> 767 -> 769 -> 771 .... (step size:2)
.
.
.
765 -> 765.1 -> 765.2 -> 765.3 (step size:0.1)</pre><p>.</p><p>is repetitive procedure.</p><p>So Im thinking of changing X as the input of step size and 765 to 805 already implemented in the function. But Im foreign to the command of for loop.</p><p>Anyone can help? Will greatly appreciate it!
Thanks!</p>ZONG YI Ng/matlabcentral/answers/contributors/5751907-zong-yi-ngtag:www.mathworks.de,2005:Question/1595762014-10-21T20:59:34Z2014-10-23T03:09:47Zfastest way to obtain the copt table<p>hi i wanted to know the fastest way to obtain the copt table for large numbers of generating units in a system with small amounts of outage like 0.02 to 0.09
i heard there is a real fast way which can calculate all calculations for 2000 units in less than 2 seconds with a normal pc or laptop(not a super computer)</p>touraj/matlabcentral/answers/contributors/5802483-tourajtag:www.mathworks.de,2005:Question/1597632014-10-23T03:01:31Z2014-10-23T03:01:31Zlist of event listeners for handle graphics<p>Where would I find a list of things that can be listened to with regard to handle graphics. In 2014b I know I can use the metaclass notation, but with handles being numbers prior to this, the metaclass approach doesn't seem to work.</p><p>Metaclass approach:</p><pre> temp = metaclass(gca)
temp.EventList</pre>Jim Hokanson/matlabcentral/answers/contributors/937359-jim-hokansontag:www.mathworks.de,2005:Question/1597602014-10-23T01:39:34Z2014-10-23T02:42:54ZPlotting the convolution of two signals<p>I am given two functions x(t) =5[u(t+1)-u(t-1)] and h(t)=u(t-1)-u(t-7). I am asked to convolve these two signals and plot the result in the range -3 to 10. Here is the code that I wrote:</p><p>t=-3:0.1:10;
t_c=-3:0.05:10;
h_t=heaviside(t-1)-heaviside(t-7);
x_t1=5.*(heaviside(t+1)-heaviside(t-1));
c_x_h=conv(x_t1,h_t);
figure(1)
plot(t_c,c_x_h)</p><p>However, since this is a simple convolution I verified it by hand and it does not look like the plot i get in MATLAB. The max value should be 10 but in MATLAB i get 100. Also, the duration of the function should be 8 but i get 4 with MATLAB. Please help.</p>Dennis/matlabcentral/answers/contributors/5808305-dennistag:www.mathworks.de,2005:Question/1595592014-10-21T18:09:24Z2014-10-23T02:29:33ZExtract Data from for loop<pre> I am attempting to plot SFC and TSFC vs The PRC values based on each value of Mach. I am trying to find a way to extract all calculated values of SFC and TSFC from the for loop for plotting. Any help would be appreciated</pre><pre> U = Mach*sqrt(gamman*R*Ta);
Toa = Ta.*((1+(((gammad-1)/2).*(Mach^2))));
To2 = Toa;
To2sTa = (1+((etad.*((To2./Ta)-1))));
Po2 = Pa.*((To2sTa).^(gammad/(gammad-1)));</pre><pre> for PRC = 5:5:100
Po3 = PRC.*Po2;
To3 = To2.*(1+((1./etac).*(PRC.^((gammac-1)/gammac))-1));
for To4 = [1500 1600 1700]</pre><pre> Cpb = ((R*gammab)/(gammab-1));
f = ((To3.*((To4./To3)-1))./((QR/Cpb)-To4)); </pre><pre> Po4 = Po3;
To5 = To4-To3+To2;
Po5 = (Po4.*(1-(1./etat)*(1-(To5/To4))).^(gammat/(gammat-1)));</pre><pre> U7 = sqrt((2*etan*R*(gamman/(gamman-1)))*To5*((1-(Pa/Po5)).^(gamman-1/(gamman))));
SFC = ((1+f)*U7-U)/1000; %((kN*s)/(kg))
TSFC = f*SFC; %((kg)/(kN*s))
end</pre><pre> end</pre><pre class="language-matlab">end
</pre>G/matlabcentral/answers/contributors/4000106-gtag:www.mathworks.de,2005:Question/1597592014-10-23T01:39:11Z2014-10-23T02:23:05ZIs it possible to solve linear system of equations with parallel computing?<p>I am interested in solving big systems of equations with parallel computing.
I have an old script that use the LU decomposition to solve it, but i was trying to speed it up using parallel computation.
Do you have any suggestion?</p>Giovanni/matlabcentral/answers/contributors/5808317-giovannitag:www.mathworks.de,2005:Question/1597532014-10-23T00:26:03Z2014-10-23T02:15:04ZNot enough input arguments.<p>Hello, I am trying to run the program, but apper the error:</p><p>Error using rwn (line 8)
Not enough input arguments.</p><p>code:</p><pre class="language-matlab">% random walk on a square lattice
% input the number of jumps nt
% output is the square displacement rs2 and the list of positions x and y
function[rs2,x,y]= rwn(nt)
x(1)=0; % start particle at the origin
y(1)=0;
rs2(1)=0;
Fd=ceil(4.*rand(nt,1));% list with nt entries, each a random integer from 1 to 4, LINE 8
delx = [1 0 -1 0]; % these two lines define the jumps on the square lattice
dely = [0 1 0 -1]; % right, up, left, down
for j=1:nt % sum over nt jumps
x(j+1)=x(j)+delx(Fd(j)); % x position at j+1 jump
y(j+1)=y(j)+dely(Fd(j)); % y position at j+1 jump
rs2(j+1)=x(j+1)^2 + y(j+1)^2; % square displacement position at j+1 jump
end
</pre>rafael/matlabcentral/answers/contributors/5808152-rafaeltag:www.mathworks.de,2005:Question/1597422014-10-22T22:33:01Z2014-10-23T01:55:18ZHow can I display the progress of textscan<p>I am using textscan to read and parse data files that vary widely in size. For small files it is very fast, but it is not uncommon to read files in excess of 700 megabytes.</p><p>Since these files can take over a minute to load, it would be helpful to show the user that progress is being made.</p><p>Is there a way to get the progress of textscan - ideally I'd send it to waitbar() or something similar, but any indication I can give my user will be a major improvement.</p><p>I have zero ideas at this point without implementing my own textscan, and that's not something I'm excited to undertake.</p>Nicholas/matlabcentral/answers/contributors/5465709-nicholastag:www.mathworks.de,2005:Question/1597362014-10-22T21:22:15Z2014-10-23T01:53:05ZHow do I perform unbalanced ANOVA ?<p>Hi! I have 3 vectors of data (each vector has a different number of data) and I'd like to perform ANOVA. How do I do it?</p>Simo/matlabcentral/answers/contributors/5085466-simotag:www.mathworks.de,2005:Question/1596722014-10-22T13:51:05Z2014-10-23T01:49:04Z[HELP] Finding the lowest positioned pixel in the figure.<p>I have a code as follow: which is converted into binary image.</p><pre class="language-matlab">image= [pos1];
BW = im2bw(pos1,map,0.4);
imshow(pos1(:,:)),figure, imshow(BW)
</pre><pre class="language-matlab">image= [pos2];
BW = im2bw(pos2,map,0.4);
imshow(pos2(:,:)),figure, imshow(BW)
</pre><p>which will return following images</p><img src = "/matlabcentral/answers/uploaded_files/19843/2.png"><img src = "/matlabcentral/answers/uploaded_files/19842/1.png"><p>with these images, I want to find the lowest point (as circled with red) and print the location information into one matrix. (only need y axis value) = Height from the bottom of the image. (the first white pixel)</p><p>for instance if in lowest point pixel in image1 located at 123,342, and
for image 2 located at 134,423</p><p>then I want to have matrix that has values of 343, and 423.</p><p>I was doing this manually for 10 images. and I gave up as there are 100s of them...</p><p>It would be really appreciate if you can help me with this.</p>YJ/matlabcentral/answers/contributors/5190234-yjtag:www.mathworks.de,2005:Question/1597492014-10-22T23:43:29Z2014-10-23T01:40:25ZHow to add labels to cluster bar graphs<p>I'm trying to code in matlab how to exactly:</p><p>1. create clusters of bar graphs. So I want to create two bar graphs beside one another comparing two values in a bar chart format, and I need to do it for 4 seperate sets of data in the same graph.</p><p>2. Also on top of these bar graphs I would like to have the data label placed on top (so the value of the bar graph can be seen)</p><p>Any Help would be much appriciated! cheers</p>Stefano/matlabcentral/answers/contributors/5808075-stefanotag:www.mathworks.de,2005:Question/1597572014-10-23T01:21:37Z2014-10-23T01:30:31ZLoad and Append Data files<p>Hello,</p><p>I am trying to load and append several matlab files. Each .mat file has 2 1x1 structures, a Data struct (has 12 fields, each with 1x50 cells), and a Settings struct (10 fields).</p><p>I'd like to load 2 (or more) .mat files, and compare the settings. I've found the STRUCTCMP function, which works well. If the settings are the same, I'ld like to append the Data structs for the two mat files so that the fields stay the same, but now each has 1x100 cells.</p><p>I have a few problems with my code.
First, when I load the file, I'd like to rename each structure so that data1 = data; and settings1 = settings; but I haven't figured out how to do this in the loop.
Second, I'm not sure how to increase the size of the structure array, data.</p><pre class="language-matlab">%% create variable names for the structures
dataNum = input('How many data files to analyze? ')
for a = 1:dataNum
data{a} = strcat('data',num2str(a));
Settings{a} = strcat('Settings',num2str(a));
end
</pre><pre class="language-matlab">%% load the data files, check to make sure they have the same settings
for i = 1:dataNum
PData = input('What is the filename? ','s');
load(PData) % load file
Settings(i) = settings; %rename settings structure, eg. settings1, settings2, etc.
if i >1
if ~STRUCTCMP(settings1,settings(i) %check to make sure they have the same settings
fprintf('Error: data files have different settings')
settings(i)
break; %stop if this is not true
end
end
data(i) = Data; %rename the data structure, eg. data1, data2, etc.
i = i+1;
end
</pre><pre class="language-matlab">%% append the data structures together
data = [data1 data2]; %# create a structure array of the data
names = fieldnames(data); %# get the field names
cellData = cellfun(@(f) {vertcat(data.(f))},names); %# collect field data into
%# a cell array
data = cell2struct(cellData,names); %# convert the cell array into a structure
</pre><p>Thanks for your help, this is my first analysis script, and my first time posting on the forum.
Christina</p>Christina/matlabcentral/answers/contributors/5807639-christina