https://uk.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions20170823T19:25:43Ztag:uk.mathworks.com,2005:Question/35383320170823T19:25:43Z20170823T19:25:43ZI have a shapefile of Uttarakhand state and precipitation data of cordex domain south Asia and i have already generate spatial plot for it. now I want to extract the rainfall data of specifically this Uttarakhand Region by using this shapefile.<p>i want to use inpolygon function for extraction rainfall data for this particular region. please help me by telling me the appropriate code so that i can extract this particular region by using shapefile</p>Sudip Kunduhttps://uk.mathworks.com/matlabcentral/profile/authors/10746811sudipkundutag:uk.mathworks.com,2005:Question/33950120170509T15:50:01Z20170823T19:19:53Zerror with matlab.wsdl.setWSDLToolPath <p>I follow the steps available in : https://www.mathworks.com/help/matlab/ref/matlab.wsdl.setwsdltoolpath.HTML, but the matlab.wsdl.setWSDLToolPath funtion display this error:</p><p>matlab.wsdl.setWSDLToolPath('JDK',jdk,'CXF',cxf)
Error using matlab.wsdl.setWSDLToolPath>checkVersion (line 227)
The path 'C:\Program Files\Common Files\apachecxf2.7.18src' does not seem to be a CXF folder.</p><p>Error in matlab.wsdl.setWSDLToolPath (line 167)
checkVersion(path, 'wsdl2java', 'CXF', 'v', ...</p><p>any idea of what the problem is ?</p>Mario Vindashttps://uk.mathworks.com/matlabcentral/profile/authors/8833471mariovindastag:uk.mathworks.com,2005:Question/35381620170823T17:09:32Z20170823T19:16:30ZWeb Server Generic Cookie Injection<p>I was told by my Windows counterpart that you were able to provide a fix (.dll) file for the Nessus plugin 44135  Web Server Generic Cookie Injection which pops up on a HBSS scan. I need a Redhat 6/7 fix for Matlab 2017a/b. This is what our Vulnerability Manager had to say about it  We were seeing this finding mainly on Windows systems for an issue with Matlab and one of its components "Matlab Connector". We only see it pop up
when Matlab is installed/running on that machine. Please provide a fix. This user's system is blocked every time the scan is ran an he's using Matlab.</p>Melissa Millerhttps://uk.mathworks.com/matlabcentral/profile/authors/10773122melissamillertag:uk.mathworks.com,2005:Question/22300620150608T17:00:57Z20170823T19:16:06ZSimulink Library Browser doesn´t show any blocks<p>Hello everybody,</p><p>I just installed Matlab 2015a (academic license) and found the simulink library browser empty, besides the recently used blocks entry (which is empty).
System is a Win7 Proffesional 64bit.</p><p>What can I do about it?</p>Stephan Hehttps://uk.mathworks.com/matlabcentral/profile/authors/4566813stephanhetag:uk.mathworks.com,2005:Question/35383220170823T19:15:17Z20170823T19:15:17ZIf i have a data for one variable how do I check whether the data is statistically significant or not?<p>I have seen on the scientific papers that on top of the boxplots or on the sides of the figure there are p values. What exactly do they mean and how can this be done in matlab?
Suppose I have a set of data that I want to know whether the data is statistically significant or not?</p>hellohttps://uk.mathworks.com/matlabcentral/profile/authors/10352797hellotag:uk.mathworks.com,2005:Question/35367120170822T18:17:33Z20170823T19:13:41ZI am trying to create a function with Matlab V6.0.0.88 and it is not working. <p>I tried for example using the following code given in the wikipedia page about the secant method</p><pre class="languagematlab">f=@(x) x^2  612;
x(1)=10;
x(2)=30;
for i=3:7
x(i) = x(i1)  (f(x(i1)))*((x(i1)  x(i2))/(f(x(i1))  f(x(i2))));
end
root=x(7)
</pre><p>And I receive the following error message</p><pre> ??? f=@(x) x^2  612;

Error: "identifier" expected, "(" found.</pre><p>I have tried a few things, but I am unable to create a function.
Even the following code, who is part of the Matlab help menu, found while searching for 'function', does not work</p><pre class="languagematlab">function [mean,stdev] = stat(x)
n = length(x);
mean = sum(x)/n;
stdev = sqrt(sum((xmean).^2/n));
</pre><p>This piece of code returns the error</p><p>??? Strings passed to EVAL cannot contain function declarations.</p><p>Can anyone help me with this?
Thank you!</p>Patrick Soucyhttps://uk.mathworks.com/matlabcentral/profile/authors/10764719patricksoucytag:uk.mathworks.com,2005:Question/35383120170823T19:13:07Z20170823T19:13:07ZUsing SavitzkyGolay filter in real time simulink model<p>I want to use SavitzkyGolay filter in my simulink model. This function is available in matlab as this
outputsignal=sgolayfilt(inputsignal,order of filter,window size);</p><p>The way it works is as follows from some reading in the internet:
It uses least squares to regress a small window of your data onto a polynomial, then uses the polynomial to estimate the point in the center of the window. Finally the window is shifted forward by one data point and the process repeats. This continues until every point has been optimally adjusted relative to its neighbors. It works great even with noisy samples from nonperiodic and nonlinear sources.</p><p>I am unable to use this function in simulink. Can this be achieved in simulink using a matlab function block?</p><p>Note: I would like to generate embedded code with this,hence the need to do it in simulink.</p>Vishal Shankarhttps://uk.mathworks.com/matlabcentral/profile/authors/5757766vishalshankartag:uk.mathworks.com,2005:Question/35383020170823T19:12:09Z20170823T19:12:09ZHow to input IQ data into Matlab/Simulink?<p>I have an SDR that outputs audio through a virtual channel, and Audio Device Reader can capture this. The same radio can output this data in complex form (IQ)and Audio Reader can't handle that. How can I get the IQ data into Simulink for processing as a complex signal? Thanks.</p>Nina Buchananhttps://uk.mathworks.com/matlabcentral/profile/authors/10377540ninabuchanantag:uk.mathworks.com,2005:Question/35382020170823T17:44:24Z20170823T19:07:14ZHow can we generate a report in Matlab that traces outputs to inputs<p>One of our customers was asking if there is a report in Matlab that traces outputs to inputs. The inputs that impact the output.</p><p>Thank you,</p><p>Pasteur</p>Pasteur Bagenzihttps://uk.mathworks.com/matlabcentral/profile/authors/2760449pasteurbagenzitag:uk.mathworks.com,2005:Question/35381920170823T17:43:13Z20170823T19:06:30ZHow do I compile a standalone application with external excel files?<p>I created a Matlab code that works with data from some excel files. I want to compile the code into a standalone application but the excel files need to remain outside as they are going to be constantly updated. The idea is to have the application work with the data from the excel and produce a different output as the excels get updated. Is there a way to compile while keeping the excels separate and thus able to be edited? Thanks.</p>Pedro Cadavidhttps://uk.mathworks.com/matlabcentral/profile/authors/10674625pedrocadavidtag:uk.mathworks.com,2005:Question/35369720170822T21:19:03Z20170823T19:05:32ZAre there any codes to generate planar graphs in matlab or are there any large collections of planar graphs in matlab?<p>Are there any codes to generate planar graphs in matlab or are there any large collections of planar graphs in matlab? When posting codes if it's not obvious how to use the code to generate planar graphs an explanation would be helpful.
(This is an modification to a previous question I posted)</p>Hao Sunhttps://uk.mathworks.com/matlabcentral/profile/authors/3855756haosuntag:uk.mathworks.com,2005:Question/35382920170823T19:03:30Z20170823T19:05:30ZHow to implement cross validation in neutral network for time series prediction<p>I am using k fold cross validation for the training neural network in order to predict a time series. I have an input time series and I am using Nonlinear Autoregressive Tool for time series. I am using 10 fold cross validation method and divide the data set as 70 % training, 15% validation and 15 % testing. But I really din't know how to generate the code.</p><p>And please to be honest, this is the first time that I am using neural networks. So, please be humble in your explanation!!</p><p>This is something that I wrote,</p><pre class="languagematlab">k=10;
Indices=crossvalind('Kfold', length(X), 10);
X = tonndata(densig,true,false);
T = tonndata(densig,true,false);
trainFcn = 'trainlm';
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = [50 20 20];
X1=cell2mat(X);
T1=cell2mat(T);
for i=1:k
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
X1(i)=find(X1(Indices(i)));
T1(i)=find(T1(Indices(i)));
[x,xi,ai,t] = preparets(net,X1,{},T1);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.trainParam.epochs = 5000;
[net,tr] = train(net,x,t,xi,ai);
end
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y);
</pre><p>Please help</p><p>Thanks
Baqar</p>Baqar Rizvihttps://uk.mathworks.com/matlabcentral/profile/authors/10300359baqarrizvitag:uk.mathworks.com,2005:Question/35382820170823T19:01:14Z20170823T19:01:14Zproblem with a PYO MMPT mode and PV modulel Matlab 2016<p>I want to implement a P & O MPPT control, using the solar module in matlab 2016, the problem I have is when I do the boost converter does not raise me to what I want, unless I put the powergui in continuous mode, otherwise it does not raise To what I want, the other problem is that when I implement the mppt does not do any work, the voltage of the panel becomes zero and I do not understand why or to that it should not work, and check the examples that come, but it does not give me all ways.</p>Alejandro Zavalahttps://uk.mathworks.com/matlabcentral/profile/authors/9648942alejandrozavalatag:uk.mathworks.com,2005:Question/35382720170823T18:59:02Z20170823T18:59:02ZHow to know parameters for 690v PMSG <p>I'm trying to model a Permanent Magnet Synchronous Generator as a part of my project. For this purpose, I have used the Permanent Magnet Synchronous Machine block from Sim Power systems. can you provide me the parameters of 690 volt, 50 Hz PMSG ? The input of PMSG is Torque.</p>AJAY SAMARIAhttps://uk.mathworks.com/matlabcentral/profile/authors/9449394ajaysamariatag:uk.mathworks.com,2005:Question/35381720170823T17:11:15Z20170823T18:56:42ZI can't understand a piece of code<p>I am extremely new to Matlab and I can't understand a basic thing I guess. I downloaded an available code of a basic active contour model(snake) and in the function, I don't understand what variable P is. Can anybody explain for me?</p><img src = "/matlabcentral/answers/uploaded_files/86231/question.JPG">Amirarsalan Rajabihttps://uk.mathworks.com/matlabcentral/profile/authors/8872969amirarsalanrajabitag:uk.mathworks.com,2005:Question/30833920161020T22:16:41Z20170823T18:55:14ZUse vrrotvec to calculate the rotation angles between two vectors (R2015b)<p>I need to calculate the rotation angle to transform vector a = [1, 0, 0]' to b = [1/sqrt(3), 1/sqrt(3), 1/sqrt(3)]',such that I script below:</p><pre class="languagematlab">X = [1, 0, 0]';
Y = [1/sqrt(3), 1/sqrt(3), 1/sqrt(3)]';
R = vrrotvec(X, Y);
</pre><p>As the outcome, I have R = 0, 0.7071, 0.7071, 0.9553</p><p>What is the meaning of the first three items, i.e. 0, 0.7071 and 0.7071? Are they the cosine value of the rotation angle against x, y and zaxes?</p>Lu Gaohttps://uk.mathworks.com/matlabcentral/profile/authors/8617165lugaotag:uk.mathworks.com,2005:Question/35381520170823T17:09:06Z20170823T18:51:58ZSubtraction Operation Within Cell Array<p>Hello,</p><p>I have a 2 x 6 cell array, each cell in row #1 {1 > 6, 2} contains a 1024 x 1024 x 100 matrix. The first cell in row #2 {2,1} contains a 1024 x 1024 matrix. I want to subtract the cell in {2,1} from each "slice" of each matrix in row#1. I am having trouble putting together code that would do this... here is what I have so far (the bit that this question is referring to is the last 3 lines of code):</p><pre class="languagematlab">%% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.spe');
dinfo = dir(filePattern);
filenames = fullfile(myFolder, {dinfo.name});
output = cellfun(@readSPE, filenames, 'uniform', 0); %convert to spe
output = cellfun(@double,output, 'uniform', 0); %convert to double
</pre><pre class="languagematlab">%% remove first five frames to reduce variability
output = cellfun(@(x)x(:,:,5:end),output,'uni',false);
%% import background
bkg = median(double(readSPE('bkg_10AOC_LightsOff.spe')),3); %temporal median + double
output{2,1} = bkg; %insert into cell array
</pre><pre class="languagematlab">%% subtract bkg from each cell
for i = 1:length(filenames)
output{1,i}  output{2,1};
end
</pre><p>I am not sure that this is accomplishing what I... any suggestions? If anyone has suggestions on a better methodology please let me know :)</p><p>Thank you for your time and help!!</p>itendhttps://uk.mathworks.com/matlabcentral/profile/authors/10352473itendtag:uk.mathworks.com,2005:Question/35380920170823T16:30:51Z20170823T18:48:52ZStuck on this MATLAB question<p>I'm supposed to write a code on MATLAB that solves this problem.</p><p>21855372,
21397898,
21303234,
21849704,
21647943,
21485234,
21825033</p><p>Take the last three digits of these numbers above and divide them by 1000. Then find arithmetic average of the numbers obtained.</p>Sara Maria El Oudhttps://uk.mathworks.com/matlabcentral/profile/authors/10763518saramariaeloudtag:uk.mathworks.com,2005:Question/35382620170823T18:48:25Z20170823T18:48:25Zafter downloading the trail software its asking for the activation key ,where will i get this ? <p>how do i get the activation key?</p>Hifsa Fathimahttps://uk.mathworks.com/matlabcentral/profile/authors/10075658hifsafathimatag:uk.mathworks.com,2005:Question/35077320170729T16:04:53Z20170823T18:47:50ZHow to randomly generating a function with math operators and operands<p>Hi,
I am new in matlab. Currently, I am trying to generate random functions with math operators like {+,,*,/} and operands like {1,2,3,4}. Now I have a cell containing the operators I need. First of all, as the operators are in a cell, how can I use them to generate functions? Also, How can I randomly combine the operators and operands to generate functions? I would appreciate it a lot if someone could help me. Thanks
Julie</p>Julie Ghttps://uk.mathworks.com/matlabcentral/profile/authors/10560407juliegtag:uk.mathworks.com,2005:Question/28060420160423T16:31:51Z20170823T18:47:49Zproblem with a fuzzy logic MPPT model<p>Hello,</p><p>I have a problem with an MPPT model using fuzzy logic: the method doesn't work as the output duty cycle is always zero, thus the output power is not even close to the MPP and i am sure that i correctly implemented all the blocs of the model (PV module, boost converter,...) as well as the fuzzy logic membership functions.Can any one help? i have joined the images of the model i'm using, the mppt bloc and a subsytem i'm using inside.</p><img src = "/matlabcentral/answers/uploaded_files/50566/model.png"><img src = "/matlabcentral/answers/uploaded_files/50565/mppt%20bloc.png"><img src = "/matlabcentral/answers/uploaded_files/50567/subsystem.png">M Ghttps://uk.mathworks.com/matlabcentral/profile/authors/7920661mgtag:uk.mathworks.com,2005:Question/4229720120628T15:04:31Z20170823T18:46:12ZCopying dynamic array to MxArray object using memcpy in c++<p>I am writing a c++ program that calls that Matlab Engine.
I am getting an error when I try to use memcpy for a dynamically allocated multidimensional array. I have a type definition as follows in my header file:</p><p>typedef double* dblArrayptr;</p><p>My array definition in my function is as as follows:</p><p>dblArrayptr *A;</p><p>A = new dblArrayptr [2*NUMROWS];</p><p>for (int i=0;i<2*NUMROWS;i++)</p><pre class="languagematlab">A[i] = new double [2*NUMROWS];
</pre><p>I initialize this matrix A with some values and then try to use the memcpy command as follows: (note: this matrix has 44 rows and 44 columns).</p><p>memcpy((void *)mxGetPr(A_m), (void *)A,1936*sizeof(double));</p><p>I receive a memory access violation error.
Access violation reading location.</p><p>This memcpy command seems to work ok if I have a single array (44x1) of type double.</p><p>Do I have to do an element by element copy?</p>Laurenhttps://uk.mathworks.com/matlabcentral/profile/authors/1061508laurentag:uk.mathworks.com,2005:Question/35382420170823T18:17:41Z20170823T18:46:03ZWrite a program to calculate the sum 1+2+3+...+300. Display the total after every 20 terms and by using an if statement to check if the current number of terms is a multiple of 20. The basic idea is this: if i/20 == ro<p>Write a program to calculate the sum 1+2+3+...+300. Display the total after every 20 terms and by using an if statement to check if the current number of terms is a multiple of 20. The basic idea is this: if i/20 == round(i/20), print the sum.</p>Mohammad Asadhttps://uk.mathworks.com/matlabcentral/profile/authors/10773647mohammadasadtag:uk.mathworks.com,2005:Question/35341020170820T17:11:50Z20170823T18:40:55Zgarchset / garchget to new functions<p>Good day,</p><p>I am trying to adapt the old functions from Econemtrics Toolbox of 2013/14 to the new one. Even though I found the following link with some instructions ( https://uk.mathworks.com/help/econ/convertingfromgarchfunctionstomodels.html ) I can't manage to adapt it to my case.</p><p>I am estimating GJR(1,1). The idea is that the code needs to add volatility shock to the previously estimated model (that is why it uses garchget and multiplies the volatility constant by a shock).</p><pre class="languagematlab">for i=1:nEquities
spec(i)=garchset(spec(i),'k',garchget(spec(i), 'k')* VolaShock(i,1)^2); % apply stress input to GARCH volatility constants
end
</pre><p>An then it simulates the output using garchsim:</p><pre class="languagematlab">for i = 1:nEquities
[~, ~, ...
StressedsimulatedReturns(:,:,i)] = garchsim(spec(i), horizon, nPaths, Z(:,:,i), ...
[], [], preResidual(i), preSigma(i), ...
preReturn(i));
end
</pre><p>I understand that now the functions to use are garch / estimate / simulate but I don't understand how to adapt the syntax... Any help / advice is appreciated.</p>art.annahttps://uk.mathworks.com/matlabcentral/profile/authors/8959172artannatag:uk.mathworks.com,2005:Question/35180620170807T09:36:15Z20170823T18:40:38ZHow can implement parallel pipeline using 3 workers in one computer ?<p>Dear everyone, Please I have a question:</p><p>I would like to used 3 workers (cores) to implement 3 functions in a parallel as pipeline, i.e. the first worker create the data, do some process(funadd), and sends the results (x) to the first buffer/queue/matrix. Then, the second worker receives the data from the first buffer, do some process (funmult), and send the results (y) to the second buffer. The third worker receive the data, do some process (fundouble) and print the output(z).
In the following attach the picture show the situation.</p><img src = "/matlabcentral/answers/uploaded_files/84843/1_o.jpg"><p>My question is that: How can I implement these three functions in parallel pipeline ?</p><p>Please, any idea how to solve this problem?</p><p>Kind regards
Ammar</p>Ammar https://uk.mathworks.com/matlabcentral/profile/authors/6713588ammartag:uk.mathworks.com,2005:Question/35334920170819T21:58:17Z20170823T18:35:53Zhow to make a 2 files .mat become 1?<p>i want to make 2 .mat files become 1 file. For example, I have 1 mat file when I give name databasefitur, and databasefitur1. In this case databasefitur and databasefitur1 have 2 rows and 255 columns. I want to make them as a group.</p><p>For example, I use this code in my program :</p><pre class="languagematlab">load file_name.mat
file1=strcat('..\Project Tugas Akhir\Histogram LoG\',file_name);
I=imread(file1);
imhist(I)
[n,xout]=imhist(I); %nilai piksel
featureSize=size(n);
featuresN=reshape(n,1,featureSize(1)); %jumlah piksel
featureSize=size(xout);
featuresXout=reshape(xout,1,featureSize(1)); %save ke databasefitur
databaseFitur2=[featuresN;featuresXout];
save('databaseFitur2','databaseFitur2');
</pre>Veizal Rasyidhttps://uk.mathworks.com/matlabcentral/profile/authors/10583233veizalrasyidtag:uk.mathworks.com,2005:Question/35382520170823T18:34:16Z20170823T18:34:16ZDetermine how many harmonics should be selected to contain 99% of the modulated signal power.<p>c(t) = 6 cos(2pi x fc1 x t)</p><p>m(t) = 2 cos(30pi x 103t)</p><p>kf1 = 50x10^3</p><p>i.e. 2pikf1 = 100pi X 10^3</p><p>The carrier frequency is 88.8 MHz.</p><p>Determine how many harmonics should be selected to contain 99% of the modulated signal
power. You can use the MATLAB builtin besselj function for this task.</p>Mujtaba Husseinhttps://uk.mathworks.com/matlabcentral/profile/authors/5819885mujtabahusseintag:uk.mathworks.com,2005:Question/35327120170818T18:21:51Z20170823T18:26:15ZGenpath is excluding package folders<p>Hello,</p><p>I am writing a script that requires to know every folder and subfolder, for which genpath() works perfectly.</p><p>However, there are a few folders that are packages (and begin with a '+'), and genpath ignores those.</p><p>Is it possible to have genpath include those, or some other way to automatically include that?</p><p>Thanks!</p>Matthew Brownhttps://uk.mathworks.com/matlabcentral/profile/authors/10621554matthewbrowntag:uk.mathworks.com,2005:Question/35382320170823T18:17:22Z20170823T18:36:53ZImage analysis  Astronomical .FITS file  streak/line detection<p>I am attempting to write code to automatically analyse a large set of .FITS images (more than 10,000 images).</p><p>My goal is to find those images that contain moving objects (asteroids/satellites), which appear as streaks (lines). I would like to reject images that contain just stars (points of light).</p><p>I have attached several images, in both .fits and .jpg format (as I realise that .fits is not as common. I use the program 'AvisFV' to view these). There are some examples with streaks, and some without. These examples also show the variance in image background, and streak size, that I am dealing with.</p><p><a href = "https://1drv.ms/f/s!AqG6zBac4y6clU1lj_sDictWxeS">.fits and .jpg examples</a></p><p>I am very new to coding, so would appreciate any suggestions to achieve my goal. After reading through examples and documentation online, I have included my best coding attempt below, however this has not had a lot of success. Here, I have converted from .fits to .jpg before running through MATLAB, however I would prefer to leave in .fits if possible.</p><p>I am not committed to any one way of line detection  any suggestions whatsoever, even if totally different from my attempt below, are welcome and much appreciated!</p><p>Many thanks in advance.</p><pre class="languagematlab">cd F:\DATA\BWHOUGH\IMAGES
% Specify the folder where the files live.
myFolder = 'F:\DATA\BWHOUGH\IMAGES';
</pre><pre class="languagematlab">% Get a list of all files in the folder with the desired file name pattern. Change from .jpg to other file type being used if required.
filePattern = fullfile(myFolder, '*.jpg');
</pre><pre class="languagematlab">% For each image, convert to binary, conduct image processing, then Hough transform
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
img = imread(fullFileName);
level = graythresh(rgb2gray(img));
BW = im2bw(rgb2gray(img),level);
BW2= imdilate(imerode(BW, ones(5)), ones(5));
BW3 = bwmorph(BW2,'remove');
[H,T,R] = hough(BW2);
P = houghpeaks(H,15,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
lines = houghlines(BW2,T,R,P,'FillGap',5,'MinLength',7);
max_len = 0;
</pre><pre> for j = 1:length(lines)
xy = [lines(j).point1; lines(j).point2];</pre><pre> % Determine the endpoints of the longest line segment
len = norm(lines(j).point1  lines(j).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end</pre><pre class="languagematlab">% Adjust desired streak length (max_len, below. 100 works well). Lines below this length will be moved to the ‘NO’ folder, above (hopefully streaks) will be moved to the ‘YES’ folder.
if length(lines)<=0
movefile(baseFileName,'F:\DATA\BWHOUGH\IMAGES\NO')
else
if max_len>=100
movefile(baseFileName,'F:\DATA\BWHOUGH\IMAGES\YES')
else
movefile(baseFileName,'F:\DATA\BWHOUGH\IMAGES\NO')
end
end
</pre><pre class="languagematlab">end
</pre>JFhttps://uk.mathworks.com/matlabcentral/profile/authors/8267281jftag:uk.mathworks.com,2005:Question/35368420170822T19:48:35Z20170823T18:19:22ZRemoving noise boundaries from segmented binary image that is not part of a curve?<p>I am trying to detect a curve in a image. This curve is broken up in many places. After some segmentation and thresholding my final binary image still has some noise. I will eventually be connecting all the different boundaries but then the noise is also counted as a boundary and that should not be part of the final connected curve. Is there any other function that will analyze boundaries and see if they are part of a curve or just noise??? The noise boundaries are different sizes, different entropies, different perimeters... so I can't just filter by property.</p><p>I have so many different images so Im not looking for a specific solution to one picture. I am just wondering what the best way to remove noise in binary images would be. That's why I haven't attached a picture. I have already tried fitting but that does not seem like a good solution. Maybe if somehow the boundary will be in the curve if it is between the coordinates of the previous boundary and the next??? Maybe some sort of pattern recognition?</p>Aa Mhttps://uk.mathworks.com/matlabcentral/profile/authors/10264504aamtag:uk.mathworks.com,2005:Question/35366020170822T17:21:54Z20170823T18:18:35ZDynamically generating an optimization problem<p>I'm an infrequent MatLab user, so when I need it I tend to find an example and tailor it to my problem. I followed that approach recently in building a constrained optimization model.</p><p>I wrote several functions for a) calculating values b) evaluating constraints and c) the objective function. My final script looked like this</p><pre class="languagematlab">x0 = [0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0];
</pre><pre> lb = [0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0;
0,0,0,0,0];</pre><pre> %at work version release returns 2014b, and then the options are
%MaxFunEvals, MaxIter </pre><pre> %or on some computers, its 2017a, and then the options are
%MaxFunctionEvaluations, MaxIterations</pre><pre> version = evalc('version release');
if strcmp(version,'2017a')
options = optimoptions(@fmincon,'Algorithm','activeset','MaxFunctionEvaluations',100000,'MaxIterations',100000);
else
options = optimoptions(@fmincon,'Algorithm','activeset','MaxFunEvals',100000,'MaxIter',100000);
end</pre><pre> p = gcp('nocreate'); % If no pool, do not create new one.
if isempty(p)
parpool;
end</pre><pre> ms = MultiStart('UseParallel', true);
problem = createOptimProblem('fmincon','objective',@carry_forward_objective,'nonlcon',@turbulence_constraints,'x0',x0,'lb',lb,'options',options);</pre><pre> [x,fval] = run(ms,problem,100)</pre><p>This has worked well, but note that the problem is hardcoded...it's the same with the referenced functions @carry_forward_objective and @turbulence_constraints. In this case there are 23 rows and 5 columns of decision variables.</p><p>My challenge now is to generalize the process so that I can read in a variable number of rows (there will always be 5 columns) from a file that defines a problem and set up the optimization. I can use xlsread to get the data in, but am unsure how to proceed programmatically creating the functions/handles required to set up the problem. Can anyone point me in the right direction?</p><p>Thanks!</p>Jeremy Hendrixhttps://uk.mathworks.com/matlabcentral/profile/authors/3285583jeremyhendrixtag:uk.mathworks.com,2005:Question/6800520130320T21:28:01Z20170823T18:15:05ZIs it possible to perform parallel computing with lsqnonlin?<p>Hello,</p><p>Could anybody please tell me if parallel computations are possible with the MATLAB optimization routine "lsqnonlin"? For my applications, this nonlinear optimization function seems to be the best one out of many, but I was disappointed to find out parallel computations were not supported for "lsqnonlin" in R2012a. What about the newest release?</p><p>I understand that it might be inherently impossible to make this function work in a parallelized way, but I would like to make sure whether or not the feature is now implemented.</p><p>Thank you in advance.</p>Igorhttps://uk.mathworks.com/matlabcentral/profile/authors/2042760igortag:uk.mathworks.com,2005:Question/35344720170821T06:36:29Z20170823T18:07:52ZHow to average geotiff file?<p>I am having three <b>level 2 AOD files</b> in <b>geotiff format</b>. First I exported the files in matlab and got unequal matrices of dimension 786*1105, 830*1014 and 9187*1156 of type int16 and georeferencing files. Now I want to find the mean of this files according to latitude longitude. I mean if I add extra rows and columns of NaN to make all matrices equal, the mean which I get is not according to the lat and long. So, kindly help me!</p>Gahana Jainhttps://uk.mathworks.com/matlabcentral/profile/authors/10582079gahanajaintag:uk.mathworks.com,2005:Question/4701320120830T09:01:33Z20170823T18:06:09Zretrieve matfile version<p>Hello community,</p><p>I want to use the MATFILE command to access specific data in .matfiles.
Is there a function which returns true if the .matfile format is 'v7.3' and false otherwise?</p><p>I know you can check this in the command window using</p><pre class="languagematlab">type myfile.mat
</pre><p>However you cannot use TYPE within a function, which is what I want to do.</p><p>Thanks in advance</p><p>David</p>David T_https://uk.mathworks.com/matlabcentral/profile/authors/3443136davidt_tag:uk.mathworks.com,2005:Question/35382220170823T17:53:54Z20170823T17:55:09ZArduino Simulink external mode error<p>when ever i try to run any simulink model in external mode with my Arduino Uno i get the following error
im runiung Matlab 2017a on Ubuntu 17.04.</p><pre> Simulation
07:47 PM
### Starting build procedure for model: untitled
Code Generation 1
Elapsed: 32 sec
AVR Memory Usage

Device: atmega328p</pre><pre> Program: 21696 bytes (66.2% Full)
(.text + .data + .bootloader)</pre><pre> Data: 1027 bytes (50.1% Full)
(.data + .bss + .noinit)
### Successful completion of build procedure for model: untitled
Build process completed successfully
Unexpected exception (basic_ios::clear: iostream error) was caught.
Component:Simulink  Category:Model error</pre>Ibrahim Essamhttps://uk.mathworks.com/matlabcentral/profile/authors/8276314ibrahimessamtag:uk.mathworks.com,2005:Question/35340820170820T16:07:51Z20170823T17:53:44Zhow can i change Pareto front axis in genetic algorithm? <p>how can i change the axis in Pareto front plot in genetic algorithm? is there a way to plot the two objective functions on the y axis and indicate the optimal solution since there is an axis. Thank you</p>Gali Musahttps://uk.mathworks.com/matlabcentral/profile/authors/6726361galimusatag:uk.mathworks.com,2005:Question/35382120170823T17:48:01Z20170823T17:48:01ZHow to plot Error function of complex numbers<img src = "/matlabcentral/answers/uploaded_files/86235/unnamed.png"><p>Dear sir how have plotted for complex function taking omega=pi/2, M=0.5</p>HAREKRISHNA MANDALhttps://uk.mathworks.com/matlabcentral/profile/authors/4920149harekrishnamandaltag:uk.mathworks.com,2005:Question/33069420170319T16:36:27Z20170823T17:45:50ZHow to update legend in MatLab R2017a<p>I found that in the new version of MatLab, R2017a, they removed the option of updating the legend (RightClick on legend > select the option Refresh).
So, how one can update the legend in MatLab R2017a?</p>Jamal Ahmadhttps://uk.mathworks.com/matlabcentral/profile/authors/3986234jamalahmadtag:uk.mathworks.com,2005:Question/31802520161223T20:34:54Z20170823T17:44:56ZMerging .mat files into 1 file, only containing variables in array form<p>Hi there,</p><p>I want to merge 5 .mat files into 1 .mat file. When doing this, the end result is a mat file which contains 1 structure array. I want the result to be a mat file that only contains matrix arrays.</p><p>The situation is follows:</p><p> Each mat file contains 11 variables (with the same name), and each variable contains 136000x1 samples.</p><p> The end result should be 1 mat file that contains the 11 variables, but with 136000x5 samples.</p>Hinemtherhttps://uk.mathworks.com/matlabcentral/profile/authors/5884637hinemthertag:uk.mathworks.com,2005:Question/35301320170816T22:08:24Z20170823T17:44:09ZIn 2017a, How do I prevent a legend item from being 'greyed out' when the plot line is set with visibility off?<p>With 2017a, my legend entries are showing up as 'greyed out' when the plot object is set with visibility off. This is not the behavior for R2015b (and previous releases).</p><p>This example code shows the legend differently in R12015b vs. R2017a. I want the R2015b behavior. I frequently use this approach when I want the legend to be in one order, but the plotting order to be different.</p><pre class="languagematlab">%% Example of greyed out legend.
% allows order of legend to be different from plotting order
% 2015b: all legend entries are normal color
% 2017a: 1st legend entry has gray text and the plot line/symbol is greyed
</pre><pre class="languagematlab">figure
legstr = {};
hold all;
</pre><pre class="languagematlab">plot(0,0,'ro','Visible','off')
legstr(end+1) = {'Line'};
</pre><pre class="languagematlab">plot(1:100,randn(1,100),'ks')
legstr(end+1) = {'Random'};
</pre><pre class="languagematlab">plot([1 100],[0.5 0.5],'ro')
</pre><pre class="languagematlab">lh=legend(legstr);
</pre><p>I'd prefer a solution that doesn't require rewriting 100's of lines of existing code, like a property setting in the legend command.</p><p>Thanks</p>Karenhttps://uk.mathworks.com/matlabcentral/profile/authors/1319481karentag:uk.mathworks.com,2005:Question/32248420170130T07:50:43Z20170823T17:35:07Zhow to get floating point number upto 4 decimal points<p>hi
i have an array of floating point numbers of type double...for example
x=[ 0.8462 0.4906 0.9422 0.2054 0.6154 0.8923 0.3622 0.8710 0.4237 0.9206 0.2757 0.7528]
how to limit the values upto 4 decimal points.</p><p>x11=(round(x*10000))/10000; does not work</p>studentambitioushttps://uk.mathworks.com/matlabcentral/profile/authors/6818953studentambitioustag:uk.mathworks.com,2005:Question/32529820170216T02:49:45Z20170823T17:28:25ZFailure to start simulink<p>When I start simulink, the following message will be displayed.
Failed to load URL https://localhost:61415/toolbox/simulink/sltemplate/web/GalleryView/gallery.html?channel=/sltemplate/GalleryView/All/&viewType=All&startPage=true&snc=EA7F23 with error (111).</p>hisayoshi funaharahttps://uk.mathworks.com/matlabcentral/profile/authors/7889002hisayoshifunaharatag:uk.mathworks.com,2005:Question/35376720170823T11:54:21Z20170823T17:27:24Zhow to solve this error ? the horzcat Dimensions of matrices being concatenated are not consistent <p>i am using of curvelet first generation code in my project. but when i call the curvelet function in main code this error appears in this section of curvelet code and main code :
Error using horzcat Dimensions of matrices being concatenated are not consistent.</p><p>Error in iso_fuwt2_po (line49)
x = [zeros(floor(ls/2),n) x zeros(ceil(ls/2),n)];</p><p>Error in cvt (line 36)
D = iso_fuwt2_po( x, J, hr );% fine to coarse</p><p>Error in MainProposedCode(line 25)
Dn=cvt(image1,5,[3 4 5 5 6]);</p><p>can someone show me how to handle and solve this error. thank you so much!</p><p>this is code in iso_fuwt2_po.m :</p><img src = "/matlabcentral/answers/uploaded_files/86193/code1.JPG"><img src = "/matlabcentral/answers/uploaded_files/86194/code2.JPG"><img src = "/matlabcentral/answers/uploaded_files/86195/code3.JPG"><p></p><p>this is code in cvt.m :</p><img src = "/matlabcentral/answers/uploaded_files/86196/code4.JPG"><img src = "/matlabcentral/answers/uploaded_files/86197/code5.JPG">maso0m aBbasihttps://uk.mathworks.com/matlabcentral/profile/authors/10249809maso0mabbasitag:uk.mathworks.com,2005:Question/35381820170823T17:16:22Z20170823T17:16:22ZMATLAB R2017a, X2Go, and hardware OpenGL<p>I have a server running RHEL 7.4 with an NVIDIA GTX 1080. At the console itself, I can startx and launch MATLAB with hardware OpenGL. If I launch MATLAB on my Windows desktop PC via Cygwin, I can also get hardware OpenGL, via the graphics card on my desktop PC.</p><p>The specific functionality I'm shooting for is hardware OpenGL when running MATLAB in X2Go NX session. I can use X2Go to establish a KDE session with the server and I can launch MATLAB, but "opengl info" causes MATLAB to crash with "MATLAB has encountered an internal problem and needs to close".</p><p>Thoughts?</p><p>Thanks!</p>Matt Hohmeisterhttps://uk.mathworks.com/matlabcentral/profile/authors/10665029matthohmeistertag:uk.mathworks.com,2005:Question/35379120170823T14:39:40Z20170823T18:20:28Zlsqcurvefit error on a different computer<p>I tried to use lsqcurvefit to fit gamma variate function. It runs ok on my mac laptop with Matlab2015a installed, although it's really slow since that laptop only have two cores and I have 630784 pairs of data to fit. So, I decided to use a more powerful computer to run it at full speed (4 core). This is a Windows computer with Matlab2015b installed, the code ran successfully for about 20 min then it gave errors as shown below. I don't know why it runs fine on my laptop and failed on a different platform after it ran 20 mins. Any ideas? Thanks!</p><pre class="languagematlab">gma_var =@(x,xdata,varargin) x(1)*((xdatax(2)).^x(3)).*exp((xdatax(2))./x(4))...
.*(exp(1)/(x(3)*x(4))).^(x(3))+x(5);
parfor i = 1:num
gamma_fit(:,i) = lsqcurvefit(gma_var,k_reshaped(i,:),t,perfusion4D_reshaped(i,:))';
end
</pre><p>k_reshaped is a 333036x5 matrix and perfusion4D_reshaped is a 333036x29 matrix</p><pre> Error using trust (line 29)
Input to EIG must not contain NaN or Inf.
Error in trdog (line 109)
[st,qpval,po,fcnt,lambda] = trust(rhs,MM,delta);
Error in snls (line 311)
[sx,snod,qp,posdef,pcgit,Z] = trdog(x,g,A,D,delta,dv,...
Error in lsqncommon (line 156)
snls(funfcn,xC,lb,ub,flags.verbosity,options,defaultopt,initVals.F,initVals.J,caller,
...
Error in lsqcurvefit (line 254)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,...</pre>Mu Hehttps://uk.mathworks.com/matlabcentral/profile/authors/3298816muhetag:uk.mathworks.com,2005:Question/35375320170823T10:22:37Z20170823T17:06:09ZRegression with dependent independent variables<p>When undertaking a linear regression evaluating y as a function of x and x^3, is there a specific function within Matlab that takes account of the mutual dependence of the independent variables (x and x^3)?</p><p>I've tried searching the documentation but haven't found anything that specifically addresses this issue.</p><p>Regards, Brian</p>Brian Scannellhttps://uk.mathworks.com/matlabcentral/profile/authors/3912127brianscannelltag:uk.mathworks.com,2005:Question/35381420170823T17:01:34Z20170823T17:01:34ZProblems in the PKEPLER function in the MATLAB astrodynamics software package.<p>The PKEPLER function is accepting values for radius only within the range of 0 to 1000. Ideally, the program should accept calls more than 6400 (radius of Earth). If these proper values are entered it displays that the rem function does not accept input because it is in the form of imaginary numbers. When values less than 1000 are given, the velocity is displayed as an complex number. Pls help solve</p>Aswath Suryahttps://uk.mathworks.com/matlabcentral/profile/authors/10715003aswathsuryatag:uk.mathworks.com,2005:Question/35335320170819T22:44:14Z20170823T16:59:54ZHow can i use interval with decimal at the end of a count in for loop. e.g. t=1:1:18.7<p>How can i use interval with decimal at the end of a count in for loop. e.g.
t=1:1:18.7</p><pre class="languagematlab">intervals = 18.7;
for t=1:intervals;
x(t+1)=Pd*t;
end
</pre>Gali Musahttps://uk.mathworks.com/matlabcentral/profile/authors/6726361galimusatag:uk.mathworks.com,2005:Question/26484120160122T19:16:32Z20170823T16:59:51ZIs there a Simulink Support Package for BeagleBoard?<p>I am using a BeagleBoardxM and would like to run Simulink models on it. Is there a support package that I can use?</p>MathWorks Support Teamhttps://uk.mathworks.com/matlabcentral/profile/authors/4622813mathworkssupportteamtag:uk.mathworks.com,2005:Question/35354620170821T19:36:59Z20170823T16:58:27Z"Subscripted assignment dimension mismatch" when using "find" with a tolerance?<p>My code gets pretty in depth so I am not sure if posting it all would be helpful at all. Essentially I am using find with a tolerance to obtain the common numbers between two matrices. Matrix N_new is a 884x884x3 layered matrix and FGIF is a 801x2 matrix. I keep getting the error for the line in the for loop saying "Subscripted assignment dimension mismatch." Any speculation as to why I would be recieving this error? I have played with the tolerance and it does not make a difference. I am pretty sure that all of the values in FGIF are a part of matrix N within the tolerance specified. I have provided a little code to get an idea of what I am going for.</p><pre class="languagematlab">[FGIF_r, FGIF_c] = size(FGIF);
tol = 0.001;
for i = 1:FGIF_r
[row(i), col(i)] = find(abs(N_new(:,:,2)FGIF(i,1))<=tol & abs(N_new(:,:,3)FGIF(i,2))<=tol);
end
</pre>Andrew Poissanthttps://uk.mathworks.com/matlabcentral/profile/authors/4445510andrewpoissant