http://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-08-31T17:52:18Ztag:nl.mathworks.com,2005:Question/2384222015-08-31T17:09:19Z2015-08-31T17:52:18Zhow to filter 50Hz harmonics ?<p>Hi , im analyzing recorded signal , I've recorded the noise and the data separately , I've found that the data signal is a little bit noisy , when i made an fft to the noise signal , i've found that it included an dc component and harmonics of 50Hz , i've filtered the dc component using the mean subtraction , but have no idea how to filter the harmonics of 50 Hz , i can use notch to filter the 50Hz but how can i filter its harmonics . My data signal is 50 - 2500 Hz.
here is the noise :</p><img src = "/matlabcentral/answers/uploaded_files/36437/Noise.JPG"><p>i've also include the mat file of the signal.</p>cobhttp://nl.mathworks.com/matlabcentral/profile/authors/5325488-cobtag:nl.mathworks.com,2005:Question/2384342015-08-31T17:42:04Z2015-08-31T17:49:51ZHow i can read the distance in matrix figure?<p>such as</p>khaled alhasanathttp://nl.mathworks.com/matlabcentral/profile/authors/6845885-khaled-alhasanattag:nl.mathworks.com,2005:Question/2381012015-08-31T00:51:58Z2015-08-31T17:47:33ZHow does particle swarm deal with objective function evaluations to NaN?<p>Hi everyone,
Simple question, though I haven't been able to find a definite answer: How does the Particle Swarm optimization routine deal with points that return a value of the objective function of NaN? I know that if FunValCheck can force it to stop in this event, but what is the default behavior?</p><p>Thanks!</p>Johnhttp://nl.mathworks.com/matlabcentral/profile/authors/2701035-johntag:nl.mathworks.com,2005:Question/2383792015-08-31T15:35:56Z2015-08-31T17:43:42ZHow could I write into the command prompt window of windows 7 with my matlab script?<p>Hello,</p><p>I'm trying to write a line into my command prompt window of Windows 7 with a matlab script, it can open it well but I didn't find how to write in it and simulate 'enter'. Would anyone know how to do that? Thank you in advance!</p><pre class="language-matlab">Lance_filename = 'Script.txt';
Input_filename = 'filename.txt';
</pre><pre class="language-matlab">fid = fopen(Lance_filename,'w');
script=sprintf('App.exe %s',Input_filename);
fwrite(fid,script,'char');
fclose(fid);
</pre><pre class="language-matlab">!cmd
</pre><pre class="language-matlab">%!cmd < Script.txt
%system('cmd.exe &');
</pre>Alberthttp://nl.mathworks.com/matlabcentral/profile/authors/6844948-alberttag:nl.mathworks.com,2005:Question/1539842014-09-08T05:49:55Z2015-08-31T17:42:06ZHow can I have two x-labels below x axis showing both LATITUDE and LONGITUDE points?<p>Both lat/lon spacing are equal and forms square grid boxes. I have another variable at y-axis.</p><p>I have attached one figure for illustration...</p><img src = "/matlabcentral/answers/uploaded_files/17922/Capture.PNG">Prasenjithttp://nl.mathworks.com/matlabcentral/profile/authors/5051877-prasenjittag:nl.mathworks.com,2005:Question/2383212015-08-31T12:57:16Z2015-08-31T17:33:53Zrandom uniform sample example<p>I am trying to generate a function but there is an error</p><p>my code is</p><pre> function X=Random_Uniform_Sample(number, dim, mins, maxs)
interval=repmat(maxs-mins, number, 1);
start=repmat(mins, number, 1);
X=interval.*rand(100,2)+start;
end</pre><p>there is an error in dim. i define number=100; dim=2;mins[-1 3]; and maxs=[2 7];</p>rathod ujjval rameshbhaihttp://nl.mathworks.com/matlabcentral/profile/authors/6506111-rathod-ujjval-rameshbhaitag:nl.mathworks.com,2005:Question/2384332015-08-31T17:33:22Z2015-08-31T17:33:22ZHow to use axes function outside of a loop?<p>I'm using the function axes inside of a loop in a GUIDE application. However, it can be slow. Is there any alternative to use it outside of the loop?
(The graphs must be in a certain position where I put on the GUIDE).</p><p>Thank you.</p>Maikon Del Re Perinhttp://nl.mathworks.com/matlabcentral/profile/authors/6603048-maikon-del-re-perintag:nl.mathworks.com,2005:Question/2383692015-08-31T14:35:42Z2015-08-31T17:33:10ZIs it possible to write a large table into a binary file? How?<p>I have a large table. If I write it into a text file, it is huge.
Is it possible to write a large table into a binary file? If yes, how?</p><p>I googled this subjest, but all the links only refer to non-table type.
For table, writetable function does not mention binary file.</p><p>Thanks.</p><p>Jennifer</p>Jennifer Zhouhttp://nl.mathworks.com/matlabcentral/profile/authors/6201072-jennifer-zhoutag:nl.mathworks.com,2005:Question/2384322015-08-31T17:30:15Z2015-08-31T17:41:31ZFor my GUI, how can I have one button open the file then the other buttons modify that file?<p>How would I link the file I open to the other buttons?</p>shannon stoffelhttp://nl.mathworks.com/matlabcentral/profile/authors/6822172-shannon-stoffeltag:nl.mathworks.com,2005:Question/2370042015-08-27T13:50:48Z2015-08-31T17:27:09ZSelf Organising Maps Toolbox<p>Currently trying to fill a gap in my knowledge. I have used the SOM Toolbox (https://github.com/ilarinieminen/SOM-Toolbox) to visualise data. However, i now wish to cluster the data or extract the information as to where my original input data is clustered. I have tried finding the BMU as a proxy for clusters but they have all been assigned to the same BMU according to the output.</p><p>Any help or suggestions would be greatly appreciated as i am a Matlab novice.</p>Jake Stephenhttp://nl.mathworks.com/matlabcentral/profile/authors/6375043-jake-stephentag:nl.mathworks.com,2005:Question/14272011-02-16T09:53:30Z2015-08-31T17:27:03ZWhat frustrates you about MATLAB?<p>I love MATLAB. It is so quick and easy to write software to do what you want. It has excellent debugging and profiling tools. It is cross platform, making code easy to share (assuming the other people have forked out for the not-so-cheap license). It has interfaces to other software.</p>
<p>However, there are some things about it that irk me. I'd like to hear from other people what things annoy them about MATLAB.</p>Oliver Woodfordhttp://nl.mathworks.com/matlabcentral/profile/authors/1073021-oliver-woodfordtag:nl.mathworks.com,2005:Question/2381402015-08-31T02:54:35Z2015-08-31T17:26:18Zcustom colors in plot (without loop)<p>Hi, suppose I have a custom color array:</p><pre class="language-matlab">c=[1 0 0
0 1 0
0 0 1]
</pre><p>Is there a way use the color array in a plot without looping? The following doesn't work:</p><pre class="language-matlab">plot(rand(100,3),'color',c)
</pre>Rainerhttp://nl.mathworks.com/matlabcentral/profile/authors/4041116-rainertag:nl.mathworks.com,2005:Question/2378122015-08-29T19:55:24Z2015-08-31T17:20:35ZHow to increase initial step size in optimization toolbox?<p>I am trying to use optimization toolbox for minimization. The problem is that, the initial change in the design variables is too small and my objective function is not too sensitive to these small changes, so after a few steps the optimization process terminates because of no change in the value of objective function. Is there any way to increase the initial step size?
Here is an example of one of my design variables in the first and second steps: First step: x=1.0, second step: x=1.000000014901161
as you see the change is about 0.000000014901161 which is too small for my problem. I would like to increase this change in the begining.</p><p>Thank you.</p>Mohammad Farshchinhttp://nl.mathworks.com/matlabcentral/profile/authors/3727592-mohammad-farshchintag:nl.mathworks.com,2005:Question/2384262015-08-31T17:15:50Z2015-08-31T17:15:50ZHow can I fix plot problems when allocating memory outside of a loop?<p>I'm using serial port to collect data. Inside of the loop, I have a vector to store the data points and then plot in a graph, but I need to allocate memory outside of the loop. When I do it, all the data points start from the origin (like the picture below).
I'm allocating memory this way:</p><pre class="language-matlab">v2 = zeros(100,1);
v1 = zeros(100,1);
t = zeros(100,1);
</pre><p>How can I fix it?</p><img src = "/matlabcentral/answers/uploaded_files/36439/problems.jpg"><p>Thank you.</p>Maikon Del Re Perinhttp://nl.mathworks.com/matlabcentral/profile/authors/6603048-maikon-del-re-perintag:nl.mathworks.com,2005:Question/2384212015-08-31T17:09:11Z2015-08-31T17:09:11ZHow to edit main.c file obtained through MATLAB coder?<p>Hi,
I am having trouble entering actual values to this main.c file which by default gives a null value for everything. Please help me understand how to edit it.
* Academic License - for use in teaching, academic research, and meeting
* course requirements at degree granting institutions only. Not for
* government, commercial, or other organizational use.
*
* main.c
*
* Code generation for function 'main'
*
*/</p><p>/*************************************************************************/
/* This automatically generated example C main file shows how to call <b>/
/</b> entry-point functions that MATLAB Coder generated. You must customize <b>/
/</b> this file for your application. Do not modify this file directly. <b>/
/</b> Instead, make a copy of this file, modify it, and integrate it into <b>/
/</b> your development environment. <b>/
/</b> <b>/
/</b> This file initializes entry-point function arguments to a default <b>/
/</b> size and value before calling the entry-point functions. It does <b>/
/</b> not store or use any values returned from the entry-point functions. <b>/
/</b> If necessary, it does pre-allocate memory for returned values. <b>/
/</b> You can use this file as a starting point for a main function that <b>/
/</b> you can deploy in your application. <b>/
/</b> <b>/
/</b> After you copy the file, and before you deploy it, you must make the <b>/
/</b> following changes: <b>/
/</b> * For variable-size function arguments, change the example sizes to <b>/
/</b> the sizes that your application requires. <b>/
/</b> * Change the example values of function arguments to the values that <b>/
/</b> your application requires. <b>/
/</b> * If the entry-point functions return values, store these values or <b>/
/</b> otherwise use them as required by your application. <b>/
/</b> <b>/
/************************************************************************</b>/
/* Include files */
#include "rt_nonfinite.h"
#include "FRW.h"
#include "main.h"
#include "FRW_terminate.h"
#include "FRW_initialize.h"</p><p>/* Function Declarations */
static void argInit_5x1_real_T(double result[5]);
static double argInit_real_T(void);
static void main_FRW(void);</p><p>/* Function Definitions */
static void argInit_5x1_real_T(double result[5])
{
int b_j0;</p><pre class="language-matlab">/* Loop over the array to initialize each element. */
for (b_j0 = 0; b_j0 < 5; b_j0++) {
/* Set the value of the array element.
Change this value to the value that the application requires. */
result[b_j0] = argInit_real_T();
}
}
</pre><p>static double argInit_real_T(void)
{
return 0.0;
}</p><p>static void main_FRW(void)
{
double dv0[5];
double Weight;</p><pre class="language-matlab">/* Initialize function 'FRW' input arguments. */
/* Initialize function input argument 'coeff'. */
/* Call the entry-point 'FRW'. */
argInit_5x1_real_T(dv0);
Weight = FRW(argInit_real_T(), argInit_real_T(), argInit_real_T(),
argInit_real_T(), argInit_real_T(), argInit_real_T(), dv0);
}
</pre><p>int main(int argc, const char * const argv[])
{
(void)argc;
(void)argv;</p><pre class="language-matlab">/* Initialize the application.
You do not need to do this more than one time. */
FRW_initialize();
</pre><pre class="language-matlab">/* Invoke the entry-point functions.
You can call entry-point functions multiple times. */
main_FRW();
</pre><pre class="language-matlab">/* Terminate the application.
You do not need to do this more than one time. */
FRW_terminate();
return 0;
}
</pre><p>/* End of code generation (main.c) */</p>Heena Agrawalhttp://nl.mathworks.com/matlabcentral/profile/authors/6237995-heena-agrawaltag:nl.mathworks.com,2005:Question/2384152015-08-31T17:02:29Z2015-08-31T17:02:29ZIs there any multi criteria analysis script or command in Matlab to simultaneously classify data in several categories?<p>Hello,</p><p>is there any multi criteria analysis script or command in Matlab to simultaneously classify data in several categories?</p>jorge salashttp://nl.mathworks.com/matlabcentral/profile/authors/6066225-jorge-salastag:nl.mathworks.com,2005:Question/2383222015-08-31T12:59:03Z2015-08-31T16:51:23ZHow to adjust the position of legend when creating plot using matlab? <p>How to adjust the position of legend when creating plot using matlab? When the plot is displayed the legend is making the points invisible by overlapping it.</p>D Josephhttp://nl.mathworks.com/matlabcentral/profile/authors/6724986-d-josephtag:nl.mathworks.com,2005:Question/2370182015-08-27T14:14:44Z2015-08-31T16:49:01ZCall a Fortran code in Matlab to get the result which I will use it in Matlab code<p>I have a Fortran code and I want to run it in MATLAB, By this I will get the output from Fortran code and will use it in Matlab code. I was trying with system command but it is only opening Fortran interface with code not running.Please help me to do this.</p>Sumit Palhttp://nl.mathworks.com/matlabcentral/profile/authors/6814463-sumit-paltag:nl.mathworks.com,2005:Question/2384052015-08-31T16:47:09Z2015-08-31T16:47:09Zgenerating 3-d plots <p>Dear all,
I am working on obstacle aviodance algorithm. I am doing it through constraint optimisation techniques. I wish to formulate a x-y-z field where x and y is distance in meters and z is height. In this plane i wish to places various objects with different shapes (circle, oval, square etc.) representing the obstacles. Can someone suggest some generic single equation consisting of tuning parameters using which i can do it. I tried approch given in section 3.3 of <a href = "http://www.sciencedirect.com/science/article/pii/S1000936113000915">http://www.sciencedirect.com/science/article/pii/S1000936113000915</a> but i was unable to show same results. Plesae help and suggest.
regards</p>IISchttp://nl.mathworks.com/matlabcentral/profile/authors/4333375-iisctag:nl.mathworks.com,2005:Question/2369902015-08-27T13:15:11Z2015-08-31T16:24:49ZWhat is edit text box type in GUI when I using findobj function?<p>Hi,</p><p>I try to get GUI edit text box object in separate m-file because I like to print something to this text box from m-file. What is the 'Type' of this edit text box when using findobj function?</p><p>Teemu</p>Teemu Juujärvihttp://nl.mathworks.com/matlabcentral/profile/authors/6662153-teemu-juujarvitag:nl.mathworks.com,2005:Question/2370802015-08-27T17:29:02Z2015-08-31T16:20:44ZHow to generate code for model without building included s-function<p>Hello, and thanks for your time.</p><p>I would like to generate external code for the General Real-Time Target that references an S-function that isn't built at code-generation time.</p><p>The S-function we're using can't be built on the same computer that we're developing our Simulink model on, because we don't have access to the libraries that are required. (I.e. we can't build our S-function because we'd get linker errors, and we can't resolve those errors.)</p><p>However, the S-function builder can generate code, and Simulink can generate code, so I thought it should be possible to generate the code for both, move them to the final destination, and build everything together (with the third-party libraries present) at that point in time. Unfortunately, if you try to generate code for a Simulink model that contains an unbuilt S-function you just get the error "S-function does not exist". This doesn't really make sense- is the complied version of the S-function really required to just generate code for the Simulink model?</p><p>Is there any way we can configure Simulink to let us generate code in this situation?</p><p>Thanks in advance,
James</p>James Orrhttp://nl.mathworks.com/matlabcentral/profile/authors/6775367-james-orrtag:nl.mathworks.com,2005:Question/2304552015-07-20T09:01:44Z2015-08-31T16:20:04ZTrue heading and Wind direction<p>Hello,</p><p>Given I have wind value, wind direction and true direction</p><p>May i know if in matlab, we have a function which resolves the wind into components parallel and perpendicular to my true direction?</p><p>In the end, I want to know if we have headwind or tailwind component?</p><p>Thanks</p>yashvinhttp://nl.mathworks.com/matlabcentral/profile/authors/4047317-yashvintag:nl.mathworks.com,2005:Question/2381462015-08-31T03:10:14Z2015-08-31T16:19:55ZCombine a (m x n x p) matrix (image) of 8 bit numbers to a (m x n) matrix of 24 bit numbers and vice versa<p>Say there is a matrix of (m x n x p), esp. a color image with R G and B channel. Each channel information is 8-bit integer.</p><p>But, for an analysis, the three 8-bit values have to be combined to get a 24-bit value and the analysis is done on the (m x n) matrix of 24-bit values.</p><p>After the analysis, the matrix has to be decomposed back to three 8-bit channels for displaying the results.</p><p>What I am doing right now:</p><ul><li>Iterating through all the values in the matrix</li><li>Convert each decimal value to binary (using `dec2bin`)</li><li>Combine the three binary values together to get a 24-bit number (using `strcat` and `bin2dec`)</li></ul><p>Code:</p><pre> for i=1:m
for j=1:n
new_img(i,j) = bin2dec(strcat(...
sprintf('%.8d',str2double(dec2bin(img(i,j,1)))), ...
sprintf('%.8d',str2double(dec2bin(img(i,j,2)))), ...
sprintf('%.8d',str2double(dec2bin(img(i,j,3))))));
end
end</pre><p>For the decomposition back to three 8-bits after analysis, the exact reverse process is done, still iterating through (m x n) values.</p><p>The problem is huge computation time.</p><p>I know that this is the not the correct way of doing this. Is there any matrix operation that I can do to achieve this so that the computation is done quickly?</p>Shahidh Khttp://nl.mathworks.com/matlabcentral/profile/authors/4491153-shahidh-ktag:nl.mathworks.com,2005:Question/2383912015-08-31T16:17:20Z2015-08-31T16:17:20ZI need some help in Genetic Algorithm Optimization... I have a fully functional code... i need to run GA for three parameters there and maximize one result... i need an example for three parameters... an example would help me a lot!!! can anyone help<p>examples needed... for three parameter optimization at the same time</p>Ifat Rahmanhttp://nl.mathworks.com/matlabcentral/profile/authors/4360839-ifat-rahmantag:nl.mathworks.com,2005:Question/2383882015-08-31T16:05:46Z2015-08-31T16:15:01ZHow can I use the compass function, changing the vector position during the time?<p>Hi.
I'm using serial port to collect data and I need to plot it using the fucntion compass.
For each data sample, I need to update the plot using compass (arrows emanating from the origin).
I'm using this code now:</p><pre class="language-matlab">axes(handles.axes3)
h=compass(eletrodo1, eletrodo2);
hold on;
drawnow;
</pre><p>The problem is, when I update the plot with new data, the past data still remains on the plot. I don't know how to clean the plot for each new data point.
Can someone help me?
Thank you.</p>Maikon Del Re Perinhttp://nl.mathworks.com/matlabcentral/profile/authors/6603048-maikon-del-re-perintag:nl.mathworks.com,2005:Question/2383832015-08-31T15:42:47Z2015-08-31T16:07:23ZLink between FIR and Genetic Algorithm toolbox to mitigate noise from communication signal<p>please can anyone help me to figure out how can I link between FIR filter and GA to create an equalizer to remove ISI or Noise from signal?</p>Alaa Fareedhttp://nl.mathworks.com/matlabcentral/profile/authors/6801923-alaa-fareedtag:nl.mathworks.com,2005:Question/2380542015-08-30T16:03:36Z2015-08-31T16:06:33ZChanging parameters in an ODE<p>I wish to change one of the parameters at each time step for an ODE solution plot. My function is as follows:</p><pre> function [t,v]=shig(b,p,m,yo)
[t v] = ode45(@fnsirtry,[0 12],yo);</pre><pre> function fnsir = fnsirtry(t,v)
a = 0.25;
r = 0.14;
fnsir(1) = p - m*v(1)-b*v(1)*v(2)+a*v(3);
fnsir(2) = (b*v(1))- (m + r)*v(2);
fnsir(3) = (r*v(2))-((m+a)*v(3));
fnsir = fnsir(:);</pre><pre> end
end</pre><p>When I plot the ODE, I want to change the value of b at each step. I have used a code like teh following:</p><pre class="language-matlab">temp = [5 9 12 17 19 24 28 27 22 17 10 7];
beta = 0.0000025*temp;
i = [1 2 3 4 5 6 7 8 9 10 11 12];
for i = 1;
b = beta(:,1)
end
for i = 2;
b = beta(:,2)
end
for i = 3;
b = beta(:,3)
end
for i = 4;
b = beta(:,4)
end
for i = 5;
b = beta(:,5)
end
for i = 6;
b = beta(:,6)
end
for i = 7;
b = beta(:,7)
end
for i = 8;
b = beta(:,8)
end
for i = 9;
b = beta(:,9)
end
for i = 10;
b = beta(:,10)
end
for i = 11;
b = beta(:,11)
end
for i = 12;
b = beta(:,12)
end
</pre><pre class="language-matlab">P = 5000;
m = 0.013;
</pre><pre class="language-matlab">yo = [200000 160 0];
[t v] = shig(b,p,m,yo);
w = [159
148
143
137
102
91
85
137
119
108
104
100];
subplot (1,2,1)
plot(t,v(:,2))
%,'-r*','Linewidth',1.5,'MarkerSize',5)
title('Infected Population')
%legend('Disease free state','Test state')
subplot(1,2,2)
plot(w)
</pre><p>Could I please get some light on this,, pls...</p>Ojaswitahttp://nl.mathworks.com/matlabcentral/profile/authors/4283965-ojaswitatag:nl.mathworks.com,2005:Question/2368902015-08-27T09:04:25Z2015-08-31T16:03:46ZI have used [K,M,F]=assema(P,T,C,A,F). It does indeed assemble a stiffness matrix K and the right hand side F. But it always returns an empty mass matrix M for all problems. Why is that?<p>I am solving scalar elliptic problems. I am using matlab to assemble my stiffness matrices but I suspect there is a bug in [K,M,F]=assema(P,T,C,A,F) as it has always returned an empty sparse mass matrix M for all input I have given it.</p>Erik Eikelandhttp://nl.mathworks.com/matlabcentral/profile/authors/3335766-erik-eikelandtag:nl.mathworks.com,2005:Question/2383862015-08-31T16:03:43Z2015-08-31T16:03:43Zhow can I adjust the contrast of an image in cpselect window. My fixed image has a bad contrast compared to my moving image and I want to fix this. Can anyone help?<p>function [xymoving_out,xyfixed_out]=Two_D_Landmark_Reg_082715(fixed_image,moving_image)
moving=moving_image;
fixed=fixed_image;
fixed=imcontrast(fixed);
show_moving=imshow(moving,[]);
get_property=get(show_moving,'CData');
conadj_moving=imadjust(get_property);
close all
[xymoving_out,xyfixed_out]=cpselect(conadj_moving,fixed,'wait',true);
end
I try to run this and I get the rolling error</p><p>Error using iptcheckhandle (line 54)
Function IMCONTRAST expected its first input argument, H, to be a valid handle to a
single graphics object.</p><p>Error in imcontrast (line 70)
iptcheckhandle(handle, {'figure', 'axes', 'image', 'uipanel'},...</p><p>Error in Two_D_Landmark_Reg_082715 (line 14)
fixed=imcontrast(fixed);</p>Slimhttp://nl.mathworks.com/matlabcentral/profile/authors/6845211-slimtag:nl.mathworks.com,2005:Question/2383852015-08-31T15:57:11Z2015-08-31T16:22:29ZFinal delay states for use in closed loop simulation – how do I get them if I have several external predictors?<p>I have trained a <tt>NARXNET</tt> to the point where I’m satisfied with its performance, but almost every time I convert the net into closed loop form to predict ahead without targets the first few values that are being predicted are way off where they should be – if I’m for example simulating 60 steps ahead with external predictors, it is very common that the first 1:5 predictions are much less accurate than the remaining 6:60.</p><p>I suspect that this problem has to do with the layer states that I’m using in the closed loop simulation, I read a <a href = "http://se.mathworks.com/matlabcentral/answers/14970-neural-network-multi-step-ahead-prediction">post made some time ago by Mark Hudson Beale</a> giving an example as to how to acquire the correct delay states to use in closed loop simulation as:</p><pre> %(This is just the last part of the example)
% 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);</pre><p>When I run the code on his example it works fine, but since I in my own problem have several external predictors, when I try it there I’m getting an error saying:</p><pre class="language-matlab">Error using mat2cell (line 97)
Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [37 2].'
</pre><p>Because what I’m getting out from the loop (Ai2) is a 27x2 matrix that has just been processed by the nets process function <tt>mapminmax</tt>.</p><p>Could someone advise me on how to get the correct delay conditions for closed loop simulation in a situation with multiple external predictors?</p><p>Thanks.</p>Petahttp://nl.mathworks.com/matlabcentral/profile/authors/5582424-petatag:nl.mathworks.com,2005:Question/2383722015-08-31T14:43:31Z2015-08-31T15:56:57ZNaN does not operate symmetrically with integer classes<p>If you are working with the integer classes, and you mix a NaN into arithmetic calculations with the data, then the result differs depending on whether the NaN appears in the <i>first</i> operation or if the NaN is encountered afterwards. At least on R2014a that is.</p><pre class="language-matlab">X = {NaN, uint8(2), uint8(3), uint8(4)};
T = perms(X);
total = @(A,B,C,D) A+B+C+D;
for K = 1 : size(T,1); result{K} = total(T{K,1},T{K,2},T{K,3},T{K,4}); end
[result(:),T]
</pre><p>ans =</p><pre> [0] [ 4] [ 3] [ 2] [NaN]
[2] [ 4] [ 3] [NaN] [ 2]
[0] [ 4] [ 2] [ 3] [NaN]
[3] [ 4] [ 2] [NaN] [ 3]
[5] [ 4] [NaN] [ 2] [ 3]
[5] [ 4] [NaN] [ 3] [ 2]
[0] [ 3] [ 4] [ 2] [NaN]
[2] [ 3] [ 4] [NaN] [ 2]
[0] [ 3] [ 2] [ 4] [NaN]
[4] [ 3] [ 2] [NaN] [ 4]
[6] [ 3] [NaN] [ 2] [ 4]
[6] [ 3] [NaN] [ 4] [ 2]
[0] [ 2] [ 3] [ 4] [NaN]
[4] [ 2] [ 3] [NaN] [ 4]
[0] [ 2] [ 4] [ 3] [NaN]
[3] [ 2] [ 4] [NaN] [ 3]
[7] [ 2] [NaN] [ 4] [ 3]
[7] [ 2] [NaN] [ 3] [ 4]
[6] [NaN] [ 3] [ 2] [ 4]
[6] [NaN] [ 3] [ 4] [ 2]
[7] [NaN] [ 2] [ 3] [ 4]
[7] [NaN] [ 2] [ 4] [ 3]
[5] [NaN] [ 4] [ 2] [ 3]
[5] [NaN] [ 4] [ 3] [ 2]</pre><p>It took me time to understand this table, and I had to do further tests to be sure. The first column is the result of the addition of the other 4 columns in that order, A+B+C+D . The operations are done starting from the left. If the NaN is <i>not</i> encountered in A or B then the NaN effectively "resets" the chain of additions to 0, so the result of the additions is whatever appears after that point. However, if the NaN occurs in the initial operation A+B in either position, then the result is 0 for that operation so the addition is whatever appears after the A+B point.</p><pre class="language-matlab">>> nan + int8(1) + int8(-5) + int8(-3)
</pre><pre class="language-matlab">ans =
</pre><pre> -8</pre><p>Entire first operation is affected, giving 0 for the pair so int8(1) is not contributing anything and the result is what is to the right of it</p><pre class="language-matlab">>> int8(0) + nan + int8(1) + int8(-5) + int8(-3)
</pre><pre class="language-matlab">ans =
</pre><pre> -7</pre><p>The first operation is affected, giving 0 for the first pair, but this is effectively the same as the case where the nan is encountered further on, with the nan resetting the total to 0 where it is encountered.</p><p>The operation of nan on items that are of single or double precision is well defined: of those were single or double items instead of uint8 or int8, then the nan would have propagated and the result would nan. But I do not recall seeing the result of combining nan and the integer classes documented.</p><p>I can come up with an explanation based upon pairwise operations and left-to-right evaluation. I would not say that it is <i>wrong</i>, just that it is <i>unexpected</i> . I was convinced for a while that it must be doing the operations right to left, until I tested further and found that it was just apparently asymmetric.</p>Walter Robersonhttp://nl.mathworks.com/matlabcentral/profile/authors/434782-walter-robersontag:nl.mathworks.com,2005:Question/1299002014-05-16T16:06:34Z2015-08-31T15:39:44ZData labels above bars on grouped bar plot<p>I'm making a grouped bar plot (i.e., a bar plot with multiple bars in each category). I would like to add labels at the top of each bar to indicate its height. I was planning to just use the text function. However, bars within a given group all have the same x location (i.e get(h,'XData') is the same for all bar series). I'm not sure how to find the proper x location for each bar within a given group. Any ideas?</p><p>Thanks,
Justin</p><img src = "/matlabcentral/answers/uploaded_files/12893/Screen%20Shot%202014-05-16%20at%2011.57.36%20AM.png">Justin Solomonhttp://nl.mathworks.com/matlabcentral/profile/authors/2738269-justin-solomontag:nl.mathworks.com,2005:Question/2383782015-08-31T15:35:19Z2015-08-31T15:35:19Zconverting canalyzer data into engineering units and export to a logfile<p>Hello,</p><p>I am trying to figure out how to convert canalyzer data into engineering units or DTC's and exporting to logfiles. I am under the impression that this can be accomplished using a .dbc file but I don't know how to execute. Anyone with this expertise please help. Thanks.</p>Keith Dawkinshttp://nl.mathworks.com/matlabcentral/profile/authors/6658043-keith-dawkinstag:nl.mathworks.com,2005:Question/2380942015-08-30T21:59:43Z2015-08-31T15:32:31Zsubstitute every n elements of a vector<p>Hi, I have a vector lets say 24 elements (zeros), and I want to substitute a vector of ones (lets say in this example a vector of two ones) n times (lets say 4 times in this example) starting from an index of the original vector decided by me, examples:</p><p>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 (original vector)</p><p>1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 (here substituted 4 times a vector of 2 ones starting form index 1)</p><p>0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 (here substituted 4 times a vector of 2 ones starting form index 3)</p><p>Is it possible to do simply something like this (possibly without a for)? just having the vector and deciding how many times substitute it, and the index to start?
Thank you so much.</p>simone clochiattihttp://nl.mathworks.com/matlabcentral/profile/authors/5218391-simone-clochiattitag:nl.mathworks.com,2005:Question/2383682015-08-31T14:22:51Z2015-08-31T15:29:46ZBVP4C: The derivative function ODEFUN should return a column vector of length 10<p>Hello</p><p>I have to resolve an ODE with boundary conditions, so I had to use the function bvp4c.</p><pre class="language-matlab">xa=-c;
</pre><pre> xb=c;
solinit=bvpinit(linspace(xa,xb,20),[1 1 1 1 1 1 1 1 1 1]);
sol=bvp4c(@(x,g)bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9),@(ga,gb)bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2),solinit);
xint=linspace(xa,xb,100);
Sxint=deval(sol,xint);</pre><pre> function bc=bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2)
bc=[ga(9)-1 ga(3) ga(4)-(3*a/a1)*ga(10) ga(8)+ga(7)*sqrt(2)*(K(2,1))^(1/4)+ga(6)*(K(2,1))^(1/2)-(3*a/a2)*ga(10) ga(7)+ga(6)*sqrt(2)*(K(2,1))^(1/4)+ga(5)*(K(2,1))^(1/2)+(2*sqrt(3)*nu2*(1-(nu2)^2)^(-1/2))*a/a2 gb(9)+1 gb(7) gb(8)-(3*a/a2)*gb(10) gb(4)+gb(3)*sqrt(2)*(K(1,1))^(1/4)+gb(2)*(K(1,1))^(1/2)-(3*a/a1)*gb(10) gb(3)+gb(2)*sqrt(2)*(K(1,1))^(1/4)+gb(1)*(K(1,1))^(1/2)+(2*sqrt(3)*nu1*(1-(nu1)^2)^(-1/2))*a/a1];
end</pre><pre class="language-matlab">function dydx=bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9)
dydx=[g(2) g(3) g(4) (y1+y3*y9)*g(1)+(y3*B(1,1))*g(3)+GAMMA(1,2)*y3*y8*g(5)+(y3*B(2,1))*g(7)+(y2+y3*y7)*g(9)+y3*z-y2 g(6) g(7) g(8) (GAMMA(2,1)+y6*y9)*g(1)+(y6*B(1,1))*g(3)+(y4+y6*y8)*g(5)+(y6*B(2,1))*g(7)+(y5+y6*y7)*g(9)+y6*z+y5 g(10) y9*g(1)+B(1,1)*g(2)+y8*g(5)+B(2,1)*g(7)+y3*g(9)+z];
endfunction dydx=bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9)
dydx=[g(2) g(3) g(4) (y1+y3*y9)*g(1)+(y3*B(1,1))*g(3)+GAMMA(1,2)*y3*y8*g(5)+(y3*B(2,1))*g(7)+(y2+y3*y7)*g(9)+y3*z-y2 g(6) g(7) g(8) (GAMMA(2,1)+y6*y9)*g(1)+(y6*B(1,1))*g(3)+(y4+y6*y8)*g(5)+(y6*B(2,1))*g(7)+(y5+y6*y7)*g(9)+y6*z+y5 g(10) y9*g(1)+B(1,1)*g(2)+y8*g(5)+B(2,1)*g(7)+y3*g(9)+z];
end
</pre><p>But I get this errors:</p><pre class="language-matlab">Error using bvparguments (line 109)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The derivative function ODEFUN should return a column vector of length 10.
</pre><pre class="language-matlab">Error in bvp4c (line 130)
[n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
</pre><pre class="language-matlab">Error in LR (line 69)
sol=bvp4c(@(x,g)bvp4ode_g(x,g,GAMMA,B,z,y1,y2,y3,y4,y5,y6,y7,y8,y9),@(ga,gb)bvp4bc_g(ga,gb,a,a1,a2,K,nu1,nu2),solinit);
>>
</pre><p>Thanks for your help.</p>Nouhayla EL GHANIhttp://nl.mathworks.com/matlabcentral/profile/authors/6784500-nouhayla-el-ghanitag:nl.mathworks.com,2005:Question/2359432015-08-24T17:38:05Z2015-08-31T15:27:26ZHow we can get the pixel values of an object in an image in matlab??<p>how we can get the pixel values of red line from starting to end point and return its pixel values.</p><img src = "/matlabcentral/answers/uploaded_files/36135/pixelvalues.png">halima jamilhttp://nl.mathworks.com/matlabcentral/profile/authors/6768688-halima-jamiltag:nl.mathworks.com,2005:Question/2371942015-08-28T03:19:06Z2015-08-31T15:26:21Zhow to fill holes in binary image<p>I am new to matlab. I need to represent the image in skeleton form using imskull from morphological operations. I am failing to get the image in skeleton form. Pls help me.</p>Jlavanya 815http://nl.mathworks.com/matlabcentral/profile/authors/6290662-jlavanya-815tag:nl.mathworks.com,2005:Question/2370892015-08-27T18:19:26Z2015-08-31T15:22:57ZError while connecting to Oracle Database from Matlab (64 bit) and Windows (64 bit) using Microsoft Oracle ODBC Driver<p>Hi,
I have a Oracle database hosted on a remote machine. I am running 64-bit MATLAB version (2011b) on a 64-bit Windows 7 machine.</p><p>I want to connect to the Oracle database using Microsoft ODBC driver for Oracle.</p><p>I am trying to connect to the Oracle database using the following connection string</p><p>PROVIDER=MSDASQL;DRIVER={Microsoft ODBC for Oracle};SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=yyyy))(CONNECT_DATA=(SERVER=DEDICATED)(SID=zzzz)));UID='wwww';PWD='yyyy';</p><p>While trying to connect, I am getting the following error</p><p>Invoke Error, Dispatch Exception:</p><p>Source: Microsoft OLE DB Provider for ODBC Drivers</p><p>Description: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified</p><p>Could you please help me in resolving the error at the earliest.</p><p>The same code is running perfectly on 32-bit windows machine.</p><p>Thanks,</p><p>Satish</p>SatishBhttp://nl.mathworks.com/matlabcentral/profile/authors/2628808-satishbtag:nl.mathworks.com,2005:Question/2383152015-08-31T12:38:52Z2015-08-31T15:19:15Zconvert m file into simulink model<p>Hallo everyone!</p><p>I want to convert a m file into simulink model, which will be later connected with Digsilent Power Factory.I chose matlab funtion.</p><p>treeensmeble is a struct and I have already saved it as a mat file. It has two feild in treeensemble, I just use one "trees". I want to load it into the funtion. But there is an error:
Undefined function or variable 'treeensemble'.</p><p>The code is as below:</p><pre class="language-matlab">function [YTS]=rtenspred(XTSA)
</pre><pre class="language-matlab">coder.extrinsic('load')
</pre><pre class="language-matlab">load treeensemble
</pre><pre> verbose=0;
persistent XTS;
persistent tree;
XTS=XTSA;
Nts=size(XTS,1);
T=length(treeensemble.trees);</pre><pre> YTS=0;</pre><pre> for t=1:T
if (verbose)
fprintf('t=%d\n',t);
end
tree=treeensemble.trees(t);
YTS=YTS+tree.weight*rtpred();
end</pre>hong yanghttp://nl.mathworks.com/matlabcentral/profile/authors/6843803-hong-yangtag:nl.mathworks.com,2005:Question/2383712015-08-31T14:38:48Z2015-08-31T15:18:00ZError Starting Desktop (java.lang.NullPointerException)<p>I just installed Matlab_R2014a on OS X 10.10 and I'm getting the error below on startup. I've tried updating the java installed but the issue persists. In the installation I accepted every toolbox (as I don't know which ones we'll be heading).</p><img src = "/matlabcentral/answers/uploaded_files/36432/Screen%20Shot%202015-08-31%20at%2016.34.10.png">Zeerak Waseemhttp://nl.mathworks.com/matlabcentral/profile/authors/3964243-zeerak-waseemtag:nl.mathworks.com,2005:Question/2383352015-08-31T13:39:39Z2015-08-31T15:04:59ZCan anyone help me with this error please? '' In an assignment A(I) = B, the number of elements in B and I must be the same. Error in RunFib (line 21) JTime(j) = integral(f,0,t(1,j),'Waypoints',t)./ t(1,j); ''<p>My code is :</p><pre class="language-matlab">function RunFib
</pre><pre class="language-matlab">x0=[12 5];
</pre><pre class="language-matlab">b = 3 ;
</pre><pre class="language-matlab">tspan = 0 : 0.001 : 10 ;
</pre><pre class="language-matlab">t0 =tspan(1);
</pre><pre class="language-matlab">tf=tspan(length(tspan));
</pre><pre class="language-matlab">A=1/(tf-t0);
</pre><pre class="language-matlab">[t,x]=ode45(@Fib, tspan , x0 , [] , 3);
</pre><pre> a1 = ( 15*x(:,1) - 3.*x(:,1).*x(:,2) );
b1 = ( -5*x(:,2) + 0.5*x(:,1).*x(:,2) );</pre><pre> f = @(tspan) ( A.* (a1.* (a1 .* (15 - 3.*x(:,2)) + b1 .* (0.5 .* x(:,2)) ) + b1 .*
( a1 .* (-3 .* x(:,1)) + b1 .* (-5 + 0.5.* x(:,1)) ) ).^2 ./ (a1.^2 + b1.^2).^3 );</pre><pre> t= (0:0.5:10);
N = length(t);
JTime = zeros(1,N);
for j = 1:N
JTime(j) = integral(f,0,t(1,j),'Waypoints',t)./ t(1,j);
end </pre><pre class="language-matlab">figure(2)
semilogy(t,JTime,'r+-')
</pre><pre class="language-matlab">1;
</pre><pre class="language-matlab">function dx = Fib(t,x,b)
</pre><pre class="language-matlab">dx=zeros(2,1);
</pre><pre class="language-matlab">dx0 = 15 * x(1) - b * x(1).* x(2);
dx1 = -5 * x(2) + 0.5 * x(1).* x(2);
</pre><pre class="language-matlab">end
</pre>Avan Al-Saffarhttp://nl.mathworks.com/matlabcentral/profile/authors/5297065-avan-al-saffartag:nl.mathworks.com,2005:Question/2383402015-08-31T13:46:08Z2015-08-31T15:01:54Zfolks this code for transmitting "Hello" over matlab what is the wrong with it ?<pre class="language-matlab">tx_msg = 'Hello'; % message to transmit
SPB = 10; % bit time in samples per bit
% transmitter %
%------tx_bs=text2bitseq(tx_msg)-------
tx_bs = [];
for c = 1:length(tx_msg)
character = tx_msg(c); % get the next character from the msg
byte = char2byte(character); % find the 8-bit ASCII
tx_bs = [byte];
end
%------tx_bs=text2bitseq(tx_msg)-------
tx_wave = bitseq2waveform(tx_bs,SPB); % change bit sequence to a waveform
% The following command is needed so that we satisfy the communication protocol.
% We will study this later in the course.
tx_wave1 = satisfy_protocol(tx_wave,SPB);
% channel %
rx_wave = txrx(tx_wave1); % transmit waveform through channel
% receiver %
rx_bs = waveform2bitseq(rx_wave,SPB); % change waveform to bit sequence
rx_msg = bitseq2text(rx_bs); % change bit sequence to text message
diagram_lab01(tx_bs,tx_wave,rx_wave,rx_bs,SPB); % generate plots
display_lab01(tx_msg,rx_msg); % display text messages
</pre>AbdElrhman Rdwanhttp://nl.mathworks.com/matlabcentral/profile/authors/6842387-abdelrhman-rdwantag:nl.mathworks.com,2005:Question/2383112015-08-31T12:31:32Z2015-08-31T15:00:32Zhow can find altered pixels<p>Hi Dears
I have two images the first is the original while the second is the watermarked image. I altered some pixels in the watermarked image , then I extracted the watermark from the altered image and compared with the original wateremark using MSE , I couldnt find the exact altered pixels, also I want a way to calculate the values of False positive (FP), false negative (FN) and average of detection rate .
with many thanks</p>qasim mohammedhttp://nl.mathworks.com/matlabcentral/profile/authors/6843880-qasim-mohammedtag:nl.mathworks.com,2005:Question/2369782015-08-27T12:29:46Z2015-08-31T14:58:14ZGuide Object Browser Unused Objects<p>I have GUI developed over a period of time and is working fine. In the process I had introduced a few edit boxes and later removed them and deleted the respective callbacks, and creatFcns etc.. Everything is working smoothly now, however, when I look into Object Browser that still shows a number of those edit boxes which are no longer used nor there anywhere in the code. Can I get rid of them from Object Browser?</p>Pappu Murthyhttp://nl.mathworks.com/matlabcentral/profile/authors/705603-pappu-murthytag:nl.mathworks.com,2005:Question/2379382015-08-30T08:33:36Z2015-08-31T14:49:35ZImage segmentation of connected shapes problem<p>Hello,
Below is the code I used to segment the image however when there are are connected shapes (shown in the img) the code take it as one object. I want it to take it as separate object and get the centroid of each. Your help will be very much appreciated. Thank you.</p><pre class="language-matlab">A = imread('image.png');
figure, imshow(A);
title('Original Image');
B = im2bw(A);
B = ~B;
B = 1-B;
B = (B == 0);
figure, imshow(B);
title('Image Without Holes');
</pre><pre class="language-matlab">C=imfill(B,'holes');
figure,imshow(C);
title('Image With Holes');
</pre><pre class="language-matlab">label=bwlabel(B);
max(max(label))
im1=(label==1);
</pre><pre class="language-matlab">for j=1:max(max(label))
[row, col] = find(label==j);
len=max(row)-min(row)+2;
breadth=max(col)-min(col)+2;
target=uint8(zeros([len breadth]));
sy=min(col)-1;
sx=min(row)-1;
</pre><pre class="language-matlab">for i=1:size(row,1)
x=row(i,1)-sx;
y=col(i,1)-sy;
target(x,y)=A(row(i,1),col(i,1));
end
mytitle=strcat('Object Number:',num2str(j));
figure,imshow(target);title(mytitle);
end
</pre><p>Image</p><img src = "/matlabcentral/answers/uploaded_files/36374/c2.png"><p>Result: 2 Objects only should be 5 objects</p><img src = "/matlabcentral/answers/uploaded_files/36375/Screen%20Shot%202015-08-30%20at%204.31.54%20PM.png">Phantom.i7http://nl.mathworks.com/matlabcentral/profile/authors/5119759-phantom-i7