http://www.mathworks.nl/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-09-02T06:53:34Ztag:www.mathworks.nl,2005:Question/1531312014-09-02T06:53:34Z2014-09-02T06:53:34ZProblem with subreferencing (subsref) operator overload<p>I am experiencing a problem with operator overloading of the subreferencing operator for a class. Below is an illustrative MATLAB value class that has a property, x, that stores a vector of integers. Operator overloading for () is implemented by overloading the subsref function.</p><p>The documentation for subsref is here: <a href = "http://www.mathworks.com/help/matlab/ref/subsref.html">http://www.mathworks.com/help/matlab/ref/subsref.html</a></p><pre class="language-matlab">classdef BizarreClass
properties
x;
end
</pre><pre> methods
function obj = BizarreClass()
obj.x = [1 2 3 4 5];
end</pre><pre> function obj = setx(obj, x_val)
disp('called setx')
obj.x = x_val;
end</pre><pre> function varargout = subsref(obj, S)
%Ignore function calls and only tend to subreferences
if (strcmp(S(1).type, '()'))
disp('called for the right reason')
varargout{1} = obj.x(S(1).subs{1});
else
disp('called for the wrong reason')
varargout = {};
end
end</pre><pre> end
end</pre><p>Now let's say I instantiate BizarreClass:</p><pre class="language-matlab">b = BizarreClass()
</pre><p>And then call the setx function to set x to a different value:</p><p>b = b.setx([1 3 5])</p><p>which gives an error:</p><pre class="language-matlab">Error in BizarreClass>BizarreClass.subsref (line 18)
if (strcmp(S(1).type, '()'))
</pre><pre class="language-matlab">Error using BizarreClass/subsref
Output argument "varargout" (and maybe others) not assigned during call to
"c:\users\johndoe\Desktop\swallowing\trunk\matlab_scripts\BizarreClass.m>BizarreClass.subsref".
</pre><p>This is happening because subsref is being called first (as it should). That is why I have logic that checks the input variable S and only handle the case where the object is subreferenced like b(3), in which case varargout gets the value indexed into the array, x. Otherwise, varargout is empty, which is the problem: The 'b = ' in 'b = setx([1 3 5])' needs to be there for the value of b to be updated. Unfortunately, this calls subsref first and not the setx method, causing that error.</p><p>I can get past this by calling setx on b like this:</p><pre class="language-matlab">b = setx(b, [1 3 5])
</pre><p>But I want to call it like:</p><pre class="language-matlab">b = b.setx([1 3 5])
</pre><p>Is there a solution? How do I not have subsref to be called for any case other than the subsref operator? Or is there a design pattern that I should use that will allow me to use b = b.setx([1 3 5])</p>John/matlabcentral/answers/contributors/5415607-johntag:www.mathworks.nl,2005:Question/1530622014-09-01T13:44:02Z2014-09-02T06:43:47Zthe first argument of "warning" should be a message identifier<p>Hello, I wrote a matlab command " warning('abc'); ", but the editor detects a problem and underscores the braketed string 'abc' with red wavy line. The given information is:</p><p>The first argument of WARNING should be a message identifier. Using a message identifier allows better control over the message.</p><p>How could I get rid of this thing? Thank you!</p>Zhou/matlabcentral/answers/contributors/4968535-zhoutag:www.mathworks.nl,2005:Question/1531302014-09-02T06:40:43Z2014-09-02T06:40:43ZI am doing my project in medical imaging. I am getting "index exceeds matrix dimensions" while trying to segment the lungs. please help me<p>I = im2double(imread('onee.png'));
I=I(:,:,1);</p><p>cropped = I(50:430,8:500); %% Crop region of interest
thresholded = cropped < 0.35; %% Threshold to isolate lungs
clearThresh = imclearborder(thresholded); %% Remove border artifacts in image
Liver = bwareaopen(clearThresh,100); %% Remove objects less than 100 pixels
Liver1 = imfill(Liver,'hole'); % fill in the vessels inside the lungs
imshow(Liver1.*cropped)</p>Bhavithra/matlabcentral/answers/contributors/4729397-bhavithratag:www.mathworks.nl,2005:Question/1531292014-09-02T06:23:09Z2014-09-02T06:37:37Zfind the projection of a image <p>i have a medical image .Now i need to identify the projection of an image ..example top ,side or front ...</p>stalin/matlabcentral/answers/contributors/5552787-stalintag:www.mathworks.nl,2005:Question/1531272014-09-02T05:48:20Z2014-09-02T06:29:30ZHow to make structure from Excel<p>Hello,
Well I am working on structures and have some kind of problem, I have excel file that contains some kinds of data in each sheet, I want to write a code that will make the same number of structures as sheets, after that it should divide each sheets into the variables and than this variables should assigned in its structure.
For example I have excel file with three sheet, these sheets contains data first second and third,
my goal is to make code three structure i mean sheet1 sheet2 and sheet3 and each structure should contain first second and third variables.
Well the last problem is solved I mean division excel file into variables but I am not be able to make structures that will contain these variables.
Waiting for your respones any idea would be great for me.</p>Giorgi/matlabcentral/answers/contributors/5435287-giorgitag:www.mathworks.nl,2005:Question/1531262014-09-02T05:04:21Z2014-09-02T06:22:54ZEdit text in MATLAB GUI<p>I want to enter fix number of charachter in EDIT text component of MATLAB GUI.</p><p>means user can enter only 10 characters and cant enter 11th one</p>Raza/matlabcentral/answers/contributors/4396283-razatag:www.mathworks.nl,2005:Question/1531282014-09-02T05:59:39Z2014-09-02T06:01:50ZAdding audio frames using 'avifile'<p>Hello,</p><pre> I want to create a custom avi file with my own images and audio data. I do not have a newer version and hence cannot use 'videoWriter'.Neither do I have the vision toolbox to use 'vision.VideoFileWriter'. So I intend to use 'avifile' instead. However, from the help description, I am able to see only video frames/images being added; I have not come across any description or example where audio data is being added to the aviobject. For my experiment, I would like to create my own audio and add it to the video in the file.
So, is it possible to add audio data frames via 'avifile'? If so, how do I go about doing that?</pre><p>Thanks and regards,
Siddharth.</p>Siddharth Kumar/matlabcentral/answers/contributors/5580564-siddharth-kumartag:www.mathworks.nl,2005:Question/1531162014-09-02T01:32:59Z2014-09-02T05:47:03ZHow to find max in a matrix (1,N,2)&& matrix (1,N,3)?<pre class="language-matlab">matrix (1,1:10,2)= 1 2 3 4 5 6 7 8 9 10
matrix (1,1:10,3)= 2 5 9 2 5 6 2 5 7 5
</pre><p>Is that a way can find out matrix (1,9,:)? which is largest considering both array.
Two number are dependent. So I can't find it separately.</p><p>any embedded function to do it?</p><p>Or I must write a code to calculate their mean value and take the max one.</p>tabw/matlabcentral/answers/contributors/5464797-tabwtag:www.mathworks.nl,2005:Question/1529472014-08-31T07:27:40Z2014-09-02T05:28:20ZFinding best neural network structure using optimization algorithms and cross-validation<p>Hi.</p><p>I'm using optimization algorithm to find best structure+inputs of a 'patternnet' neural network in MATLAB R2014a using 5-fold cross validation. Where should i initialize weights of my neural network?</p><pre> *Position_1(for weight initialization)*</pre><pre> for i=1:num_of_loops
*Position_2(for weight initialization)* </pre><pre> - repeating cross validation
for i=1:num_of_kfolds
*Position_3(for weight initialization)*
- Cross validation loop</pre><pre> end
end</pre><p>I'm repeating 5-fold cross validation (because random selection of cross validation) to have more reliable outputs (average of neural network outputs). Which part is better for weight initialization (Position_1,Position_2 or Position_3) and why?</p><p>thanks.</p>Jack/matlabcentral/answers/contributors/5193869-jacktag:www.mathworks.nl,2005:Question/1529312014-08-30T21:30:25Z2014-09-02T05:28:01ZHow to translate the following code from Mathematica to Matlab?<p>I need to construct a matrix similar to the following:</p><p>l = 2; m = 4;
Table[(2 x - y*l)/m, {x, 0, 5}, {y, 0, 5}] // MatrixForm</p><img src = "/matlabcentral/answers/uploaded_files/17590/Untitled.jpg"><p>How can I do that in Matlab?</p>Tigo/matlabcentral/answers/contributors/5560534-tigotag:www.mathworks.nl,2005:Question/1531032014-09-01T20:49:58Z2014-09-02T05:21:14Zhow to set the ticks in the colorbar to be automatic and as many as possible?<p>i'm trying to use as many ticks in the colorbar
doing so manualy lead to unexpected resault such as:</p><img src = "/matlabcentral/answers/uploaded_files/17661/Screenshot%202014-09-01%2023.48.02.png"><p>(in the attached image)</p><p>i used:</p><pre class="language-matlab">cbr=colorbar('fontsize',15);
set(cbr,'YTick',min(min(MAT)):max(max(MAT))/100:max(max(MAT)))
</pre><p>how can i still get as many ticks as possible but still keeping the data readable</p>Kobi/matlabcentral/answers/contributors/3268302-kobitag:www.mathworks.nl,2005:Question/1531092014-09-01T22:25:19Z2014-09-02T05:19:43ZNumber greater than the largest positive floating-point number (1.7977e+308)<p>I'm trying to calculate the following expression:</p><p>(l+m)! / (l!m!)</p><p>but when l=m > 85 I get infinity, because the result is greater than the largest positive floating-point number (1.7977e+308).</p><p>Is there a way of increasing this number limit, or even a trick to avoid this problem?</p>Tigo/matlabcentral/answers/contributors/5560534-tigotag:www.mathworks.nl,2005:Question/1529412014-08-31T03:12:15Z2014-09-02T04:46:18ZBizarre value class behavior<p>Below is a self-explanatory VALUE class I developed for purposes of illustration.</p><pre> classdef ClassA
properties
x;
y;
end</pre><pre> methods</pre><pre> function obj = ClassA()
obj.x = 0;
obj.y = 0;
end</pre><pre> function setX(obj, val)
obj.x = val;
end </pre><pre> function setY(obj, val)
obj.y = val;
end </pre><pre> function obj = set.x(obj, val)
*obj* .x = val;
end</pre><pre> function obj = set.y(obj, val)
obj.y = val;
end</pre><pre> end</pre><pre> end</pre><p>I instantiated it as follows:</p><pre class="language-matlab">a = ClassA();
</pre><p>Good. That worked. Now to test the setter methods:</p><pre class="language-matlab">a.x = 1;
a.y = 2;
</pre><p>Those worked too. But doing this:</p><pre class="language-matlab">a.setX(3)
a.setY(5)
</pre><p>causes the prompt to not echo the value of the properties as is done when the setter methods are used. Why? And when I enter the variable name in the prompt, the property values are echoed back but they do not change upon using setX and setY. This is puzzling. I followed proper VALUE class syntax for setX and setY. Help please!</p>John/matlabcentral/answers/contributors/5415607-johntag:www.mathworks.nl,2005:Question/1530472014-09-01T10:59:52Z2014-09-02T04:45:31Zmaximum variable size allowed by the program is exceeded?<p>PLz help me</p><p>This is the code</p><pre> alps=17; %slope angle
dz=200; %depth of water table from the suface
dlz=400; % toltal depth of slope
fi=25; %friction angle
C=0.4; %4 kpa=0.4 N/cm^2
gsat=0.21; %21 kN/m^3
gw=0.098; %9.81 Kn/m^3
Dzero=4; %0.0004m^2/s
ksat=1e-3; %e-5 m/s
iz=2e-4; %iz=7.2 mm/h= 2e-4 cm/s
deltat=10; %time step
deltaz=0.8; %space step
T=12*60*60; %time duration of rainfall= 12h to seconds
e=(deltat/deltaz^2)*Dzero*cos(17*pi/180)*cos(17*pi/180);
n=500; %time step, based on T</pre><pre> %Setup sparse matrix</pre><pre> b= sparse(1:n,1:n,-116.314,n,n); % element b... 1...n
c= sparse(1:n-1,2:n,e,n,n); % element c...
a= sparse(2:n,1:n-1,-e,n,n); % element a... 2...n-1</pre><pre> c(1)=114.314; a(1)=0; a(n)=114.314; %Boundary condition
A= a+b+c;</pre><pre> l=e*ones(1:n); m=112.314*ones(1:n); u=e*ones(1:n);</pre><p>and
This is the error below, please tell me why this error appears and how to solve.
My system is 64 bit and 6gb ram and processor speed is 2.5 Ghz
Error using ones
Maximum variable size allowed by the program is exceeded.</p><pre> Error in hillslopesparse (line 30)
l=e*ones(1:n); m=112.314*ones(1:n); u=e*ones(1:n);</pre>advaita vedanta/matlabcentral/answers/contributors/2227782-advaita-vedantatag:www.mathworks.nl,2005:Question/1531252014-09-02T04:37:05Z2014-09-02T04:37:05ZHow to build a model for Optical fibers using Matlab 2014a version and where do i get blocks for these ?<p>Hi,</p><p>I am started exploring the Optical Communication and trying to use the MATLAB Simuklink but i am not able to find out any blocks which is related to the Optical fibers.</p><p>Help me out to work on this domain using Simulink.</p>Karthik/matlabcentral/answers/contributors/4981905-karthiktag:www.mathworks.nl,2005:Question/1531222014-09-02T03:20:29Z2014-09-02T04:30:23ZSolving a large equation<p>I have a large equation of the form:</p><pre class="language-matlab">8.5567=10.75-158.34*y+2112.07*y^2-12211.07*y^3-29.44*x+2185.91*x*y-35690.08*x*y^2+187137.42*x*y^3+129.16*x^2-9697.93*x^2*y+173834.73*x^2*y^2-935832.82*x^2*y^3-174.03*x^3+13191.71*x^3*y-245488.55*x^3*y^2+1384550.57*x^3*y^3
</pre><p>For x ranging from 0.15 to 0.39 I want to develop the value(s) of y.</p><p>Any ideas on how to do this would be greatly appreciated.</p><p>Thank you.</p>Nicholas/matlabcentral/answers/contributors/5439689-nicholastag:www.mathworks.nl,2005:Question/1531212014-09-02T03:13:47Z2014-09-02T04:16:22ZHow to add arrows to solution trajectories using ode?<p>￼I have a system of two odes and i want to plot the phase portrait with arrows and clearly representing the stable and unstable steady states. The problem is that i am getting the solution trajectories but without arrows. So it is very difficult to see which steady state is stable. Here is the ode system:</p><pre> function dy = twodim(~,y, mu, d1, d2, K, n, p, sigma1, sigma2)</pre><pre> dy(1,1) = mu.*((y(1) + y(2)).^n)./(K.^n + (y(1) + y(2)).^n) - d1.*y(1) - y(1).*(sigma1 - sigma2.*(y(2)./(y(1) + y(2) + 1e-12))) ;</pre><pre> dy(2,1) = y(1).*(sigma1 - sigma2.*(y(2)./(y(1) + y(2) + 1e-12))) - (p + d2).*y(2);</pre><p>Below is the part of the code I use to draw the solution trajectories:</p><pre> mu = 2000;
K = 27000;
d1 = 0;
d2 = 0;
sigma1 = 0.25;
sigma2 = 0.75;
p = 0.24;
n = 1;</pre><pre> close all; hold on
for a = 0:5250:15000
for b = 0:5250:15000
[t, y] = ode45(@(t,y)twodim(t,y, mu, d1, d2, K, n, p, sigma1, sigma2), 0:0.2:15000, [a; b]);
plot(y(:,1), y(:,2))
end
end
hold off
axis([0 15000 0 15000])</pre>Rose/matlabcentral/answers/contributors/2816791-rosetag:www.mathworks.nl,2005:Question/1531242014-09-02T04:02:26Z2014-09-02T04:29:36ZWhat is the reason for this code to go out of memory?<pre> filename= 'train_images_idx3_ubyte';
imgs=[];
readdigit =60000</pre><p>% Read digits
% This program reads 60000 binary image</p><pre> fid = fopen(filename, 'r','b');
offset= fread(fid, 4, 'int32');
imgs = fread(fid,inf, 'uchar');
imgs = transpose(reshape(imgs,28*28,readdigits));
fclose(fid);</pre><p>In this code,if i didnt use transpose in line 7, it shows out of memory. I have 1.8 terabyte of memory. Then y it shows out of memory. If i use transpose, it goes good. Whats the reason?</p>subha/matlabcentral/answers/contributors/4575737-subhatag:www.mathworks.nl,2005:Question/1530302014-09-01T07:29:55Z2014-09-02T03:57:28ZCan i get example code for finding type of noise in an image. Like Speckle.<p>I need help on finding type of noise in an image. any method through which we can make assumption or anything. Original image is also available and then the distorted image. I have also checked the comments by Image Analyst <a href = "http://www.mathworks.com/matlabcentral/answers/106380#answer_115410">Answer by Image Analyst on 16 Nov 2013</a>
Subtract the "true" image and then look at the spectrum of the noise to see what known type of noise it resembles.</p>Harsimran Singh/matlabcentral/answers/contributors/5531171-harsimran-singhtag:www.mathworks.nl,2005:Question/1531232014-09-02T03:42:43Z2014-09-02T03:42:43ZPeak over Threshold (POT) Method<p><b>Can anyone help me?</b></p><p>I'm trying to find how to find the peaks over threshold = 3.</p><p>My code so far is:</p><p>%% PLOT TIMESERIES</p><p>figure ('color','white');</p><p>plot(Time(:,1),Hsig(:,1))</p><p>legend('Hsig')</p><p>title('Hourly Hsig values against time')</p><p>xlabel(['Day/month'])</p><p>ylabel(['Hsig wave power (P) Average'])</p><p>datetick('x','dd/mm')</p><p>print ('Hsig wave power (P) average');</p><p>----------------------------------------------------------------------</p><p><b>How can I use a Peak over Threshold (POT) method to identify the hours where Hsig>3m?</b></p>Imogen/matlabcentral/answers/contributors/5580215-imogentag:www.mathworks.nl,2005:Question/1375352014-06-25T12:39:47Z2014-09-02T03:41:22Zconverting 2d matrix to 3d<p>Can anyone help me with making a 2D matrix into a 3D matrix?</p><p>I have a (71680 x 8) 2d matrix and I need to make a 3D matrix of dimensions (512 x 8 x 140) I need to take (512 x 8) consecutive matrices by row for 140 layers.</p><p>Can anyone help me with this? I really appreciate any help</p>Joe M/matlabcentral/answers/contributors/5426507-joe-mtag:www.mathworks.nl,2005:Question/1526092014-08-28T07:07:37Z2014-09-02T03:21:05ZHow to use filter<p>Hi all,</p><p>I am new to Matlab. I need to know how can fix uneven illumination issues from an image.</p>Siam/matlabcentral/answers/contributors/5563540-siamtag:www.mathworks.nl,2005:Question/1530532014-09-01T11:44:49Z2014-09-02T02:58:18ZPlotting mean of the columns of image on that image<p>I am struggling to plot the mean of the columns of the gray scale image on the same image. Mean of the columns of an image can be found by using Mean command in Matlab, but i don't have any idea how to plot it in image coordinates. Any idea or help is appreciated! Thank you :)</p>Yawar Rehman/matlabcentral/answers/contributors/1607545-yawar-rehmantag:www.mathworks.nl,2005:Question/1531202014-09-02T02:53:30Z2014-09-02T02:53:30ZHow to write matlab code of graph cut algorithm for image segmentation?<p>i want to segment a satellite image using the graph cut algorithm</p>Christina/matlabcentral/answers/contributors/5431512-christinatag:www.mathworks.nl,2005:Question/1529562014-08-31T10:32:37Z2014-09-02T02:22:31ZMatlab 2014a parachute problem<p>Here is the code</p><pre class="language-matlab">function dummy=parachute(c)
m=68;
g=9.81;
t=10;
v=45;
c=0.1:20:100;
dummy=-v+(g*m./c).*(1-exp(-c/m)*t);
fplot('parachut',[0,20])
grid on
xlabel('c')
ylabel('f(c)')
</pre><p>here is the error message I am receiving</p><pre class="language-matlab">Maximum recursion limit of 500 reached. Use
set(0,'RecursionLimit',N) to change the limit. Be
aware that exceeding your available stack space can
crash MATLAB and/or your computer.
</pre><pre class="language-matlab">Error in ismember>ismemberlegacy
</pre><p>I want the program to run . then I have to make a function to find "c" at 10 seconds by graphic means in the command window.</p><p>I am stuck with this error messages or another messages.</p>Robert/matlabcentral/answers/contributors/2172750-roberttag:www.mathworks.nl,2005:Question/1469632014-08-09T13:47:37Z2014-09-02T02:15:13ZCrossvalidation of liinear models?<p>Hi,
does anyone knows if there is a function to crossvalidated my linear model? i can only find it for descision trees unfortunately.. Thank you!</p>Tania/matlabcentral/answers/contributors/5140994-taniatag:www.mathworks.nl,2005:Question/1527802014-08-29T15:41:31Z2014-09-02T02:13:54ZHow to compress the image ?<p>for example, I have a 3D image in grayscale, 512X512X300.</p><p>I just want to compress it in X and Y plane.</p><p>I want 4 pixels to combine into one pixel.</p><p>And the value of the combined pixel takes average on that 4 pixels or take its max.</p><p>Can I directly do on 3D image? If not, please tell me how to do it on 2D image.</p><p>Thanks.</p>tabw/matlabcentral/answers/contributors/5464797-tabwtag:www.mathworks.nl,2005:Question/1531192014-09-02T02:09:54Z2014-09-02T02:09:54Zi am getting the error message : "Warning: Unsuccessful read: A timeout occurred before the Terminator was reached." when doing a fscanf to read the altimeter board<p>Hi Everyone,</p><p>I am trying to use Matlab to fetch the data from an altimeter board with the microcontroller MSP-EXP430G2. Actually a height is read from a GPS and sent to the board , which should use that data (which is not so precised) and calculate an updated more precised one. The problem is . at times it works well , but sometimes i have the following error message <b>:"Warning: Unsuccessful read: A timeout occurred before the Terminator was reached."</b> when doing the fscanf on the device (altimeter). Changing the timeout to even up to 10 did not help , nor setting the Terminator from LF to CR and vice versa. And don't know why it works only at times.</p><p>Any help will be very appreciated because i am really stuck.</p><p>Here is the matlab code :</p><pre> function [ updated_height ] = prec_height1( height )</pre><pre class="language-matlab">obj1 = instrfind('Type', 'serial', 'Port', 'COM15', 'Tag', '');
</pre><pre class="language-matlab">if isempty(obj1)
</pre><pre> obj1 = serial('COM15');</pre><pre class="language-matlab">else
</pre><pre> fclose(obj1);</pre><pre> obj1 = obj1(1);</pre><pre> set(obj1, 'TimeOut',10,'baudrate',9600,'Terminator','CR');</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">fopen(obj1);
</pre><pre> pause(0.5);</pre><pre> fprintf(obj1,'I');</pre><pre> pause(0.5);</pre><pre> hhh=height*1000;</pre><pre> % Sending the height data</pre><pre> fwrite(obj1, hhh, 'uint32');</pre><pre> obj1.ReadAsyncMode = 'continuous'; % out = fread(obj1,obj1.BytesAvailable,'uint32');</pre><pre> pause(0.5);</pre><pre class="language-matlab">fprintf(obj1,'H');
</pre><pre class="language-matlab">updated_height = fscanf(obj1,'%f');* % out=str2DOUBLE(out1);
</pre><pre> end</pre><p>Thanks in advance for your help</p>Gerko/matlabcentral/answers/contributors/5153196-gerkotag:www.mathworks.nl,2005:Question/1531102014-09-01T22:29:59Z2014-09-02T02:05:04ZHow to read file '04015.dat','04015.atr' and '04015.qrs' of MIT BIH AF Database(PHYSIONET)<p>By using the rddta.m file i can read the ecg signal from mit bih arrhythmia database.But in mit bih AF data base there are two ecg signals in a single dat file.but i badly need to read data from those files.So can any one please give me a code or suggest me how can i modify the rddta.m to read data from mit bih AF database.</p>Mahdi/matlabcentral/answers/contributors/5579219-mahditag:www.mathworks.nl,2005:Question/1523522014-08-26T05:42:07Z2014-09-02T01:52:52Zassigning a start point to a variable<p>I am writing a ga code in matlab using predefined functions. I want to assign a value to one of my variables as a start point, so for the first run, it uses the assigned value instead of creating its own. I will be appreciated if you can guide me how to do that.</p><p>Best
Elnaz</p>Elnaz/matlabcentral/answers/contributors/5189220-elnaztag:www.mathworks.nl,2005:Question/1531182014-09-02T01:45:47Z2014-09-02T01:45:47ZCan you help me plot gaussian waves or hermite waves in simulink?<p>Can you help me plot gaussian waves or hermite waves in simulink?</p>Kushal/matlabcentral/answers/contributors/5072085-kushaltag:www.mathworks.nl,2005:Question/1531172014-09-02T01:44:38Z2014-09-02T01:44:38ZCan you help me plot gaussian waves in simulink?<p>Can you help me plot gaussian waves in simulink?
Plots may be gaussian or hermite.</p>Kushal/matlabcentral/answers/contributors/5072085-kushaltag:www.mathworks.nl,2005:Question/1531152014-09-02T01:21:28Z2014-09-02T01:21:28ZUsing import matlab.io.* with Compiler<p>Using fits.openFile, fits.readKey, fits.readImg, and so forth works fine in my code when I specify import matlab.io.*. However, I can't get this to work in the compiled version. Running 8.1.0.604 (R2013a) 32-bit. Help!</p>John Kuehne/matlabcentral/answers/contributors/1847227-john-kuehnetag:www.mathworks.nl,2005:Question/1531142014-09-02T01:07:49Z2014-09-02T01:07:49Zupdating objective function using fmincon<p>Hi all,
I have a problem using fmincon. I need to run fmincon for 24 times and each time one of the outputs should be transfered to objective function for the next iteration.
the problem is that objective function can not diagnose that output from fmincon m.file.
How can I do that?</p>Afsaneh/matlabcentral/answers/contributors/3970255-afsanehtag:www.mathworks.nl,2005:Question/1531132014-09-02T00:59:29Z2014-09-02T01:03:14Zhow to use fminunc to get Hessian matrix<p>Hi,</p><p>I tried to use "fminunc" to get Hessian matrix, but received error information such as - <i>____________________________________________________________________________</i></p><p>Error using Agarch.
Too many output arguments
...
Error in rho1_H01_noplots (line 139)
[theta,fval,exitflag,output,grad,hessian] = fminunc(@(theta)Agarch(theta,z,zx),theta0,opts);</p><p>Caused by:
Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue. <i>____________________________________________________________________________</i></p><p>And I defined "opts" as - <i>____________________________________________________________________________</i></p><p>opts = optimset('GradObj','on','Hessian','on','Algorithm','sqp','Display', 'off'); <i>____________________________________________________________________________</i></p><p>I have been reading the online documents relevant to "fminunc" and "hessian" and adjusted my code correspondingly, but still can't make it work. So I am wondering if anyone could help me fix this issue.</p><p>Thanks very much!</p><p>Xiao</p>Sophia/matlabcentral/answers/contributors/4906945-sophiatag:www.mathworks.nl,2005:Question/1531112014-09-02T00:18:42Z2014-09-02T00:18:42ZHow to set up a ARMAX model with more than one exogenous time series?<p>I am trying to forecast Y1 with using Y2 and Y3 as exogenous time series I have written the following code for one input, one output. How can I write it for two inputs (Y2 and Y3)?</p><pre class="language-matlab">tseries = iddata(Y1, Y2,1)
m1 = armax(tseries, [1 1 0 0])
</pre>Fred/matlabcentral/answers/contributors/2985425-fredtag:www.mathworks.nl,2005:Question/1531082014-09-01T22:13:01Z2014-09-01T23:56:27ZInner join() Producing Duplicate Entries<p>I have several large times series of meteorological variables from the same measurement tower. I wanted to compare data values as the exact same measurement points in time. I setup serial date numbers and values into <tt>dataset()</tt> arrays similar to the following post:</p><p><a href = "http://www.mathworks.com/matlabcentral/newsreader/view_thread/310964">Match Time Series by Time Vector</a></p><p>I followed Message 5 to code something like <tt>C = join(Dataset1, Dataset2, 'Type', 'inner')</tt>. The results looked good at first input dates like the following:</p><pre class="language-matlab">[DS1.Time DS2.Time] =
01-Jan-2012 00:07:22 01-Jan-2012 00:07:22
01-Jan-2012 00:17:22 01-Jan-2012 00:17:22
01-Jan-2012 00:37:22 01-Jan-2012 00:37:22
01-Jan-2012 00:47:22 01-Jan-2012 00:47:22
01-Jan-2012 00:57:22 01-Jan-2012 00:57:22
01-Jan-2012 01:47:22 01-Jan-2012 01:07:22
01-Jan-2012 01:57:22 01-Jan-2012 01:27:22
01-Jan-2012 02:07:22 01-Jan-2012 01:47:22
01-Jan-2012 02:17:22 01-Jan-2012 01:57:22
01-Jan-2012 02:27:22 01-Jan-2012 02:07:22 ...
</pre><p>so that the resulting dates (with data) using <tt>C = join(DS1,DS2,'Type','inner')</tt> would be:</p><pre class="language-matlab">C.Time =
01-Jan-2012 00:07:22
01-Jan-2012 00:17:22
01-Jan-2012 00:37:22
01-Jan-2012 00:47:22
01-Jan-2012 00:57:22
01-Jan-2012 01:47:22
01-Jan-2012 01:57:22
01-Jan-2012 02:07:22
01-Jan-2012 02:17:22
01-Jan-2012 02:27:22 ...
</pre><p>The problems started when I would take the output <tt>C</tt> to perform more time series merging. From and inner join being like and intersection of the times in two datasets, it stands to reason that <tt>length(C) <= length(DS1)</tt> and <tt>length(C) <= length(DS2)</tt>. This became not the case using <tt>Cnew = join(C,DS4,'Type','inner')</tt>. Checking the times on the ends looked fine, but I finally discovered repeated data rows in the middle of the resulting dataset like:</p><pre class="language-matlab">Cnew.Time =
...
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11
02-Nov-2012 09:50:11 ...
</pre><p>After much investigation, the only way I found to fix this problem after an inner join was to use the <tt>unique()</tt> function in the following way:</p><pre class="language-matlab">Cnew = join( C, DS4, 'key', 'Time', 'Type', 'inner', 'MergeKeys', true ) ;
CnewUnique = unique(Cnew , 'Time') ;
</pre><p>This would finally produce the output I was looking for:</p><pre class="language-matlab">CnewUnique.Time = ...
02-Nov-2012 09:00:11
02-Nov-2012 09:10:11
02-Nov-2012 09:20:11
02-Nov-2012 09:30:11
02-Nov-2012 09:40:11
02-Nov-2012 09:50:11
02-Nov-2012 10:00:11
02-Nov-2012 10:10:11
02-Nov-2012 10:20:11 ...
</pre><p>This took <b>many</b> hours to figure out so I wanted to ask the following question(s):</p><ol><li>Why was the <tt>join(...,'inner',...)</tt> not working the way I expected, as it did before?</li><li>Is there a better way to match up the times from several time series? (I did not have success with the <a href = "http://www.mathworks.com/help/matlab/ref/timeseries.synchronize.html">synchronize</a> function either for an "intersection" of the times.)</li><li>Has anyone else had a similar problem? Is Matlab possibly having a "bug"-type behavior here?</li></ol><p>Any insights are appreciated. Thank you for contributing this this post.</p>Paul Quelet/matlabcentral/answers/contributors/4012500-paul-quelettag:www.mathworks.nl,2005:Question/1530942014-09-01T19:30:07Z2014-09-01T22:29:30ZStop/Delete Timer Issues While Closing GUI<p>Hi,</p><p>I use a timer to update an axes in a GUI. I want to handle the case in which the user closes the window while the timer is still running, i.e., the axes still beeing updated.</p><p>The Problem:</p><p>However, every so often the execution time of the TimerFcn is longer than the timers period (depending on the pc's performance). This can cause an error when closing the GUI while the timer is still running.</p><pre> Error while evaluating TimerFcn for timer 'timer-1'</pre><pre> Bad handle</pre><p>FYI, I use</p><pre> T = timerfind;
if ~isempty(T)
stop(T)
delete(T)
end</pre><p>in the figure's delete function. Apparently, the TimerFcn is still being called after the execution of the figure's delete function. Hence, within my TimerFcn an error occurs during a call to</p><pre> cla(myaxes),</pre><p>for cla expects a valid figure handle (though the GUI's figure has just been deleted).</p><p>All in all, it seems that the execution time being larger than the timer period is causing this. Of course I could reduce the timer period, but this is not desirable. I figured out a workaround by using a try-catch phrase within the TimerFcn, however it's not a proper solution.</p><p>Question:</p><p>Is there any way to force the TimerFcn to stop and somehow flush its executin queue/event buffer, regardless of its current state? Any thoughts about solving this issue are very welcome!</p><p>Thank you in advance!</p><p>Hannes</p>Hannes/matlabcentral/answers/contributors/5554056-hannestag:www.mathworks.nl,2005:Question/1530612014-09-01T13:30:01Z2014-09-01T22:27:31Zhow can i make a change in my image ?<p>hi guys .
i have an image (257*161) .</p><p>im = f(x,y)</p><p>how can i change my image equation to im = f(x/8 , y/12 )</p><p>could you please help me ?</p><p>thanks</p>hamed/matlabcentral/answers/contributors/3810756-hamedtag:www.mathworks.nl,2005:Question/1531072014-09-01T22:05:32Z2014-09-01T22:05:32ZHow can i get data with getdata but when i got some number of samples i can use it in other function while i am getting others sample?<p>I want to get data with getdata function but when i use it, i have to wait until the function get all samples, I want to know if can i use this function and when i get some number of samples I can use it in others function and continus with the adquisition without problem</p><p>Regards</p>Jesus/matlabcentral/answers/contributors/1671943-jesustag:www.mathworks.nl,2005:Question/1531062014-09-01T22:01:58Z2014-09-01T22:01:58Zhelp in p code<p>good evening everybody</p><p>my question is how can I add a help within a p code ?</p><p>thanks in advance</p>XAXRXTX/matlabcentral/answers/contributors/4836391-xaxrxtxtag:www.mathworks.nl,2005:Question/1531042014-09-01T20:59:33Z2014-09-01T21:50:35Zcalculation of observable area of an airplane?<p>I have an application where I need the observed equivalent area of an airplane in an arbitrary orientation. That is if the observer is directly under the AC the area would simply the be the 3-view top area, but what if the observer were 45deg behind the right wing and 30deg below the horizontal plane of the AC? I have been using an approximation that ignores wing area-this is no longer sufficient.</p><p><a href = "http://en.wikipedia.org/wiki/Projected_area">wikipedia</a> has an ok article, by extension I could sum the three areas each corrected by cos(beta). But does not account for when one surface is partly hiding a second surface.</p><p>Currently I am using a simple method given 2d area and observed angle (cos(beta) effectively), I would consider a method that required 2d surface point definitions for top/left/fore.</p><p>Run time is not critical, provided I can sweep it into a 2d data table (range is handled by other means).</p><p>Any direction or key words to search on would be appreciated. thanks.</p>chris/matlabcentral/answers/contributors/5389725-christag:www.mathworks.nl,2005:Question/1531052014-09-01T21:49:09Z2014-09-01T21:49:09ZTime simulation with FRD model<p>Hello</p><p>I have a FRD model of a linear system. Is it possible to use it to run time simulations to an input I will define in time domain?</p><p>Thanks</p>Michele/matlabcentral/answers/contributors/5351676-micheletag:www.mathworks.nl,2005:Question/1257272014-04-14T16:03:11Z2014-09-01T21:31:24ZHow to apply Kalman filter on time series? <p>I have time series from stock market and want to apply the Kalman Filter. I read the samples about the setup of the Filter and they all work with some kind of matrizes. The command dspadpt3 gives me some weird mask which I have no conlcusion about handling it.</p><p>So, my main purpose would be so apply the Filter on a time series and see how it is adapted resp. hulled in (var resp. covar?).</p><p>Is there a hint resp. sample how to start the stuff? (e.g. how to get the matrixes, how to continue for a plot, etc.)</p>Leo/matlabcentral/answers/contributors/5217676-leotag:www.mathworks.nl,2005:Question/1530352014-09-01T08:15:15Z2014-09-01T21:12:56Zanimation : movie + comet in one figure (subplots)<p>Hi, I would like to plot two different animations in one figure. One the one hand I have a comet plot:</p><pre class="language-matlab">comet(data.pg{1,1});
</pre><p>And then I have an animation of a bar plot:</p><pre class="language-matlab">axis tight manual;
set(gca,'NextPlot','replaceChildren');
for i = 1:length(emg2{1,1})
extensors = [emg2{1,1}(i,1:5);emg2{1,1}(i,6:10);emg2{1,1}(i,11:15);emg2{1,1}(i,16:20);emg2{1,1}(i,21:25);emg2{1,1}(i,26:30);emg2{1,1}(i,31:35);emg2{1,1}(i,36:40);emg2{1,1}(i,41:45)];
bar3(abs(extensors))
F(i) = getframe;
end
movie(fig,F,1)
</pre><p>Now I want both animations to run at the same time and in the same figure but in subplots. I used a code but it doesn't work. Can anybody help ?</p><pre class="language-matlab">axis tight manual;
set(gca,'NextPlot','replaceChildren');
for i = 1:length(emg2{1,1})
subplot(1,2,1);
extensors = [emg2{1,1}(i,1:5);emg2{1,1}(i,6:10);emg2{1,1}(i,11:15);emg2{1,1}(i,16:20);emg2{1,1}(i,21:25);emg2{1,1}(i,26:30);emg2{1,1}(i,31:35);emg2{1,1}(i,36:40);emg2{1,1}(i,41:45)];
bar3(abs(extensors))
subplot(1,2,2);
comet(data.pg{1,1});
F(i) = getframe;
end
movie(F,1)
</pre>N/matlabcentral/answers/contributors/4790141-ntag:www.mathworks.nl,2005:Question/1527672014-08-29T12:40:35Z2014-09-01T20:57:33Zxcorr and time lag<p>Hi all,</p><p>I have a simple, but yet I can't seem to figure it out, question about crosscorrelation.When I find my maximum crosscorrelation, I want to find the corresponding time lag.
What I have in code so far:</p><pre class="language-matlab">x = [0 0 1 5 1 -2 -3 -2 0 0];
y = [0 0 1 5 1 -2 -3 -2 0 0];
X2 = xcorr(x,y,'coeff'); (so we expect a xcorr of 1 because its the same signal)
plot(lags,C)
[val,idx] = max(abs(C))
</pre><p>Now it says that the maximum crosscorrelation (1) is at time lag 10. now I get that because the time series goes from -9 till +9, so step 10 is at zero-lag, but how can I get as answer the zero and not 10. So I want the real value of time lag and not the amount of steps.</p><p>Later on I would actually want to make the time lags correspond to real time as well ,so for example a lag of 1 equals to 2 seconds, which is the reason I want the amount and not the steps so I know how many seconds really passed. How can I do this also, so make the time lag correspond to real seconds?</p>N/matlabcentral/answers/contributors/4790141-ntag:www.mathworks.nl,2005:Question/1531012014-09-01T20:30:17Z2014-09-01T20:57:04ZI need to make a computation that will return the answer with units. <pre> I wrote several programs with will make my desired computations successfully. my problem arises when I try to add a line that will allow the user to type in the units (feet for example) used then return that unit squared Ft^2 or square feet.</pre><p>I have a program with will compute the area of a square successfully .</p><pre> X=hight
y=base
fprintf (the area is %d \n x*y)</pre><pre> this program will return the area but i need to have units after the number (ft^2) and I need for the user to choose the units. </pre>daniel/matlabcentral/answers/contributors/5574603-danieltag:www.mathworks.nl,2005:Question/1529302014-08-30T21:20:30Z2014-09-01T20:50:49Zvalues of randi function repeat themselves<p>while using the function randi that generate random integers uniformly disterbuted i sometimes get in the output vector the same numbers
for example:</p><p>4 2 5 3 4 8 7 9 7 4</p><p>(the number 4 was three times in the row above)</p><p>how can i avoid this?</p><pre class="language-matlab">locTX=randi([1 20],1,4);
</pre>Kobi/matlabcentral/answers/contributors/3268302-kobitag:www.mathworks.nl,2005:Question/1530762014-09-01T15:32:19Z2014-09-01T20:46:25ZStatus for forum members: who would use/care for it?<p>Dear all,</p><p> I am well aware that the TMW forum is not Skype or gChat, but, while traveling for an extended period of time, I would be happier if I had been able to change my/some "status for the TMW forum" to "Traveling until mid-September", rather than just disappearing without leaving a note.</p><p>Hence my question (before I submit something to TMW): if there was a status field in users' profiles, would you use it and/or care for it?</p><p>Best wishes,</p><p>Cedric</p>Cedric Wannaz/matlabcentral/answers/contributors/1078046-cedric-wannaztag:www.mathworks.nl,2005:Question/1530222014-09-01T03:59:07Z2014-09-01T20:41:41ZMatlab very slow at initialization and execution. Why?<p>Hi,</p><p>I recently upgraded my matlab version to 2013a from 2011. I had a network license earlier and now a license key. I have a mac (Mavericks - 10.9.4) and uninstalled 2011 before I installed 2013a. But every since its installation, matlab has become extremely slow. It takes a really long time for initialization (approx 5 mins after opening the window) and then a very long time every time I run simple commands (like print a 2x2 matrix that I just defined). I also upgraded to JAVA (jdk and jre) to 1.7 version.</p><p>Thanks,
PH</p>Pavithra/matlabcentral/answers/contributors/2357755-pavithra