http://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-12-20T12:11:15Ztag:nl.mathworks.com,2005:Question/1671092014-12-18T16:41:44Z2014-12-20T12:11:15ZHow I can change the video in Motion-Based Multiple Object Tracking example?<p>Hi .I am new in matlab and I want to study the Motion-Based Multiple object Tracking example.I tried to change the video but I have this error "The filename specified was not found in the MATLAB path".Please help me in this .Thanks..</p>amani Aljefri/matlabcentral/answers/contributors/5947272-amani-aljefritag:nl.mathworks.com,2005:Question/1672942014-12-20T05:40:48Z2014-12-20T12:06:40ZFinding peaks in data based on certain threshold <p>Hi
I have an array [V Data] (Attached data file).The plot is shown below.</p><img src = "/matlabcentral/answers/uploaded_files/22814/Plot.png"><p>I want to detect the # of peaks (3 in this case) which are above a certain threshold (value is = 0.1)
I also want to find the points where it crosses the threshold and extract respective values from V</p><p>Thanks
SATEJ</p>Satej/matlabcentral/answers/contributors/5966330-satejtag:nl.mathworks.com,2005:Question/1673342014-12-20T11:56:00Z2014-12-20T12:02:41ZInstall video adapters in R2014b on Ubuntu 14.04 64bit system<p>I have a Ubuntu 14.04 64bit system on which I have installed R2014b.
With previous versions of the Image Acquisition Toolbox, the files for all of the adaptors were included in the installation. Starting with version R2014a, each adaptor is available separately through the Support Package Installer.</p><p>When I issue the command <tt>imaqhwinfo</tt>, I get the message <tt>No Image Acquisition adaptors found</tt>.</p><pre class="language-matlab">imaqhwinfo
Warning: No Image Acquisition adaptors found. Image acquisition adaptors may be available as downloadable support packages. Open Support Package Installer to install additional vendors.
</pre><p>I have opened <tt>Support Package Installer</tt> and I installed the <tt>OS Generic Video Interface</tt> in the <tt>/home/user/Documents/MATLAB/SupportPackages/R2014b</tt> folder.</p><p>When I installed it I got the following <tt>Warning</tt>:</p><pre class="language-matlab">Warning: Unable to save path to "/usr/local/MATLAB/R2014b/toolbox/local/pathdef.m".
MATLAB may not have write access to the folder. Possible fix:
1) Use SAVEPATH with an input argument to save path to a temporary file
2) Exit from MATLAB
3) Copy temporary file to MATLABROOT/toolbox/local/pathdef.m
4) Restart MATLAB and verify that support package folders are on the MATLAB path
> In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/RegistryUtils.p>RegistryUtils.savePath at 36
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/PackageInstaller.p>PackageInstaller.install at 1120
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/PackageInstaller.p>PackageInstaller.installRecursiveImp at 655
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/PackageInstaller.p>PackageInstaller.installRecursive at 473
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/+internal/executeConfirm.p>installFromFolder at 278
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/+internal/executeConfirm.p>performThreadedDownload at 188
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/+internal/executeConfirm.p>installFromInternet at 300
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/+internal/executeConfirm.p>installWorkflow at 210
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/+internal/executeConfirm.p>executeConfirm at 68
In /usr/local/MATLAB/R2014b/toolbox/shared/hwconnectinstaller/+hwconnectinstaller/Step.p>Step.next at 169
</pre><p>Still No adaptors are found. Probably I haven't installed the adaptors correctly or in the correct path or as the message as suggests the path is not saved.
Do you know the cause and the solution to this problem?</p><p>I must also add that I have tested my camera on my system and it works fine.</p><p>Thank you very much.</p>Giorgos Papakonstantinou/matlabcentral/answers/contributors/3060153-giorgos-papakonstantinoutag:nl.mathworks.com,2005:Question/1673332014-12-20T11:42:24Z2014-12-20T11:42:24Zgpu array calculation limited memory<p>Hi,
i have a quadro 2200 with 4 gig ram. I would like to do a calculation with a variable that is 6 gigabytes big. Since gpuarray is limited, I wanted to know if there is any other solutiob</p>AA/matlabcentral/answers/contributors/5703029-aatag:nl.mathworks.com,2005:Question/1673322014-12-20T11:30:29Z2014-12-20T11:30:29Zwelcom how work jump in matlab<p>welcom how work jump in matlab ....i need jump from statement to statement...how work this in matlab</p>fatima ali/matlabcentral/answers/contributors/5601917-fatima-alitag:nl.mathworks.com,2005:Question/1651462014-12-02T19:08:02Z2014-12-20T11:13:20ZMY PREDICTION DATA IS NOT UPTO DATE AS MY EXPECTATION<p>I have taken population in x and oil price in t. i have taken the year from 1984 to 2014. my work is to find the population and the oil price in the year 2015,2016,2017 or multistep like 2015,2020,2025. i have used the below code and got the result which is not expecting. how the prediction value decreases from 32 onwords while population increases and oil price increases. plz help to solve the problem.
x =</p><pre class="language-matlab">Columns 1 through 6
</pre><pre> [682.5000] [696] [711.7500] [727] [743] [759]</pre><pre class="language-matlab">Columns 7 through 10
</pre><pre> [775.2500] [792.2500] [809.2500] [826.2500]</pre><pre class="language-matlab">Columns 11 through 15
</pre><pre> [843.2500] [860] [877] [896.5000] [914.5000]</pre><pre class="language-matlab">Columns 16 through 19
</pre><pre> [932.5000] [950.5000] [968.7500] [987.5000]</pre><pre class="language-matlab">Columns 20 through 24
</pre><pre> [1.0055e+003] [1.0245e+003] [1044] [1060] [1076]</pre><pre class="language-matlab">Columns 25 through 30
</pre><pre> [1.0935e+003] [1110] [1126] [1142] [1158] [1174]</pre><pre class="language-matlab">Column 31
</pre><pre> [1.1905e+003]
t=</pre><pre class="language-matlab">Columns 1 through 6
</pre><pre> [643] [729] [737] [773] [824] [894.9000]</pre><pre class="language-matlab">Columns 7 through 10
</pre><pre> [947.4400] [987.8500] [1.0838e+003] [1.1498e+003]</pre><pre class="language-matlab">Columns 11 through 14
</pre><pre> [1.1683e+003] [1.1903e+003] [1.2749e+003] [1.3111e+003]</pre><pre class="language-matlab">Columns 15 through 18
</pre><pre> [1.4133e+003] [1.5747e+003] [1.6809e+003] [1.7655e+003]</pre><pre class="language-matlab">Columns 19 through 22
</pre><pre> [1.8444e+003] [2.0313e+003] [2.1274e+003] [2.1887e+003]</pre><pre class="language-matlab">Columns 23 through 26
</pre><pre> [2.2634e+003] [2.3463e+003] [2.4296e+003] [2.5124e+003]</pre><pre class="language-matlab">Columns 27 through 30
</pre><pre> [2.6909e+003] [2.8008e+003] [2.9077e+003] [3.0080e+003]</pre><pre class="language-matlab">Column 31
</pre><pre> [3.1162e+003]</pre><pre class="language-matlab">net = narxnet;
[X,Xi,Ai,T] = preparets(net,x,{},t);
net = train(net,X,T,Xi,Ai);
view(net)
% SIMULATE NETWORK FOR ORIGINAL SERIES
[Y,Xf,Af] = sim(net,X,Xi,Ai);
% CONTINUE SIMULATION FROM FINAL STATES XF & AF WITH ADDITIONAL
% INPUT DATA USING CLOSED LOOP NETWORK.
% Closed Loop Network
netc = closeloop(net);
view(netc)
% 10 More Steps for the first (now only) input
X2 = num2cell(rand(1,10));
% Initial input states for closed loop continuation will be the
% first input's final states.
Xi2 = Xf(1,:);
% Initial 2nd layer states for closed loop contination will be the
% processed second input's final states. Initial 1st layer states
% will be zeros, as they have no delays associated with them.
Ai2 = cell2mat(Xf(2,:));
for i=1:length(net.inputs{1}.processFcns)
fcn = net.inputs{i}.processFcns{i};
settings = net.inputs{i}.processSettings{i};
Ai2 = feval(fcn,'apply',Ai2,settings);
end
Ai2 = mat2cell([zeros(10,2); Ai2],[10 1],ones(1,2));
% Closed loop simulation on X2 continues from open loop state after X.
Y2 = sim(netc,X2,Xi2,Ai2);
plot(1:length(t),cell2mat(t))
hold on
plot(1:length(Y),cell2mat(Y),'r')
plot(length(t):length(t)+length(Y2)-1,cell2mat(Y2),'g')
legend('Input data & target series','One-step ahead prediction','Multi-step prediction beyond target series');
</pre>srikanta mohapatra/matlabcentral/answers/contributors/5511202-srikanta-mohapatratag:nl.mathworks.com,2005:Question/1655952014-12-05T16:51:36Z2014-12-20T10:57:46ZInputname() in Nested Functions: how to integrate the Input variable name of a function in a ".txt" file (opened in the function) when the input itself comes form a loop-function?<p>I have a main function (function1) that prints the results in a .txt file named with the inputname of function1. because I need to do evaluations for many differend variables, I use a second function with a loop (function 2). The input values for function1 are in the base workspace:</p><pre class="language-matlab">function [] = function2()
</pre><pre class="language-matlab">s=['a';'b';'c';'d']
for j=1:length(s)
function1(evalin('base',strcat(s(j,:))))
end
end
</pre><p>and</p><pre class="language-matlab">function [O] = function1(I)
[...]
inputn=inputname(1);
out=fopen(['function1_',inputn,'.txt'],'wt');
fprintf(out,'..results..');
fclose(out);
[...]
end
</pre><p>If i use only function1(a), a text-file is created that is called function1_a.txt
If i use the loop, the name of the text-file doesn't change and is just called "function1_.txt" (overwrites the file with each iteration in function 2).
I know, there might be smarter ways to code without evalin(...) but this worked so far...</p><p>How can I get a new .txt file for every single Input variable (function1_a.txt, function1_b.txt,...)?
(R2012)</p><p>Many thanks for your help, kind regards Jo.</p>Jo/matlabcentral/answers/contributors/5331875-jotag:nl.mathworks.com,2005:Question/1671192014-12-18T18:23:38Z2014-12-20T10:55:40ZForecasting by Neural Network<p>Hello everyone ! I am entirely new to the "Neural Network Toolbox". However I have explored many example data sets provided in NN toolbox , but i am having trouble in fitting my own case study into it . i am frustrated and completely drained out after following many webinars and searching here. Your help will be highly appreciated . My problem is as follows .</p><pre> I have the data set which contains monthly demand of 30 vehicle models of a heavy commercial automobile manufacturer for the past 3 years. In short , my datasheet is of size [ 30 X 36 ] , ( 30 vehicle models are represented row wise) . </pre><p>I want to forecast the future demand of all vehicles by using Neural Network . I have tried using Curve Fitting , Time series (both NAR and NARX) by the default setting and various training algorithms , But still the MSE is not acceptable . Is it just because of my "SMALL data set" ? or anything else ?</p><p>Kindly suggest me some method (or some way ) , So that i can work with the same dataset and predict the future values by using Neural Network .</p><p>Your coperation will be higly praised . Thank You all in advance ( Please ignore my bad english)</p>pradeep kumar/matlabcentral/answers/contributors/5306014-pradeep-kumartag:nl.mathworks.com,2005:Question/1373932014-06-24T16:55:44Z2014-12-20T10:54:45ZHow can we encourage more thoughtful feedback on FEX submissions? <p>Is there a way that either TMW or File Exchange (FEX) users can encourage more thoughtful feedback on FEX pages? I find that ratings without verbal feedback are not very helpful. I always wonder, "did you give this submission one or two stars because there are errors in the code; because it's computationally inefficient; because you didn't take the time to learn how to use it; because it was designed to solve a different problem than the problem you are trying to solve?" A five-star rating can be a helpful endorsement, but when I see a four-star rating without explanation I am left to wonder about the submission's weaknesses.</p><p>Perhaps the most confounding rating is a three-star rating without comment. What does it mean? On more than one occasion I've even noticed users who have created a Mathworks account simply to leave a three-star rating without comment, and have not left any other feedback on FEX. Clearly they're driven to express their lack of opinion, but there's no telling why.</p><p>It's counter-intuitive, but I think reducing the five-star rating system to a simple thumbs-up/thumbs-down rating could actually add nuance, particularly if a minimum word limit were required when giving a negative review. Amazon has recognized the value of a minimum word limit in reviews, and it's turned out to be quite helpful.</p><p>Without a redesign of the FEX rating system, is there a way to encourage more thoughtful feedback?</p>Chad Greene/matlabcentral/answers/contributors/1062128-chad-greenetag:nl.mathworks.com,2005:Question/1673032014-12-20T06:48:05Z2014-12-20T10:46:28ZEditor code completion for MATLAB Handle classes?<p>When working with the definition for a handle class. Can the code completion feature see the methods and properties of the class?</p><pre class="language-matlab">classdef A < handle
properties
a;
b;
end
</pre><pre> methods
function obj = A()
obj.b = 1; %Code Editor does not see the property b when I type in the period after obj.
end
end
end</pre><p>Code Editor does not see the property b when I type in the period after obj.</p>John/matlabcentral/answers/contributors/5415607-johntag:nl.mathworks.com,2005:Question/1673312014-12-20T10:01:21Z2014-12-20T10:42:25ZHow can I find the roots of a symbolic polynimial<p>I create a symbolic transfer function matrix. I find its inverse. The first element of the matrix is a polynomial. Note that this polynomial is symbolic so no operation can be done on it. I want to convert this to a polynomial and find the roots. How should I go about this? Thanks.</p><p>aa =</p><p>- 30*s^4 + 300*s^3</p><p>>> coeffs(aa)</p><p>ans =</p><p>[ 300, -30]</p><p>Here aa is the polynomial I go ahead and extract the coefficients and then i can do a "aa=double(aa)" to convert it to double. And then find the roots. But the problem is When I do the coeffs(aa) i should get [-30 300 0 0] and not [300 -30]. Even if I get [0 0 300 -30], I can get my way through. But the issue is i need those missing zeros (coefficients of s^2 and s^1).</p><p>Thanks,</p>Ron Aditya/matlabcentral/answers/contributors/4529545-ron-adityatag:nl.mathworks.com,2005:Question/1672752014-12-20T02:47:04Z2014-12-20T10:25:31ZHow to solve a system of (a large number of) nonlinear simultaneous equations using MATLAB?<p>I have about 10,000 non-linear equations that need to be solved simultaneously. How can I set up codes in MATLAB or use its tools to solve them?</p><p>Many of the equations I have are in this form:</p><pre class="language-matlab">log(Y(i)) = log(A(i)) + B(i)* log[ X1(i)^(-1/rho(i)) + X2(i)^(-1/rho(i)) + X3(i)^(-1/rho(i)) ]
</pre><p>i is an index (i.e i = 1, 2, 3,...,45 ). Y(i), X1(i), X2(i) and X3(i) are the variables that need to be solved and maybe different for each i. A(i), B(i), rho(i) are known parameters for all i.</p><p>So the equation above actually represents a total of 45 different equations, as shown below.</p><pre class="language-matlab">log(Y(1)) = log(A(1)) + B(1)* log[ X1(1)^(-1/rho(1)) + X2(1)^(-1/rho(1)) + X3(1)^(-1/rho(1)) ]
log(Y(i)) = log(A(2)) + B(2)* log[ X1(2)^(-1/rho(2)) + X2(2)^(-1/rho(2)) + X3(2)^(-1/rho(2)) ]
...
log(Y(45)) = log(A(45)) + B(45)* log[ X1(45)^(-1/rho(45)) + X2(45)^(-1/rho(45)) + X3(45)^(-1/rho(45)) ]
</pre><p>There are many other equations that link one variable X(i) to others. For example, I might also have a set of equations below.</p><pre class="language-matlab">log(X(i)) = log(C(i)) + D(i)* log[ Z1(i)^(-1/mu(i)) + Z2(i)^(-1/mu(i)) + Z3(i)^(-1/mu(i)) ]
</pre><p>for each i in {1, 2, 3,...,45}. Similarly C(i), D(i) and mu(i) are known parameters.</p><p>If listed all of the equations, at the end, the number of equations will be the same as the number of variables.</p>Ken Kajonchai/matlabcentral/answers/contributors/6002283-ken-kajonchaitag:nl.mathworks.com,2005:Question/1672532014-12-19T19:31:37Z2014-12-20T10:18:00ZUsage Of "goto" for previous lines<p>hello guys
Iva had a simple but confusing question... i was writing a program for Euler's formula, then I found out Matlab doesn't have any "goto" function for refering to previous lines . i was looking for an alternate and i will appreciate it if you guys help me with this :)
here's an example:</p><pre> x=[0.1:0.1:1]
h=0.1
i=1
y(1)=1
Z(1)=1.1
Y(1)=1.1
%Y'=y*(x^(1/3))
while i<11
y(i+1)=y(i)+(h*(x(i)*(y(i)^(1/3))))
Z(i+1)=(x(i+1)*(y(i+1)^(1/3)))
line** y(i+1)=y(i)+(0.5*h*(Y(i)+Z(i+1)))
Y(i+1)=x(i+1)+y(i+1)
if abs(Y(i+1)-Z(i+1))>0.00000000001
Z(i+1)=Y(i+1)
goto(line**)
end
i=i+1
end</pre>Hossein/matlabcentral/answers/contributors/6001849-hosseintag:nl.mathworks.com,2005:Question/1671122014-12-18T16:59:11Z2014-12-20T10:17:37Zconverting a function into a code ?<p>hello everyone
i'm struggling with this question
(sin(x), exp(x^2-y^2), 0)
how do i convert the whole thing into a matlab code ?
and how can i use matlab to find the "curl" of a function ?</p>maryam 94/matlabcentral/answers/contributors/4888532-maryam-94tag:nl.mathworks.com,2005:Question/1670322014-12-18T05:52:54Z2014-12-20T10:15:33ZI have 32x32 matrix...But I want to make this a 512x512 matrix with the same element as in the 32x32 matrix..and the rest of which would be zero in 512x512 matrix.. how do i do it?? <p>I have 32x32 matrix...But I want to make this a 512x512 matrix with the same element as in the 32x32 matrix..and the rest of which would be zero in 512x512
matrix..
how do i do it??</p>Sanik/matlabcentral/answers/contributors/5509302-saniktag:nl.mathworks.com,2005:Question/1673062014-12-20T07:22:56Z2014-12-20T09:37:24Zfind the coordinates of an image<p>how to get the xy coordinates of palm from the image</p><img src = "/matlabcentral/answers/uploaded_files/22818/013012_1_1.png">RAMESH MUNIRATHINAM/matlabcentral/answers/contributors/1799784-ramesh-munirathinamtag:nl.mathworks.com,2005:Question/1672912014-12-20T05:34:39Z2014-12-20T09:12:24ZUnstructured grid to structured grid<p>Dear all,
what would be the best way, in your opinion, to get a structured grid out of an unstructured grid?</p><p>What I have is something like this:</p><pre class="language-matlab">x y f
</pre><pre class="language-matlab">1 12 7
3 10 4
1 11 2
2.4 15 0
</pre><p>So basically x and y are totally random and in no specific order. What I need is to resample the values of f on a structured grid with a constant step.</p><p>I had a quick look at interp2 and it looks like it will only work if my vectors are strictly monotonic which is not the case as I have plenty of repeated values for x and y.</p><p>Thanks a lot</p>Lorenzo/matlabcentral/answers/contributors/1211445-lorenzotag:nl.mathworks.com,2005:Question/465992012-08-23T18:28:00Z2014-12-20T08:57:13Zautomatic kmeans: choosing the number of clusters automatically?<p>Hi, I was wondering if there is a way in matlab to do automatic kmeans clustering where the number of clusters K is choosen automtically instead of being user defined? Thanks</p>jenka/matlabcentral/answers/contributors/1181469-jenkatag:nl.mathworks.com,2005:Question/1670992014-12-18T14:43:42Z2014-12-20T08:56:05ZUsing subrange makes array operations slow<p>This is a question about the performance of code which I would naively expect to be much better. I define two random arrays:</p><pre class="language-matlab">a = randn(1, 10000);
b = randn(10000, 1);
</pre><p>Then try to multiply them together in two ways:</p><pre class="language-matlab">timeit(@() a*b)
</pre><pre class="language-matlab">ans =
</pre><pre> 4.3080e-06</pre><pre class="language-matlab">timeit(@() a(1:10000)*b(1:10000))
</pre><pre class="language-matlab">ans =
</pre><pre> 1.5634e-05</pre><p>You can see that when I use a sub-range of the arrays, multiplication gets about 3.6x slower, even in the case when the subrange is the whole array.</p><p>I could imagine that there is some overhead in parsing the subrange part of the command; but when the vectors become longer, the "overhead" grows:</p><pre class="language-matlab">a = randn(1, 1000000);
b = randn(1000000, 1);
timeit(@() a*b)
</pre><pre class="language-matlab">ans =
</pre><pre> 0.0010</pre><pre class="language-matlab">timeit(@() a(1:1000000)*b(1:1000000))
</pre><pre class="language-matlab">ans =
</pre><pre> 0.0062</pre><p>So, I have the two-fold question:</p><p>1) As a matter of curiosity, why is the performance so much worse when I use sub-ranges?</p><p>2) When we wish to perform read-only operations on sub-ranges, what can we do (besides copying the array) to keep performance reasonable?</p><p>Thanks,
Clayton</p><p>PS. Version information:
MATLAB Version: 8.3.0.532 (R2014a)
Operating System: Microsoft Windows 7 Ultimate Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot™ 64-Bit Server VM mixed mode</p>Clayton Davis/matlabcentral/answers/contributors/5437741-clayton-davistag:nl.mathworks.com,2005:Question/1673092014-12-20T08:28:27Z2014-12-20T08:49:51Zwho can i apply for a job?<p>I am Electrical Engineer and i invent a new application for analyzing electric circuits at parametric approach. I am from Iran and I want to apply for a job in Mathworks. Can i do it? if yes, how can i do it?
Thank you</p>mohamad Jahanmahin/matlabcentral/answers/contributors/3632738-mohamad-jahanmahintag:nl.mathworks.com,2005:Question/1672282014-12-19T15:12:22Z2014-12-20T08:49:19ZCan we define operators in MATLAB?<p>I started learning OOP in MATLAB and I saw that we can either use the colon(A,B) syntax or simply A:B. This kind of method works for other operators and we may even redefine how they work.</p><p>My question is: can we somehow achieve that MATLAB recognises some other symbols we define? For example, I want to use ° for dyadic product in my class and if I typed A°B, dyadic(A,B) would be executed on objects A and B.</p>Zoltán Csáti/matlabcentral/answers/contributors/2924415-zoltan-csatitag:nl.mathworks.com,2005:Question/1673082014-12-20T08:12:24Z2014-12-20T08:31:33ZI am newbie in the matlab, may some experts tell me what are the meaning of codes or logic in this file?<p>Hello, I am a new user to MatLab, but I actually don't actually know what i should type in the matlab program to let me run my desired program.</p><p>Actually, I am doing my final year project with the mitigation and the simulation of the bus stop. In order to simulate the real scenario, I use a distribution and a program flow to simulate the bus congestion.</p><p>However, as I am new to Matlab, my program files are given by my supervisor and I don't know what is the logic flow or meaning of the codes in the files.</p><p>May some experts tell me the flow of the program codes and help me?
Thank you very much.</p><p>The following are the codes.</p><p>Files: Sim_FIFO_MDc.m</p><pre class="language-matlab">global size;
global Avg_Wait;
global Avg_Wait_Q; % Average wait time in queue per bus
global Serv_Rate;
global Arr_Rate;
</pre><pre class="language-matlab">global U0; %parameters same as Sim.m
global j0;
global IntArr;
global Arr;
global Serv;
global Wait;
global Wait_Q;
global Wait_S;
global Pos;
global c;
global Cs;
</pre><pre class="language-matlab">% Generate inter-arrival time vector
IntArr(1 : size) = -1 / Arr_Rate * log(U0(j0 : j0 + size - 1));
% Inter-arrival time follows an exponential distribution (i.e., bus arrivals are Poisson)
j0 = j0 + size;
</pre><pre class="language-matlab">% Generate service time vector
Serv(1 : size) = (1 / Serv_Rate) * ones(size, 1); % Service time is deterministic
</pre><pre class="language-matlab">% Serv(1 : size) = gamrnd(1 / Cs ^ 2, Cs ^ 2 * Serv_Rate, size, 1);
% Service time follows gamma distribution, where mean is 1, and coefficient of variation is Cs
Arr(1 : size) = cumsum(IntArr); % Calculate arrival times
Wait_Q(1) = 0;
Wait_S(1) = 0;
Pos(1) = 1;
</pre><pre class="language-matlab">for i = 2 : size % iterate for all the buses
if Pos(i - 1) == c
Wait_Q(i) = max(0, Wait_Q(i - 1) + Serv(i - 1) + Wait_S(i - 1) - IntArr(i));
else
Wait_Q(i) = max(0, Wait_Q(i - 1) - IntArr(i));
end
</pre><pre> if Wait_Q(i - 1) + Serv(i - 1) + Wait_S(i - 1) < IntArr(i) + Wait_Q(i) + 0.0001
Pos(i) = 1;
else
Pos(i) = Pos(i - 1) + 1;
end</pre><pre> Wait_S(i) = max(0, Wait_Q(i - 1) + Serv(i - 1) + Wait_S(i - 1) - Wait_Q(i) - Serv(i) - IntArr(i));
end</pre><pre class="language-matlab">Wait = Wait_Q + Wait_S;
</pre><pre class="language-matlab">Avg_Wait = mean(Wait);
Avg_Wait_Q = mean(Wait_Q);
</pre><pre class="language-matlab">Files: Sim.m
</pre><pre class="language-matlab">T_start = clock; % see if the program ends or not, ctrl+c can stop the program
</pre><pre class="language-matlab">global size; % number of buses in each round go into the bus stop
size = 200000; % set it into a high size because to reduce the fluctuation error
global Avg_Wait; % Average wait time per bus
global Serv_Rate; % Service rate (inverse of average service time per bus)
Serv_Rate = 1; %set service rate to one , don't care the unit at all.
global Arr_Rate; % Arrival rate of buses (i.e., bus flow) (eg, 3 buses per time unit(serv_rate))
</pre><pre class="language-matlab">global U0; %used for indexes
global j0;
%all the following global variables is having the size of "size".
global IntArr; % Vector for inter-arrival times (headway)
global Arr; % Vector for arrival times
global Serv; % Vector for service times
global Wait_Q; % Vector for bus wait times in queue
global Wait_S; % Vector for bus wait times in berths
global Wait; % Vector for bus wait times (sum of Q+S)
global Pos; % Vector for the berth numbers where buses dwell
global c; % Berth number (0,1,2) max=2 berths
global Cs; % Coefficient of variation in service time
</pre><pre class="language-matlab">M = 20000000; %random number generator
U0 = rand(M, 1); % Random seed (a vector of random numbers of size M, each is uniformly distributed between 0 and 1)
j0 = 1; %random take one number from 0 to 1
</pre><pre class="language-matlab">IntArr = zeros(size - 1, 1);
Arr = zeros(size, 1);
Serv = zeros(size, 1);
Wait = zeros(size, 1);
Wait_Q = zeros(size, 1);
Wait_S = zeros(size, 1);
Pos = zeros(size, 1);
</pre><pre class="language-matlab">Cs = 0.5; % coefficient of variation in service time
c = 2; % number of berths
</pre><pre class="language-matlab">%plotting the figure start from 2 because first one always zero.
for i0 = 2:20 % Need 20 data points on the curve
% Arr_Rate = 0.15, 0.25, ..., 1.95, subject to adjustment
Arr_Rate = 0.1 * (i0-1) + 0.05;
Sim_FIFO_MDc; %deterministic function service time
beta(i0) = Arr_Rate / c; % beta = bus flow per berth
W(i0) = Avg_Wait; % Average wait time per bus
</pre><pre> if j0 > M - 200 * size %reset the U0 and j0 if data is not enough
U0 = rand(M, 1);
j0 = 1;
end
end</pre><pre class="language-matlab">% First data point
beta(1) = 0;
W(1) = 0;
</pre><pre class="language-matlab">plot(beta, W);
</pre><pre class="language-matlab">T_end = clock;
T_dur = T_end - T_start;
fprintf('\nThe simulation takes %4.2f seconds.\n' ...
, T_dur(4) * 3600 + T_dur(5) * 60 + T_dur(6));
</pre>Echo/matlabcentral/answers/contributors/6002556-echotag:nl.mathworks.com,2005:Question/1673042014-12-20T07:04:02Z2014-12-20T08:09:20ZCount the index of the array<p>Hi, I have a array like below:
[0
0
0
0
0
0
0
0
0
10
0
0
0
0
15
0
17]</p><p>I want count how many numbers >0 in the array (like in this case count is 3 (because 10,15,&17). Can some please help me how to count this in matlab.
Thanks in advance</p>Mekala balaji/matlabcentral/answers/contributors/5786945-mekala-balajitag:nl.mathworks.com,2005:Question/1673072014-12-20T07:23:09Z2014-12-20T08:00:29ZChecking the repeated values, add them and find mean<p>I m working on my project, where i have 2 images as Img1 and Img2. As Img1 is the binary image so i have calculated all decimal values. For Img2 i have taken the pixel values.</p><p>For convenience i have taken 10X10 matrix values from the entire image for the below operation.</p><pre class="language-matlab">[row,col] = size(Img1);
m = zeros(row,col);
w = [1 2 4 8; 16 32 64 128; 256 512 1024 2048; 4096 8192 16384 32768];
for i=2:10
for j=2:10
O = double(Img1(i-1:i+2,j-1:j+2));
m(i,j) = sum(sum(O.* w));
</pre><pre> end;
end;
[row,col] = size(Img2);
count = row*col;
outMat = zeros(4,4,count);
l=0;
O = zeros(1,256);
for i=2:10
for j=2:10
l=l+1;
outMat(:,:,l) = Img2(i-1:i+2,j-1:j+2);
vec = outMat(3,3,:);
vec = vec(:);
end;
end;
Now, for Img2 , i have collected all pixel values, and need to store 2 col.as below.</pre><pre class="language-matlab">Col1 col2 from Img2
from Img1
44128 162
54960 150
58320 119
31200 120
48240 180
54960 160
44128 163
51109 90
44128 56
Here, 44128 is repeated 3 times,now adding all correspong mapping values from col2 i.e. 162,163,56 add them all divide by 3(becos occurance of 44128 is 3 times) and same procedure to be followed for all values.
</pre><pre class="language-matlab">44128 (162+163+56)/3
54960 (150+160)/2
58320 (119/1)
31200 (120/1)
48240 (180/1)
51109 (90/1)
Here, I want to create an array N of 1D 1X(size of col) which acts as a counter of Img1 decimal values,repeated values and store the counter values inside N, and then finding mean by dividing corresponding counter values of N to the Img2 pixel values as above.
</pre><p>Please help:-( , how can i write the code inside the for loop above.</p>Sanghamitra Tripathy/matlabcentral/answers/contributors/5068829-sanghamitra-tripathytag:nl.mathworks.com,2005:Question/1673052014-12-20T07:15:13Z2014-12-20T07:58:09ZHow can I substitute a variable?<p>Dear community,</p><p>How can I use <b>'subs'</b> here?</p><p>I defined x array to interpolate y and here I want to substitute x= 2 into y . By the way, how can I substitute x into y?</p><pre> a= 5;
x = 0:pi/10:pi;
y = a*sin(x).^2 ./(sin(x) + cos(x));
subs ( y,{x},{2} ) --> it won't work by doing like this</pre><p>Thanks in advance</p>Moj/matlabcentral/answers/contributors/4426902-mojtag:nl.mathworks.com,2005:Question/1671942014-12-19T09:01:41Z2014-12-20T07:34:50ZFastest & most effective way to create this uniqe matrix:<p>Hey there,
I need to create this matrix as a bonus for a work i have, can't find the paradigm here:</p><pre class="language-matlab">A =
1 2 3 8 1 6
2 1 0 3 5 7
3 0 1 4 9 2
8 3 4 1 0 3
1 5 9 0 1 2
6 7 2 3 2 1
</pre><p>It must be in an effective & short way.
Thank you if anyone can help with this one.</p>Eitan/matlabcentral/answers/contributors/6000657-eitantag:nl.mathworks.com,2005:Question/1673022014-12-20T06:34:21Z2014-12-20T07:01:57Zdetermining number of inputs<p>hello.
usually in matlab, we ask the user to enter a value once using this code x=input('message').
but what if we wanted the user to determine how many times to enter a value?</p>maryam 94/matlabcentral/answers/contributors/4888532-maryam-94tag:nl.mathworks.com,2005:Question/1671212014-12-18T18:36:00Z2014-12-20T06:58:24ZHow to create a 2D circular intensity plot?<img src = "/matlabcentral/answers/uploaded_files/22753/snapshot.png"><p>Hi,
I can generate 2D plots like in the image above in comsol. I want to generate the same in matlab. This is a plot of electric field distribution in a cylindrical resonator. My matlab code has the electric field as a function of radius and angle. May be creating a meshgrid and then using polar command might be the way to go but I am not sure how to do that correctly. Any suggestion or link would be appreciated.
Thanks <a href = "</matlabcentral/answers/uploaded_files/22752/snapshot.png"></matlabcentral/answers/uploaded_files/22752/snapshot.png</a>></p>Zeba/matlabcentral/answers/contributors/2270000-zebatag:nl.mathworks.com,2005:Question/1670152014-12-18T01:29:36Z2014-12-20T06:57:00ZCan I restore the original matrix back from its gray scale image?<p>Please I have converted a matrix with floating numbers into gray scale(normalized the intensity values to 0-1) but I want to convert this gray scale mat file back to the original matrix. Can someone help please? I am quite new in Matlab please.</p>Folake Olaniyan/matlabcentral/answers/contributors/5997601-folake-olaniyantag:nl.mathworks.com,2005:Question/1671082014-12-18T16:37:42Z2014-12-20T06:44:19Zhow can i remove object bigger than x pixel <p>i know that bwareaopen remove small elements , but how can i remove object bigger than x pixels???</p><p><a href = "http://www.image-share.com/ijpg-2791-262.html">http://www.image-share.com/ijpg-2791-262.html</a></p><p>i want to just the letter to stay so how can i remove that 2 big objects???</p>Lukasz Jarod/matlabcentral/answers/contributors/5985971-lukasz-jarodtag:nl.mathworks.com,2005:Question/1668422014-12-16T17:49:12Z2014-12-20T06:39:14ZArtificial neural network - weights & biases - prediction of output manually<p>Dear sir,
I have used NFtool in MATLAB R2013a version.
The network has 4 input neurons,10 hidden neurons and 1 output neuron (4:10:1).
After training weights and biases are as follows:
w1=[0.750864871929357,-1.04662070128428,0.555215506062414,-2.41372663384;
-1.33674312135999,-1.85497432421788,0.171644014211756,-1.00901376117434;
-1.17697464915732,-1.08381929419222,2.01867242513843,0.385346102708722;
-0.0982385098389994,1.43234967610556,-1.41891080319675,-2.09657813780530;
1.08226078842391,-1.36558283863748,1.20315995998298,1.33386725200220;
-1.44768438970138,1.42745137761629,-0.548723980920127,1.52251782685021;
-0.230162677732705,-1.06104686232403,2.13730692111303,0.0887419171415393;
-1.56156708761931,0.954115050802265,1.54060918006507,-0.37101963949;
1.10848762448537,-0.547779828726692,0.623497558837630,-2.08211223923105;
-0.796185938428902,-1.87122284630215,-0.667945823175087,-0.3641647426447];</p><p>w2=[-1.28202522701169,-0.542561923373967,1.19938712052237,0.790702378108044,0.369732822823546,0.135892694919764,0.604111142205213,-0.00267333272566883,-0.176734563355046,0.637073092209164];</p><p>b1=[-2.13336267394184;1.92619564521441;1.70251721423456;0.930601278940955;0.0521504054343906;-0.766964385399286;-1.16952707663656;-1.86958140128970;1.81604428796975;-3.22036974290436];</p><p>b2=[-0.165085306853076];</p><p>Based on these weights and biases, I have predicted the output (z) by using the following equation….</p><p>z =((b2)+(w2*tansig(b1+w1*x')));</p><p>while doing so, for one of the sets (200 150 30 10), the output is =
-0.0694 which is not equal to the actual value of 61.5</p><p>But the same thing if I do simulate function and calculate the value, the output is = 61.53 which is close to the actual value of 61.5.</p><p>Why is this discrepancy?
I tried with mampminimax function also….but no use! Can anyone help me?</p>Raja/matlabcentral/answers/contributors/3534192-rajatag:nl.mathworks.com,2005:Question/1667642014-12-16T03:32:29Z2014-12-20T06:34:50ZHow to plot from certain range of data?<p>Hi everyone,</p><p>Actually I want find the stepinfo value but I have huge amount of data (many square waves of data). As far as I know stepinfo can determine if the signal in one square wave. Therefore I want to plot the data in certain range. The data (x and y) are in same folder of the workspace. What I did is below but did not work.</p><p>1.</p><pre class="language-matlab">>> x=Scope1(:,1);
>> x=[10:0.02:20];
>> y=Scope1(:,3);
>> plot(x,y)
Error using plot.
Vectors must be the same lengths.
</pre><p>2.</p><pre class="language-matlab">>> x=Scope1(:,1);
>> xlim=([10 20]);
>> y=Scope1(:,3);
>> plot(x,y)
</pre><p>Number 2 produce no error but it plots whole data (xlim is not functioning).</p><p>I also tried with fplot (function, xlim ) but it didn't work (it plot y=x).</p><pre class="language-matlab">>> x=Scope1(:,1);
>> y=Scope1(:,3);
>> fplot('y' , [10 20])
</pre><p>Can anybody help me how to plot?</p><p>Thank you in advance!</p><p>arys</p>arymas/matlabcentral/answers/contributors/2574381-arymastag:nl.mathworks.com,2005:Question/1650162014-12-02T01:29:51Z2014-12-20T06:32:14ZHow can I create a button that says yes & no?<p>Hello, how can I create a yes & no button to a question that I want to prompt the user's answer to and then also store whether the user clicked yes or no?</p>HC/matlabcentral/answers/contributors/5952492-hctag:nl.mathworks.com,2005:Question/1238152014-03-31T08:55:56Z2014-12-20T06:29:42ZHOW TO SEGMENT A WORD INTO CHARACTERS USING VERTICAL PROJECTION?<p>hello everyone! i am trying to segment a word into characters using vertical projection of histogram. i can find the histogram and i am able to find the threshold value. the histogram looks like this.</p><img src = "/matlabcentral/answers/uploaded_files/10658/vertical.jpg"><p>as you can see that there are 4 peaks in the histogram hence i am assuming it represents the 4 characters from the above figure.</p><p>the code is given in the figure below.</p><img src = "/matlabcentral/answers/uploaded_files/10657/code.png"><p>now i am stuck with how to segment each characters after finding the threshold. can anyone help me with this??</p>soumyadeep/matlabcentral/answers/contributors/5043416-soumyadeeptag:nl.mathworks.com,2005:Question/1226702014-03-22T15:31:27Z2014-12-20T06:29:41ZCalculate the edge of a transparent object<p>Hi!
I'm trying to calculate the profile of a lens. I took the picture of the profile and now i'm trying to find the edge of the lens with a matlab code.
I tryed to use edge detection algorithm but the problem is that the shades on the lens make it difficult.</p><p>I attach the picture</p><p>Does anybody can help me?
Thank you in advance :)</p>clara Lagomarsini/matlabcentral/answers/contributors/2894369-clara-lagomarsinitag:nl.mathworks.com,2005:Question/240412011-12-15T12:42:02Z2014-12-20T06:24:02ZCut An Image<p>Hi All,</p><p>Is there a way by which we can separate an image like this?</p><p><a href="http://i39.tinypic.com/tamp9f.png">http://i39.tinypic.com/tamp9f.png</a></p><p>I would like to get an output like below.</p><p><a href="http://i43.tinypic.com/2a0doxs.png">http://i43.tinypic.com/2a0doxs.png</a></p><p>I tried morphological operation but i could not and I am not sure that it is a true way.</p><p>Thanks in advance.</p>bahar cham/matlabcentral/answers/contributors/3155423-bahar-chamtag:nl.mathworks.com,2005:Question/1673002014-12-20T06:06:28Z2014-12-20T06:07:31ZDetect outer contour and find contour's co-ordinates, at sub-pixel level, ignoring noise.<p>Hi,</p><p>I want to find the co-ordinates of an object's contour (similar to a circular rim) which will be rotated in 3D. This need not appear like a circle when rotated in 3D. (Only the outermost contour is sufficient)</p><p>Also, if the contour has little noise, then I want this algorithm to ignore noise, and detect the correct contour of rim.</p><p>This should be done at a subpixel level (detecting contours).</p><p>It should be fast.</p><p>These points I have mentioned above are the requirements I have.</p><p>In order to do this, I have tried the following:</p><ol><li>Simple Sobel / Canny edge detectors. These do not give sub-pixel accuracy. Moreover, it does not tolerate any noise.</li><li><a href = "http://in.mathworks.com/matlabcentral/fileexchange/23445-chan-vese-active-contours-without-edges">Chan Vese Active Contours without edges</a>. This algorithm detects at subpixel level, but is extremely slow (I am working with images of resolution around 10MP).</li><li><a href = "http://in.mathworks.com/matlabcentral/fileexchange/9168-detect-circles-with-various-radii-in-grayscale-image-via-hough-transform">Detect circles with various radii in grayscale image via Hough Transform.</a> This has given me the best results so far. Here are a couple of points about this algorithm:</li></ol><ul><li>It has subpixel accuracy, as shown below:</li></ul><img src = "/matlabcentral/answers/uploaded_files/22817/Example%20of%20Tao%20Peng's%20output.png"><ul><li>This is fast enough.</li><li>It takes input as grayscale image and extracts contour information from this (instead of converting it to binary as many other algorithms I have come across do, therefore losing information).</li><li>If it encounters any noise on the contours, it ignores it and finds the contour (As displayed in the image below (I have introduces a little noise on the left side of rim's contour, and the algorith still works very well!)).</li></ul><img src = "/matlabcentral/answers/uploaded_files/22815/distorted_imgs.bmp"><ul><li>The problem with this is that when I rotate my object (circular rim) in 3D a little more, it cannot detect contour. (I have attached an image (Hough_grd_doesnt_work_for_this.bmp))</li><li>Since I am interested in detecting the contours, I also want the co-ordinates of the detected contour for my further processing. Using this algorithm, I am not able to access the co-ordinates.</li></ul><p>This is the problem I am facing.</p><p>I want to know if there's any other algorithm which I can use for my work. Or if I can make some changes to CircularHough_Grd to make it more flexible.</p><p>Any inputs will be appreciated.</p><p>Thank you.</p>Sanya/matlabcentral/answers/contributors/5488039-sanyatag:nl.mathworks.com,2005:Question/1669452014-12-17T13:03:03Z2014-12-20T05:49:32Zi got this code from mathwork.......and i m getting this error "Function definitions are not permitted in this context". Please help m<pre class="language-matlab">% SLIC Simple Linear Iterative Clustering SuperPixels
%
% Implementation of Achanta, Shaji, Smith, Lucchi, Fua and Susstrunk's
% SLIC Superpixels
%
% Usage: [l, Am, Sp, d] = slic(im, k, m, seRadius, colopt, mw)
%
% Arguments: im - Image to be segmented.
% k - Number of desired superpixels. Note that this is nominal
% the actual number of superpixels generated will generally
% be a bit larger, espiecially if parameter m is small.
% m - Weighting factor between colour and spatial
% differences. Values from about 5 to 40 are useful. Use a
% large value to enforce superpixels with more regular and
% smoother shapes. Try a value of 10 to start with.
% seRadius - Regions morphologically smaller than this are merged with
% adjacent regions. Try a value of 1 or 1.5. Use 0 to
% disable.
% colopt - String 'mean' or 'median' indicating how the cluster
% colour centre should be computed. Defaults to 'mean'
% mw - Optional median filtering window size. Image compression
% can result in noticeable artifacts in the a*b* components
% of the image. Median filtering can reduce this. mw can be
% a single value in which case the same median filtering is
% applied to each L* a* and b* components. Alternatively it
% can be a 2-vector where mw(1) specifies the median
% filtering window to be applied to L* and mw(2) is the
% median filtering window to be applied to a* and b*.
%
% Returns: l - Labeled image of superpixels. Labels range from 1 to k.
% Am - Adjacency matrix of segments. Am(i, j) indicates whether
% segments labeled i and j are connected/adjacent
% Sp - Superpixel attribute structure array with fields:
% L - Mean L* value
% a - Mean a* value
% b - Mean b* value
% r - Mean row value
% c - Mean column value
% stdL - Standard deviation of L*
% stda - Standard deviation of a*
% stdb - Standard deviation of b*
% N - Number of pixels
% edges - List of edge numbers that bound each
% superpixel. This field is allocated, but not set,
% by SLIC. Use SPEDGES for this.
% d - Distance image giving the distance each pixel is from its
% associated superpixel centre.
%
% It is suggested that use of this function is followed by SPDBSCAN to perform a
% DBSCAN clustering of superpixels. This results in a simple and fast
% segmentation of an image.
%
% Minor variations from the original algorithm as defined in Achanta et al's
% paper:
%
% - SuperPixel centres are initialised on a hexagonal grid rather than a square
% one. This results in a segmentation that will be nominally 6-connected
% which hopefully facilitates any subsequent post-processing that seeks to
% merge superpixels.
% - Initial cluster positions are not shifted to point of lowest gradient
% within a 3x3 neighbourhood because this will be rendered irrelevant the
% first time cluster centres are updated.
%
% Reference: R. Achanta, A. Shaji, K. Smith, A. Lucchi, P. Fua and
% S. Susstrunk. "SLIC Superpixels Compared to State-of-the-Art Superpixel
% Methods" PAMI. Vol 34 No 11. November 2012. pp 2274-2281.
%
% See also: SPDBSCAN, MCLEANUPREGIONS, REGIONADJACENCY, DRAWREGIONBOUNDARIES, RGB2LAB
% Copyright (c) 2013 Peter Kovesi
% Centre for Exploration Targeting
% School of Earth and Environment
% The University of Western Australia
% peter.kovesi at uwa edu au
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% The Software is provided "as is", without warranty of any kind.
% Feb 2013
% July 2013 Super pixel attributes returned as a structure array
%
% Note that most of the computation time is not in the clustering, but rather
% in the region cleanup process.
clc;
clear all;
close all;
</pre><pre class="language-matlab">im=imread('E:\project details wg\project\coding1\converted\ZX.jpg')
function [l, Am, Sp, d] = slic(im, k, m, seRadius, colopt, mw, nItr, eim, We)
if ~exist('colopt','var') || isempty(colopt), colopt = 'mean'; end
if ~exist('mw','var') || isempty(mw), mw = 0; end
if ~exist('nItr','var') || isempty(nItr), nItr = 10; end
</pre><pre> if exist('eim', 'var'), USEDIST = 0; else, USEDIST = 1; end
MEANCENTRE = 1;
MEDIANCENTRE = 2;
if strcmp(colopt, 'mean')
centre = MEANCENTRE;
elseif strcmp(colopt, 'median')
centre = MEDIANCENTRE;
else
error('Invalid colour centre computation option');
end
[rows, cols, chan] = size(im);
if chan ~= 3
error('Image must be colour');
end
% Convert image to L*a*b* colourspace. This gives us a colourspace that is
% nominally perceptually uniform. This allows us to use the euclidean
% distance between colour coordinates to measure differences between
% colours. Note the image becomes double after conversion. We may want to
% go to signed shorts to save memory.
im = rgb2lab(im);
% Apply median filtering to colour components if mw has been supplied
% and/or non-zero
if mw
if length(mw) == 1
mw(2) = mw(1); % Use same filtering for L and chrominance
end
for n = 1:3
im(:,:,n) = medfilt2(im(:,:,n), [mw(1) mw(1)]);
end
end
% Nominal spacing between grid elements assuming hexagonal grid
S = sqrt(rows*cols / (k * sqrt(3)/2));
% Get nodes per row allowing a half column margin at one end that alternates
% from row to row
nodeCols = round(cols/S - 0.5);
% Given an integer number of nodes per row recompute S
S = cols/(nodeCols + 0.5);
% Get number of rows of nodes allowing 0.5 row margin top and bottom
nodeRows = round(rows/(sqrt(3)/2*S));
vSpacing = rows/nodeRows;
% Recompute k
k = nodeRows * nodeCols;
% Allocate memory and initialise clusters, labels and distances.
C = zeros(6,k); % Cluster centre data 1:3 is mean Lab value,
% 4:5 is row, col of centre, 6 is No of pixels
l = -ones(rows, cols); % Pixel labels.
d = inf(rows, cols); % Pixel distances from cluster centres.
% Initialise clusters on a hexagonal grid
kk = 1;
r = vSpacing/2;
for ri = 1:nodeRows
% Following code alternates the starting column for each row of grid
% points to obtain a hexagonal pattern. Note S and vSpacing are kept
% as doubles to prevent errors accumulating across the grid.
if mod(ri,2), c = S/2; else, c = S; end
for ci = 1:nodeCols
cc = round(c); rr = round(r);
C(1:5, kk) = [squeeze(im(rr,cc,:)); cc; rr];
c = c+S;
kk = kk+1;
end
r = r+vSpacing;
end
% Now perform the clustering. 10 iterations is suggested but I suspect n
% could be as small as 2 or even 1
S = round(S); % We need S to be an integer from now on
for n = 1:nItr
for kk = 1:k % for each cluster
% Get subimage around cluster
rmin = max(C(5,kk)-S, 1); rmax = min(C(5,kk)+S, rows);
cmin = max(C(4,kk)-S, 1); cmax = min(C(4,kk)+S, cols);
subim = im(rmin:rmax, cmin:cmax, :);
assert(numel(subim) > 0)
% Compute distances D between C(:,kk) and subimage
if USEDIST
D = dist(C(:, kk), subim, rmin, cmin, S, m);
else
D = dist2(C(:, kk), subim, rmin, cmin, S, m, eim, We);
end
% If any pixel distance from the cluster centre is less than its
% previous value update its distance and label
subd = d(rmin:rmax, cmin:cmax);
subl = l(rmin:rmax, cmin:cmax);
updateMask = D < subd;
subd(updateMask) = D(updateMask);
subl(updateMask) = kk;
d(rmin:rmax, cmin:cmax) = subd;
l(rmin:rmax, cmin:cmax) = subl;
end
% Update cluster centres with mean values
C(:) = 0;
for r = 1:rows
for c = 1:cols
tmp = [im(r,c,1); im(r,c,2); im(r,c,3); c; r; 1];
C(:, l(r,c)) = C(:, l(r,c)) + tmp;
end
end
% Divide by number of pixels in each superpixel to get mean values
for kk = 1:k
C(1:5,kk) = round(C(1:5,kk)/C(6,kk));
end
% Note the residual error, E, is not calculated because we are using a
% fixed number of iterations
end
% Cleanup small orphaned regions and 'spurs' on each region using
% morphological opening on each labeled region. The cleaned up regions are
% assigned to the nearest cluster. The regions are renumbered and the
% adjacency matrix regenerated. This is needed because the cleanup is
% likely to change the number of labeled regions.
[l, Am] = mcleanupregions(l, seRadius);
% Recompute the final superpixel attributes and write information into
% the Sp struct array.
N = length(Am);
Sp = struct('L', cell(1,N), 'a', cell(1,N), 'b', cell(1,N), ...
'stdL', cell(1,N), 'stda', cell(1,N), 'stdb', cell(1,N), ...
'r', cell(1,N), 'c', cell(1,N), 'N', cell(1,N));
[X,Y] = meshgrid(1:cols, 1:rows);
L = im(:,:,1);
A = im(:,:,2);
B = im(:,:,3);
for n = 1:N
mask = l==n;
nm = sum(mask(:));
if centre == MEANCENTRE
Sp(n).L = sum(L(mask))/nm;
Sp(n).a = sum(A(mask))/nm;
Sp(n).b = sum(B(mask))/nm;
elseif centre == MEDIANCENTRE
Sp(n).L = median(L(mask));
Sp(n).a = median(A(mask));
Sp(n).b = median(B(mask));
end
Sp(n).r = sum(Y(mask))/nm;
Sp(n).c = sum(X(mask))/nm;
% Compute standard deviations of the colour components of each super
% pixel. This can be used by code seeking to merge superpixels into
% image segments. Note these are calculated relative to the mean colour
% component irrespective of the centre being calculated from the mean or
% median colour component values.
Sp(n).stdL = std(L(mask));
Sp(n).stda = std(A(mask));
Sp(n).stdb = std(B(mask));
Sp(n).N = nm; % Record number of pixels in superpixel too.
end
%-- dist -------------------------------------------
%
% Usage: D = dist(C, im, r1, c1, S, m)
%
% Arguments: C - Cluster being considered
% im - sub-image surrounding cluster centre
% r1, c1 - row and column of top left corner of sub image within the
% overall image.
% S - grid spacing
% m - weighting factor between colour and spatial differences.
%
% Returns: D - Distance image giving distance of every pixel in the
% subimage from the cluster centre
%
% Distance = sqrt( dc^2 + (ds/S)^2*m^2 )
% where:
% dc = sqrt(dl^2 + da^2 + db^2) % Colour distance
% ds = sqrt(dx^2 + dy^2) % Spatial distance
%
% m is a weighting factor representing the nominal maximum colour distance
% expected so that one can rank colour similarity relative to distance
% similarity. try m in the range [1-40] for L*a*b* space
%
% ?? Might be worth trying the Geometric Mean instead ??
% Distance = sqrt(dc * ds)
% but having a factor 'm' to play with is probably handy</pre><pre class="language-matlab">% This code could be more efficient
function D = dist(C, im, r1, c1, S, m)
</pre><pre> % Squared spatial distance
% ds is a fixed 'image' we should be able to exploit this
% and use a fixed meshgrid for much of the time somehow...
[rows, cols, chan] = size(im);
[x,y] = meshgrid(c1:(c1+cols-1), r1:(r1+rows-1));
x = x-C(4); % x and y dist from cluster centre
y = y-C(5);
ds2 = x.^2 + y.^2;
% Squared colour difference
for n = 1:3
im(:,:,n) = (im(:,:,n)-C(n)).^2;
end
dc2 = sum(im,3);
D = sqrt(dc2 + ds2/S^2*m^2);
%--- dist2 ------------------------------------------
%
% Usage: D = dist2(C, im, r1, c1, S, m, eim)
%
% Arguments: C - Cluster being considered
% im - sub-image surrounding cluster centre
% r1, c1 - row and column of top left corner of sub image within the
% overall image.
% S - grid spacing
% m - weighting factor between colour and spatial differences.
% eim - Edge strength sub-image corresponding to im
%
% Returns: D - Distance image giving distance of every pixel in the
% subimage from the cluster centre
%
% Distance = sqrt( dc^2 + (ds/S)^2*m^2 )
% where:
% dc = sqrt(dl^2 + da^2 + db^2) % Colour distance
% ds = sqrt(dx^2 + dy^2) % Spatial distance
%
% m is a weighting factor representing the nominal maximum colour distance
% expected so that one can rank colour similarity relative to distance
% similarity. try m in the range [1-40] for L*a*b* space
%</pre><pre> function D = dist2(C, im, r1, c1, S, m, eim, We)
% Squared spatial distance
% ds is a fixed 'image' we should be able to exploit this
% and use a fixed meshgrid for much of the time somehow...
[rows, cols, chan] = size(im);
[x,y] = meshgrid(c1:(c1+cols-1), r1:(r1+rows-1));
x = x-C(4);
y = y-C(5);
ds2 = x.^2 + y.^2;
% Squared colour difference
for n = 1:3
im(:,:,n) = (im(:,:,n)-C(n)).^2;
end
dc2 = sum(im,3);
% Combine colour and spatial distance measure
D = sqrt(dc2 + ds2/S^2*m^2);
% for every pixel in the subimage call improfile to the cluster centre
% and use the largest value as the 'edge distance'
rCentre = C(5)-r1; % Cluster centre coords relative to this sub-image
cCentre = C(4)-c1;
de = zeros(rows,cols);
for r = 1:rows
for c = 1:cols
v = improfile(eim,[c cCentre], [r rCentre]);
de(r,c) = max(v);
end
end
% Combine edge distance with weight, We with total Distance.
D = D + We * de;</pre>tripti santani/matlabcentral/answers/contributors/5639979-tripti-santanitag:nl.mathworks.com,2005:Question/1672882014-12-20T05:26:07Z2014-12-20T05:26:07ZImporting target_dataset from an excel file to a neural network toolbox for pattern recognition (nprtool)<p>In the neural network toolbox in matlab (nnstart), i am using the Pattern recognition tool (nprtool); and i want to import a dataset from an excel file to the target field in the toolbox.</p><p>the problem is that i can import the input(matrix of size 1*50) easily, while i am not able to import the target (4 * 50) at all.</p><p>can someone please let me know whether there is a strict structure of the excel dataset, or is there a way to insert the target data.</p><p>thank you very much</p>alladin/matlabcentral/answers/contributors/5452474-alladintag:nl.mathworks.com,2005:Question/1670122014-12-18T01:14:20Z2014-12-20T05:21:21ZOdd behaviour of 2x2-matrix and 2x1-vector operation<p>Consider a 2x2 matrix A with columns uncorrelated, and a vector x:</p><pre> A = [ a b ]
[-b' a']
x = [ a']
[ b']</pre><p>where a and b are complex scalar. The product of A*x is supposed to be mathematically:</p><pre> A*x = [ a*a'+b*b' ] = [ a*a'+b*b' ]
[-b'*a'+a'*b'] [ 0 ]</pre><p>In matlab 2012b, I tried to compare A*x matrix operation and the element-wise operations such as a*a'+b*b' and -b'*a'+a'*b'.
Both results happen to be different with some random pairs of a and b. a*a'*b*b' always shows positive real, but matrix operation shows some residual on the imaginary part sometime.
Even -b'*a'+a'*b' entry of matrix operation shows such erroneous imaginary part, which is supposed to be zero!</p><p>The following script finds the mismatch result and shows the hex forms of the results.</p><p>y0, y1, y2, z show the result of different operations:</p><ul><li>y0 = A*x; % matlab matrix multiply script</li><li>y1 = mtimes(A,x); % mtimes operation</li><li>y2 = mvmult_lapack (A, x); % private code using lapack routine (ZGEMV)</li><li>z = [a*a'+b*b';-b'*a'+a'*b']; % element-wise operation</li></ul><p><b>Result</b> : y2 and z are always same and real, but y0 and y1 have erroneous imaginary part. Note that the real parts of y0 and y1 are different from the real parts of y2 and z by eps, say a difference of the last bit of floating-point format.</p><p><b>Discuss and Question</b> : It is not clear why the A*x script shows the difference from the element-wise operation. It could not be a problem with LAPACK/BLAS. There seems parser or storage register problem in machine code when the matrix operation is called.
Is this only preblem with 2012b or my machine?</p><p><b>Test script</b> :</p><pre> %%
randn('seed',0)
ii=0;
while 1,
ii = ii + 1;
a = randn+i*randn;
b = randn+i*randn;
%
A = [a b; -b' a'];
x = [a'; b'];
y0 = A*x;
y1 = mtimes(A,x);
y2 = mvmult_lapack (A, x);
z = [a*a'+b*b';-b'*a'+a'*b'];
if sum(y0~=z) % break when the results are different!
break
end
if ii==10000
break
end
end
ii
%
a
b
y0
y1
y2
z
y0==z
[num2hex(real(y0)), repmat(' ',[2 1]), num2hex(imag(y0))]
[num2hex(real(y1)), repmat(' ',[2 1]), num2hex(imag(y1))]
[num2hex(real(y2)), repmat(' ',[2 1]), num2hex(imag(y2))]
[num2hex(real(z)), repmat(' ',[2 1]), num2hex(imag(z))]</pre><p><b>Output</b> :</p><pre> ii =</pre><pre> 1</pre><pre> a =</pre><pre> 1.16495351050066 + 0.626839082632431i </pre><pre> b =</pre><pre> 0.0750801546776829 + 0.351606902768522i</pre><pre> y0 = </pre><pre> 1.87930836084417 - 3.46944695195361e-18i
0 - 2.08166817117217e-17i</pre><pre> y1 =</pre><pre> 1.87930836084417 - 3.46944695195361e-18i
0 - 2.08166817117217e-17i</pre><pre> y2 =</pre><pre> 1.87930836084417
0</pre><pre> z =</pre><pre> 1.87930836084417
0</pre><pre> ans =</pre><pre> 0
0</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1e bc50000000000000
0000000000000000 bc78000000000000</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1e bc50000000000000
0000000000000000 bc78000000000000</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1d 0000000000000000
0000000000000000 0000000000000000</pre><pre> ans =</pre><pre> 3ffe11a5a4cecd1d 0000000000000000
0000000000000000 0000000000000000</pre>Sung-Eun Jo/matlabcentral/answers/contributors/1329294-sung-eun-jotag:nl.mathworks.com,2005:Question/1672872014-12-20T04:57:09Z2014-12-20T05:01:05Zhi i have one query image and 20 dataset images and i want to find out the precision and recall graph but i am not getting the correct results pls help!!!<pre class="language-matlab">clc
clear all
</pre><pre class="language-matlab">I=imread('1.jpg'); % to read the image
I_read=imresize(I,[256 256]);
% image resize
I=rgb2gray(I_); % rgb to gray conversion
%I=I_enlarge;
imshow(I);
</pre><pre class="language-matlab">Seq=cell(1,20);
</pre><pre class="language-matlab">for i=1:20
</pre><pre> I=imread(sprintf('%d.jpg',i));
I=imresize(I,[256 256]);</pre><pre> I=rgb2gray(I);
Seq{i}=I;
end
for i = 1 : 20 % loop for calculating histogram intersections
A=Seq{i};
B=I;
a = size(A,2);
b = size(B,2);
K = zeros(a, b);
for j = 1:a
Va = repmat(A(:,j),1,b);
K(j,:) = 0.5*sum(Va + B - abs(Va - B));
end
end
num_images = 20;
sims=K
relevant_IDs = [1 2 3 4 5 6 7 8 9 10];
num_relevant_images = numel(relevant_IDs);
[sorted_sims, locs] = sort(sims, 'descend');</pre><pre class="language-matlab">locations_final = arrayfun(@(x) find(locs == x, 1), relevant_IDs)
locations_sorted = sort(locations_final)
precision = (1:num_relevant_images) ./ locations_sorted;
</pre><pre class="language-matlab">recall = (1:num_relevant_images) / num_relevant_images;
disp(precision)
disp(recall)
plot(recall, precision, 'b.-');
xlabel('Recall');
ylabel('Precision');
title('Precision-Recall Graph - GEOGRAPHICAL IMAGE RETIREVAL');
axis([0 1 0 1.05]); %// Adjust axes for better viewing
grid;
</pre>preeti/matlabcentral/answers/contributors/5593219-preetitag:nl.mathworks.com,2005:Question/1672862014-12-20T04:43:34Z2014-12-20T04:44:34ZCan anyone upload codings of active constellation extension for PAPR reduction in OFDM,Please...<p>I need codings of active constellation extension method.HOw can we extend constelllation points of QAM.Please anyone help me.</p>tinu baby/matlabcentral/answers/contributors/5862648-tinu-babytag:nl.mathworks.com,2005:Question/1672482014-12-19T18:44:00Z2014-12-20T04:31:03Zhow to generate random numbers from a distribution which is the convolution of exponential distributions?<p>Hello,</p><p>I would like to simulate two independent laser speckle intensities. Based on J. Goodman's book (Speckle Phenomena in Optics, p.39), the formula for the intensity distribution is the convolution of two exponential distributions:</p><p>p(i) = i/(I^2) exp(-i/I)</p><p>with I being the average intensity.</p><p>Is there already a function doing this? If not, how should I proceed to write it myself?</p><p>Thanks for the answer!</p><p>Cheers
Guillaume</p>Guillaume/matlabcentral/answers/contributors/5326629-guillaumetag:nl.mathworks.com,2005:Question/1672512014-12-19T18:55:21Z2014-12-20T04:26:07ZMatlab multitasking without using Parallel Computing Toolbox?<p>Hello.</p><p>I am a novice in programming in general, but I am using a arduino Due which is using a SAM3X8E 32bit mcu.
SAM3 has both DMAC(Direct Memory Access Controller) and PDCs(Peripheral DMA Controller) which allows me for example to setup the ADC to continuously convert and store the results in a array without the CPU doing any of it. So I am free to preform other tasks at the same time.</p><p>A PC is far more powerful but is there any way to write a script to do many(or two) things at the same time as akin to DMA?</p><p>Maybe continuously reading a serial port for values to plot or process at the same time, using a ping-pong buffer.</p><p>Regards</p>David/matlabcentral/answers/contributors/5703086-davidtag:nl.mathworks.com,2005:Question/1667942014-12-16T10:21:22Z2014-12-20T04:14:58ZDoubt with interface showing a volume<p>I'm trying to make an interface that shows a volume with a black background, but when I run it all the window goes black as the figure background, and I don't know why. There is the code of the interface:</p><pre class="language-matlab">_ _ _ _ _function varargout = funcionapliss(varargin)
% FUNCIONAPLISS MATLAB code for funcionapliss.fig
% FUNCIONAPLISS, by itself, creates a new FUNCIONAPLISS or raises the existing
% singleton*.
%
% H = FUNCIONAPLISS returns the handle to a new FUNCIONAPLISS or the handle to
% the existing singleton*.
%
% FUNCIONAPLISS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FUNCIONAPLISS.M with the given input arguments.
%
% FUNCIONAPLISS('Property','Value',...) creates a new FUNCIONAPLISS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before funcionapliss_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to funcionapliss_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
</pre><pre class="language-matlab">% Edit the above text to modify the response to help funcionapliss
</pre><pre class="language-matlab">% Last Modified by GUIDE v2.5 12-Dec-2014 18:58:30
</pre><pre class="language-matlab">% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @funcionapliss_OpeningFcn, ...
'gui_OutputFcn', @funcionapliss_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
</pre><pre class="language-matlab">if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
</pre><pre class="language-matlab">% --- Executes just before funcionapliss is made visible.
function funcionapliss_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to funcionapliss (see VARARGIN)
</pre><pre class="language-matlab">% Choose default command line output for funcionapliss
%handles=guidata(hObject);
%handles.output = hObject;
%%to inicialize the pic, 3d graph
% % Update handles structure
structels;
elems;
global f;
global struct;
global methods;
struct= getappdata(0,'struct');
methods= getappdata(0,'method');
f= getappdata(0,'elegdicom');
global ini;
ini=50;
</pre><pre class="language-matlab">if methods==1
handles.output=Vidto3dIsosurface(f,struct,elem3,1,'posicio');
end
*if methods==2
handles.output=Vidto3dSurface(f,struct,elem3,1);
end*
%%set current data value
%%END
% Update handles structure
guidata(hObject, handles);
global n; %variable global per rotació
n=1;
global s;
global az;
global el;
global tot;
global m;
az = 180;
el = 85;
s=1;
tot=ini+ini/2;
m=0;_
</pre><pre class="language-matlab">% UIWAIT makes funcionapliss wait for user response (see UIRESUME)
%uiwait(handles.figure1);
</pre><pre class="language-matlab">% --- Outputs from this function are returned to the command line.
function varargout = funcionapliss_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">% Get default command line output from handles structure
axes(handles.axes3);
varargout{1} = handles.output;
</pre><pre> _ _ _</pre><p>The method 2 is when that volume is shown.</p>iuohp/matlabcentral/answers/contributors/4242100-iuohptag:nl.mathworks.com,2005:Question/1668982014-12-17T09:35:28Z2014-12-20T04:14:47Zcomputer vision system toolbox<p>I am using MATLAB R2012a. in the help menu there it shows the computer vision system toolbox, but when i run a command "FD=vivion.CascadeObjectDetection('EyepairBig');" it shows an error "undefined variable 'vision' or class vision.cascadeobjectdetection " . I'm using it for detection of eyes on a face in an image
Am i supposed to do something with the toolbox before using it.
please help.</p><p>Thanks in advance</p>Zeeshan/matlabcentral/answers/contributors/5321559-zeeshantag:nl.mathworks.com,2005:Question/1668632014-12-16T22:11:25Z2014-12-20T04:11:47ZSynchronize/show variables in workspace with GUI <p>Hopefully someone can help me.</p><p>I try to built a GUI using guide which show three variables from the workspace in a window. I am able to create the window but I have no idea how reprogram to link/synchronize the variables to the GUI. If the variable chance of value so should the value chance in the window.</p><p>Two variable (a and b) are numbers and one variable (c) is a string.</p><p>If possible could someone provide the code including the code to link the workspace variables which I can then open with guide to adjust.</p><p>That would be of great help to me.</p><p>Thanks in advance.</p>Leon/matlabcentral/answers/contributors/3600911-leontag:nl.mathworks.com,2005:Question/1672682014-12-19T22:37:55Z2014-12-20T04:06:13Zexist() for functions only?<p>As I understand, the exist() function in MATLAB will return "2" if the input is a MATLAB function.</p><p>The list of options for the second input 'kind' are builtin, class, dir, file, and var.</p><p>I want to input 'kind' so that exist() will ONLY search for functions, and return 2 if it is a match to a function and a 0 if not.</p><p>Is there any way to do this?</p>Daniel/matlabcentral/answers/contributors/4784474-danieltag:nl.mathworks.com,2005:Question/1671712014-12-19T06:23:28Z2014-12-20T03:33:27ZDear expert i am asking to check my network i am using this network in structural engineering field please help me to correct <p>dear sir
i am using this first time and aspect valuable comment from you
i am new in ANN , i want to use feed forward neural network in structural engineering.
i make a M file using neural network function but i am facing one problem that my result is different in every successive training without changing any parameters and i also found to solve this problem. but result after simulate to test data it is not so much accurate so i how can i get better result please my network is as following and aspect valuable correction.</p><p>%%%%%modeling for Gradient Descent Error minimization Coading MLP%%%%%%%%</p><p>clear all</p><p>clc
%%%%%%%%%%%%%%%%%%%%%%%Loading data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>load='E:\Lila khatiwada\Matlab practice\Lila practice CSV file';
B=fullfile(load,'lila.csv');
sample_d=dlmread(B,',','A1..AN21');</p><p>%%%%%%%%%%%%% ANN Parameters%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>sh=100;</p><p>ep=10000;</p><p>go=1e-5;</p><p>lr=0.0001;</p><p>HN1=20;</p><p>HN2=10;</p><p>ON=1;
%%%%%%%%%%%ANN Data(Input parameters and Target patameters%%%%%%%%</p><p>p=sample_d(1:20,:);</p><p>t=sample_d(21,:);</p><p>%%%%%%%%%%%%%%%%%%%%Data Scalling%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>[pn,psp]=mapminmax(p,0.1,.9);</p><p>[tn,pst]=mapminmax(t,0.1,.9);</p><p>TEST=10;</p><p>VAL=10;</p><p>iitst=[size(p,2)-TEST+1:size(p,2)];</p><p>iival=[size(p,2)-TEST-VAL+1:size(p,2)-TEST];</p><p>iitr=[1:size(p,2)-TEST-VAL];</p><p>val.p=pn(:,iival);</p><p>val.T=tn(:,iival);</p><p>test.p=pn(:,iitst);</p><p>test.T=tn(:,iitst);</p><p>ptr=pn(:,iitr);</p><p>ttr=tn(:,iitr);</p><p>%%%%Network Architecture%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>net=feedforwardnet([HN1 HN2]);</p><p>net.layers{1}.transferfcn='logsig';</p><p>net.layers{2}.transferfcn='logsig';</p><p>net.layers{3}.transferfcn='purelin';</p><p>net=configure(net,ptr,ttr);</p><p>% y1=net(ptr);</p><p>% plot(ptr,ttr,'o',ptr,y1,'x');</p><p>%%%%Initialize weight %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>setdemorandstream(491218382)</p><p>net=initnw(net,3);% initialize the net (weights and biases initialized)</p><p>%%%%Stopping Criteria%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>net.trainParam.goal=go; % error goal</p><p>net.trainParam.epochs=ep; % maximum iterations</p><p>net.trainParam.show=sh; % showing intervals</p><p>net.trainParam.max_fail=10; % Change this to effect the validation</p><p>net.trainParam.lr=lr;</p><p>net.trainParam.mc=0.9;</p><p>%%%%Network Training%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p><p>net1.trainfcn='trainlm';</p><p>net1=train(net,ptr,ttr);</p><p>% y2=net(ptr);</p><p>% perf= perform(net,ttr,y2);</p><p>% plot(ptr,ttr,'+',ptr,y2,'*');</p><p>%%%%%%%%%%% Simulating%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yp = sim(net1,test.p);</p><p>[y1,PS] = mapstd(yp);</p><p>a = mapstd('reverse',yp,PS);</p>lila/matlabcentral/answers/contributors/5569325-lilatag:nl.mathworks.com,2005:Question/1670132014-12-18T01:23:11Z2014-12-20T03:27:29ZString for pushButton GUIDE GUI - using Greek letters<p>When I try to put in "α" into the String field of the GUIDE GUI pushButton, it replaces it with a blank character (as if there's an empty space there). How may I fix this so that I type in the α into the pushButton String?</p>Muaaman/matlabcentral/answers/contributors/5823965-muaaman