https://es.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-03-23T02:14:15Ztag:es.mathworks.com,2005:Question/3314192017-03-23T02:07:49Z2017-03-23T02:13:45ZI need help in plotting the data but I keep getting an error<p>I get the rolling when I run the code</p><p>Error using plot
Vectors must be the same length.</p><p>Error in untitled8 (line 80)
subplot(2,1,1),plot(t,position)</p>Brandon Phillipshttps://es.mathworks.com/matlabcentral/profile/authors/9582019-brandon-phillipstag:es.mathworks.com,2005:Question/3314212017-03-23T02:13:36Z2017-03-23T02:14:15ZHow to vectorize computing all pairwise vectors in a pointcloud?<p>I have an m points x n dimensions array <tt>xy</tt> of Cartesian coordinates. In my case, n is 2, but this should generalize to at least three dimensions. My goal is get the all the vectors created by combinatorial pairs of points. I can do this with nested for loops (see below), how can I vectorize this operation? I can get the vector magnitudes with <tt>pdist2(xy,xy)</tt>, but not the vector angles.</p><pre class="language-matlab">[m,n] = size(xy);
V = zeros(m,m,n);
for im1 = 1:m
for im2 = 1:m
V(im1,im2,:) = xy(im1,:) - xy(im2,:);
end
end
</pre>Burke Rosenhttps://es.mathworks.com/matlabcentral/profile/authors/9360644-burke-rosentag:es.mathworks.com,2005:Question/3314202017-03-23T02:11:39Z2017-03-23T02:11:39ZHow to install SeDuMi 1.3 on MATLAB R2014a with windows 7 64 bit<img src = "/matlabcentral/answers/uploaded_files/73130/%E6%88%AA%E5%9B%BE.jpg">zhang penghttps://es.mathworks.com/matlabcentral/profile/authors/5853801-zhang-pengtag:es.mathworks.com,2005:Question/3314082017-03-23T01:03:14Z2017-03-23T02:03:20ZHow to fprintf from multiple cells?<p>Let's say I was given a certain phrase, for example '%s likes to eat %s.' and I was given the same number of arrays as there is %s in the phrase. In the case, 2: Name={Peter, John, Aaron} and Fruit={kiwis, apples, bananas}. I need to create a function that takes in the phrase and the cell arrays corresponding to the %s's of the phrase (so basically a varargin) and does the fprintf of the cell contents as following:</p><p>Peter likes to eat kiwis.</p><p>John likes to eat apples.</p><p>Aaron likes to eat bananas.</p><p>So my function is:</p><pre class="language-matlab">function[ ]=myfprintf(message, varargin)
</pre><pre class="language-matlab">%First I search for number of %s in the phrase:
</pre><pre class="language-matlab">idx=ismember('%s',phrase);
number=length(find(idx));
</pre><pre class="language-matlab">%And then create the fprintf loop
</pre><pre> for j=1:size(varargin{1},2)</pre><pre> for i=1:number
fprintf(phrase,charac{i,j})
end
end
end</pre><p>but it doesn't show up like I need it to. How do I do that?</p>Dadahttps://es.mathworks.com/matlabcentral/profile/authors/8897801-dadatag:es.mathworks.com,2005:Question/3314172017-03-23T02:00:13Z2017-03-23T02:00:13ZHow do I write a code for the midpoint method of solving a system of ODEs?<p>Apply the midpoint method to approximately solve (⋆) over [0, 100] with
initial condition y(0) = (1, 0)T. To begin, the method needs a solution value at t1 = h
as well as at t0 = 0. Use the forward-Euler method to obtain this. Use step-sizes
h = .1, .01, and .001. Print out and hand in a table showing the step-sizes in the
first column and the maximum errors in the second column. (The exact solution is
y(t) = (cos(t), − sin(t))T.)</p>Samantha Cornwellhttps://es.mathworks.com/matlabcentral/profile/authors/9589308-samantha-cornwelltag:es.mathworks.com,2005:Question/3313822017-03-22T21:23:11Z2017-03-23T01:59:37ZSplit numerical double array to multiple columns?<p>Hey guys,</p><p>I'm sure there's a simple workaround for this but I can't seem to find it. I have data with the following format</p><pre> whos data
Name Size Bytes Class Attributes</pre><pre class="language-matlab">data 1095x9 78840 double
</pre><p>data(1:10, 1)</p><p>ans =</p><pre> 20090101
20090102
20090103
20090104
20090105
20090106
20090107
20090108
20090109
20090110</pre><p>It's currently in the format of yearmonthday, but I would like to pull them apart to look at year, month, day. How do I pull, for example, the first 4 numbers from a double array?</p>Katehttps://es.mathworks.com/matlabcentral/profile/authors/4341490-katetag:es.mathworks.com,2005:Question/3314162017-03-23T01:57:39Z2017-03-23T01:57:39Zhi i'm korean student. how to solve this problem? here's my error capture~!<p>hi i'm korean student. how to solve this problem? here's my error capture~!</p>1 1https://es.mathworks.com/matlabcentral/profile/authors/9986152-1-1tag:es.mathworks.com,2005:Question/3314152017-03-23T01:53:07Z2017-03-23T01:58:47ZI'm trying to solve a coupled ODE using ODE45. Now i want to run this solver on distribution of initial conditions & diff. equation constants without using a for loop around ODE<p>I'm trying to solve a coupled ODE using ODE45. I was successful in running the system. Now i want to run this solver on distribution of initial conditions (y0 in below example) & diff. equation constants (a,b,c in below example) without using a for loop around ODE call which is bad. Interest is to study system sensitivity to input variation and estimate system response sigma for given input parameters each with it's own sigma variation.</p><p>As i want to generate >3 sigma distribution i need to sample >1e3 values.
I want to avoid below method and get a better solution like send the full matrix of parameters samples from distribution at once without the for loop</p><p>%sample code
for i=1:10000
[t,y]=ode45(@(t,y) myfunc(t,y,a,b,c),tspan, yo, opts);
end</p><p>I found this old thread which seems to answer similar question which i need to try yet, also it's a pretty old response so was hoping we may new solutions shared.</p><p><a href = "http://www.mathworks.com/matlabcentral/newsreader/view_thread/22879">http://www.mathworks.com/matlabcentral/newsreader/view_thread/22879</a></p><p>Any help on this is really appreciated. Thanks.</p>Shanky Jainhttps://es.mathworks.com/matlabcentral/profile/authors/5768623-shanky-jaintag:es.mathworks.com,2005:Question/3314052017-03-23T00:42:54Z2017-03-23T01:52:03ZCan someone please help me know what's wrong with my code? because it doesn't show the right graph !<p>that's what i have done on Matlab, but I can't get the right graph for the question.</p><p>first I created a function :</p><pre class="language-matlab">function [y]=discontinuity(x,a,n,c)
s=length(a);
y=zeros(s,1);
for i=1:s
if x(i)>=a
y(i)=((x(i)-a)^n)/c;
else
y(i)=0;
end
end
end
</pre><p>Then, I created a script</p><pre class="language-matlab">x=0:0.5:360;
y=zeros(length(x),1);
for i=1:length(x)
y(i)= -((100/24)*x(i))^4+(8500/6)*x(i)^3-27.30e6*x(i)+(100/24)*discontinuity(x(i),120,4,29e6*110)-(2000/6)*discontinuity(x(i),180,3,29e6*110)+(9500/6)*discontinuity(x(i),240,3,29e6*110)-(4000/6)*discontinuity(x(i),300,3,29e6*110);
end
plot(x,y)
grid on
xlabel('distance in inches')
ylabel('deflection in inches')
</pre>Rehab Mohamed`https://es.mathworks.com/matlabcentral/profile/authors/9497783-rehab-mohamedtag:es.mathworks.com,2005:Question/3314142017-03-23T01:46:23Z2017-03-23T01:46:23ZHow to enable variable autocomplete in function calling?<p>In old version of MATLAB, automatic tab completion worked.</p><p>Now, autocompletion of MATLAB R2017a(academic) not work when type with function.</p><img src = "/matlabcentral/answers/uploaded_files/73125/Screen%20Shot%202017-03-23%20at%2010.43.27%20AM.png"><p>how can I fix this problem?</p><p>thanks.</p>Jinwoo Honghttps://es.mathworks.com/matlabcentral/profile/authors/9761519-jinwoo-hongtag:es.mathworks.com,2005:Question/3314112017-03-23T01:20:29Z2017-03-23T01:44:25ZStruct contents reference from a non-struct array object.<p>Struct DATA_VICON is a 1x1 Struct with 5 fields that are 3x8685 doubles</p><p>The following code returns the error:</p><p>x = DATA_VICON.rate(3,:);
plot(x)</p><p>(rate is one of the arrays in the struct)</p><p>But when I try the code in the command line it actually works! If you have any idea what I need to do differently please let me know.</p>Lindsey Marinellohttps://es.mathworks.com/matlabcentral/profile/authors/6642866-lindsey-marinellotag:es.mathworks.com,2005:Question/3311772017-03-22T02:34:55Z2017-03-23T01:42:46Zextracting 2-d plot from 3d plot <p>Hi,</p><p>I have x,y,z plot by using scatter3 function. I would like to see a 2-d plot such as x vs z or y vs z.
What is the function that I can use to this?</p><p>Thanks</p>Mike Leehttps://es.mathworks.com/matlabcentral/profile/authors/5106932-mike-leetag:es.mathworks.com,2005:Question/3314132017-03-23T01:42:19Z2017-03-23T01:42:19Zi an anfis what is the reason that epoch error dose not decreases? my case is in output in linear and input mf s are triangular and optimization in hybrid<p>i an anfis what is the reason that epoch error dose not decreases? my case is in output in linear and input mf s are triangular and optimization in hybrid</p>monideepahttps://es.mathworks.com/matlabcentral/profile/authors/7024194-monideepatag:es.mathworks.com,2005:Question/3314122017-03-23T01:41:58Z2017-03-23T01:47:50ZHow can I vectorize this code to decrease computation time?<p>I have created a script that takes two instances of a DICOM structure (e.g. the same tumor at two different points in time) and rotates one instance of the structure about the other instance's center of mass, for the three rotation planes, in an effort to find the x,y, and z axis rotation that leads to the maximum overlap between the two structures.</p><p>At this stage the user defines the max rotational search limit and the step size. The max rotational search limit includes negative and positive degrees of rotation. So, for a rotation of 5 degrees with 1 degree step size, as defined by user input there are 1331 possible combinations of rotations:</p><p>x = -5 -4 -3 -2 -1 0 1 2 3 4 5</p><p>y = -5 -4 -3 -2 -1 0 1 2 3 4 5</p><p>z = -5 -4 -3 -2 -1 0 1 2 3 4 5</p><p>The problem is, as the user selects higher max rotation limits my code slows severely. I anticipate that I could rewrite some of the for-loops using vectorization, however I am having significant difficulty and any help would be greatly appreciated. The code/pseudocode looks like this:</p><pre class="language-matlab">for x_theta = -MAX_ROT : STP_SZ : MAX_ROT
for y_theta = -MAX_ROT : STP_SZ : MAX_ROT
for z_theta = -MAX_ROT : STP_SZ : MAX_ROT
R = makehgtform('xrotate', x_theta, 'yrotate', y_theta, 'zrotate', z_theta);
R = R(1:3, 1:3);
</pre><pre> for j = 1:1:length(array containing points of each slice)
s = points on slice j - center of mass point; % Subtract center of mass from points so we can rotate about the center of mass
rotatedPoints{:, j} = (R * s); % Multiply points by rotation matrix
rotatedPoints{:, j} = rotatedPoints{:, j} + center of mass point; % Add center of mass back to points
end</pre><pre> MASK = false(dimensions of 3D image volume);</pre><pre> for k = 1 : 1 : length(rotatedPoints)</pre><pre> slice = interp1(SCNINFO.start(3):SCNINFO.width(3):...
SCNINFO.start(3) + (SCNINFO.dimensions(3) - 1) ...
* SCNINFO.width(3), 1:SCNINFO.dimensions(3), ...
-rotatedPoints{1, k}(1, 3), interpolator, 0);</pre><pre> if slice ~= 0</pre><pre> mask = poly2mask((Rotatedpoints_temp{1, k}(:,2) + (SCNINFO.width(2) * ...
(SCNINFO.dimensions(2) - 1) + ...
SCNINFO.start(2)) + SCNINFO.width(2)/2) / ...
SCNINFO.width(2) + 1, ...
(Rotatedpoints_temp{1, k}(:,1) + SCNINFO.width(1)/2 - ...
SCNINFO.start(1)) / SCNINFO.width(1) + 1, ...
SCNINFO.dimensions(1), ...
SCNINFO.dimensions(2));
end</pre><pre> % If the new mask will overlap an existing value,
% subtract
if max(max(mask + MASK(:,:,slice))) == 2
MASK(:,:,slice) = ...
MASK(:,:,slice) - mask;</pre><pre> % Otherwise, add it to the mask
else
MASK(:,:,slice) = ...
MASK(:,:,slice) + mask;
end
end</pre><pre class="language-matlab">overlapImage = reference structure mask & MASK;
numOverlapPixels = nnz(overlapImage);
rotatedResults = 2 * numOverlapPixels / (volume reference structure + volume structure);
end
end
end
</pre><p>After running with the MATLAB profiler most time is consumed during the poly2mask. This is because I am making a binary mask from every slice of points for every rotation combination!</p>Loweyhttps://es.mathworks.com/matlabcentral/profile/authors/6290178-loweytag:es.mathworks.com,2005:Question/3312562017-03-22T11:34:14Z2017-03-23T01:40:48ZJoin 2 tables with different values in the key variable<p>I would like to join the tables:</p><pre class="language-matlab">A = 6 x 1 table B = 4 x 2 table
Var 1 Var 1 Var 2
930 930 10
931 935 3
932 938 5
935 940 7
936
939
</pre><p>The key variable (Var 1) do not have exactly the same values in Table A and B. I would like to join using the following rule:</p><p>Rule: For each value of Var 1 in Table A, find the value of Var 1 in Table 2 that is the MINIMUM and GREATER THAN OR EQUAL TO the value in Table A. Then join the corresponding row of Var 2 from Table B to Table A.</p><p>e.g. for 930, the minimum which is greater than or equal to 930 in Table B is 930, so 10 is joined to Table A.</p><p>for 931, the minimum which is greater than or equal to 931 in Table B is 935, so 3 is joined to Table A.</p><p>for 932, the minimum which is greater than or equal to 932 in Table B is 935, so 3 is joined to Table A.</p><p>for 935, the minimum which is greater than or equal to 935 in Table B is 935, so 3 is joined to Table A.</p><p>for 936, the minimum which is greater than or equal to 936 in Table B is 938, so 5 is joined to Table A.</p><p>for 939, the minimum which is greater than or equal to 939 in Table B is 940, so 7 is joined to Table A.</p><p>So the resulting Table A I want would be:</p><pre class="language-matlab">A = 6 x 2 table
Var 1 Var 2
930 10
931 3
932 3
935 3
936 5
939 7
</pre><p>The outer join would not work for me because I cannot have NaN. What would be a good way to achieve this?</p><p>Not sure the text formatting here is clear so I attach a pdf for easy reading.</p>Jonathan Chanhttps://es.mathworks.com/matlabcentral/profile/authors/6878345-jonathan-chantag:es.mathworks.com,2005:Question/3307402017-03-19T23:10:28Z2017-03-23T01:29:16ZFinding roots of differential equations<p>How can I find the roots/zeros of a differential equation such as</p><img src = "/matlabcentral/answers/uploaded_files/72793/Capture.PNG">stevesy55https://es.mathworks.com/matlabcentral/profile/authors/9795455-stevesy55tag:es.mathworks.com,2005:Question/3311352017-03-21T19:40:18Z2017-03-23T01:27:31Zerror 2059 compiler matlab<p>I'm attempting to run a code through matlab on Windows 10 which was previously run on windows XP. Currently running MATLAB 2015a (64-bit) with Windows 7.1 SDK as the compiler.</p>Jack Chttps://es.mathworks.com/matlabcentral/profile/authors/7101214-jack-ctag:es.mathworks.com,2005:Question/3313652017-03-22T19:42:39Z2017-03-23T01:20:12ZHow can I use integral function this way?<pre class="language-matlab">function [mat_uni] = mat_unif(i,j,k,s,ro,h_b,x_b1,x_b2)
</pre><pre class="language-matlab">fi_jk = 2./sqrt(3).*pi.^(-1./4).*2.^(j./2).*(1-(2.^j.*x-k).^2).*exp(-(2.^j.*x-k).^2./2);
</pre><pre class="language-matlab">fi_is = 2./sqrt(3).*pi.^(-1./4).*2.^(i./2).*(1-(2.^i.*x-s).^2).*exp(-(2.^i.*x-s).^2./2);
</pre><pre class="language-matlab">mat_uni_der = @(x) 2.*ro.*h_b.*fi_jk.*fi_is;
</pre><pre class="language-matlab">mat_uni = integral(mat_uni_der, x_b1, x_b2);
</pre><pre class="language-matlab">end
</pre><p>The problems when integrating this function come from calling fi_jk and fi_is functions, since matlab does not recognize x as a variable that will later be used by integral().</p><p>If I delete the 'x' as an input, I am told that there are not enough input arguments. I have tried to define x using 'syms x', but other errors appeared: 'Input function must return 'double' or 'single' values. Found 'sym''.</p><p>Could it be useful to use the function handle? If so, how to use it?</p><p>Also, I would like to know what "opstruct" is used for.</p><p>Thank you very much for the possible answers.</p>Aparicio Nietohttps://es.mathworks.com/matlabcentral/profile/authors/6287661-aparicio-nietotag:es.mathworks.com,2005:Question/3314102017-03-23T01:11:59Z2017-03-23T01:16:11ZHow can I plot a phase portrait of x' vs x<p>I am conducting a project on friction looking at the stick/slip phenomena in a similar system to that linked below.</p><img src = "https://www.researchgate.net/profile/Alain_Le_Bot/publication/267489313/figure/fig1/AS:295626962161675@1447494369005/Figure-1-THE-FRICTION-INDUCED-VIBRATION-MASS-SPRING-OS-CILLATOR-UNDER-STUDY.png"><p>I have written the code in order to plot the state space (x against x') given some initial conditions for position and velocity. I would now like to plot a phase portrait to show the general direction of motion in a similar fashion to the one linked below.</p><img src = "http://dynamicsystems.asmedigitalcollection.asme.org/data/journals/jdsmaa/26273/008004j.2.jpeg"><p>However all of the help I have found online does not explain how to do this when one axis is just the derivative of the other.</p><p>The general pattern of behaviour is two ellipses that have centres at +-d/w^2 on the x axis where d=mu*g and w^2 = k/m where k is the spring stiffnes, mu is the kinetic coefficient of friction, g is gravity, and m is mass. The RHS ellipse only exists below the line x'=v where v is the constant belt velocity and the LHS ellipse only exists above this line.</p><p>I would like to have arrows showing what will happen to the values throughout the state space for some decided parameters.</p><p>Below is the code I made to calculate the x and x' values, if you run it with</p><pre> X = Coulomb3([-2 4], 6, 0.005, 10, 2, 1, 0.3);</pre><p>then you should get an idea of where the ellipses are placed.</p><pre class="language-matlab">function [X] = Coulomb3(Init, Tf, tstep, k, m, v, mu)
</pre><pre class="language-matlab">dmu = mu;
smu = 1.3*mu;
</pre><pre class="language-matlab">g = 9.81;
</pre><pre class="language-matlab">w = sqrt(k/m);
c = smu*m*g/k;
d = dmu*g;
</pre><pre class="language-matlab">tol = 0.05;
</pre><pre class="language-matlab">X(1, 1) = Init(1);
X(1, 2) = Init(2);
</pre><pre class="language-matlab">while length(X) <= Tf/tstep
sc = 1;
if X(end, 2) < v - tol || (abs(X(end, 2) - v) < tol && X(end, 1) >= c)
A = X(end, 2)/w;
if A<0; sc=-1; end
B = X(end, 1) - d/w^2;
R = sqrt(A^2 + B^2);
phi = atan(B/A);
for t = 1:Tf/tstep
if sc*cos(w*t*tstep + phi) > v/(R*w)
T = t; %finding where the line first touches the x'=v line
break;
end
T = Tf/tstep;
end
for t = 1:T
X(end+1, :) = [sc*R*sin(w*t*tstep + phi) + d/w^2 sc*R*w*cos(w*t*tstep + phi)];
end
end
</pre><pre> if abs(X(end, 2) - v) < tol && abs(X(end, 1)) < c
for t = 1:Tf/tstep
if X(end, 1) + t*tstep*v > c
T = t; %finding where the x'=v line runs out (at c)
break;
end
T = Tf/tstep;
end
for t = 1:T
X(end+1, :) = [(X(end, 1) + tstep*v) v];
end
end</pre><pre> if X(end, 2) > v + tol || (abs(X(end, 2) - v) < tol && X(end, 1) <= -c)
A = X(end, 2)/w;
B = X(end, 1) + d/w^2;
R = sqrt(A^2 + B^2);
phi = atan(B/A);
for t = 1:Tf/tstep
if cos(w*t*tstep + phi) < v/(R*w)
T = t; %finding where the line first touches the x'=v line
break;
end
T = Tf/tstep;
end
for t = 1:T
X(end+1, :) = [R*sin(w*t*tstep + phi) - d/w^2 R*w*cos(w*t*tstep + phi)];
end
end
end
end</pre><p>Any help is greatly appreciated as I would like to have this last figure to conclude my project.</p><p>Thanks</p>Liam Wheenhttps://es.mathworks.com/matlabcentral/profile/authors/8831537-liam-wheentag:es.mathworks.com,2005:Question/3314092017-03-23T01:10:15Z2017-03-23T01:10:15ZIam doing a project in image processing which is light spot tracking for automatic headlight control in cars.. which algorithm can i use?<p>how can i track the headlight of the oncoming car and differentiate between wether it is high beam or low beam?</p>sunil Jakharhttps://es.mathworks.com/matlabcentral/profile/authors/10000574-sunil-jakhartag:es.mathworks.com,2005:Question/3313782017-03-22T20:48:12Z2017-03-23T01:08:31ZHow to analyze part of a signal?<p>Hello, I have created a sinusoidal signal, but I only want to find a peak value between 'x' to 'y' seconds of the signal. How would I set a limit so that only the data of the sinusoidal signal is analyzed in MATLAB between 'x' to 'y' seconds?</p><p>I have tried to use the function "xlim", but I think that is only for setting limits on a graph.</p><p>I hope this is not to broad of a question, but any help would be greatly appreciated.</p>Anonymous45https://es.mathworks.com/matlabcentral/profile/authors/9945585-anonymous45tag:es.mathworks.com,2005:Question/3314072017-03-23T00:55:28Z2017-03-23T00:55:28ZWhy isn't my circuit generating any output? [Simulink]<p>I created a digital circuit for the following boolean expression: W=X(X+Z)+XY. However, the simulation isn't providing me with any output, is there anything wrong with the way I have constructed it?</p>Jacob John 16BCE2205https://es.mathworks.com/matlabcentral/profile/authors/9818835-jacob-john-16bce2205tag:es.mathworks.com,2005:Question/3311072017-03-21T16:57:55Z2017-03-23T00:45:40ZHow can I solve a matrix differential equation within MATLAB?<p>I am interested in solving an ODE dF/dt=F*A, where <b>both</b> A and F are matrices (in particular, 5x5 matrices).
I have used ode45 and dsolve before for problems like dx/dt=A*x, where x is a vector but not a matrix like in this case.</p>Eduhttps://es.mathworks.com/matlabcentral/profile/authors/9989456-edutag:es.mathworks.com,2005:Question/3314062017-03-23T00:44:33Z2017-03-23T00:46:22ZHow to change the random distribution to Weibull distribution?<p>My supervisor wants me to use the scripts he provided and change the random distribution of the cracks to Weibull or Gaussian distribution. I have tried to fit in the method described in mathworks for Weibull distribution but I do not see any changes on the results since I was just inputing the codes. I have attached the scripts for the calculation of crack density where the cracks are distributed randomly.</p>Aukhat Uaphttps://es.mathworks.com/matlabcentral/profile/authors/6127546-aukhat-uaptag:es.mathworks.com,2005:Question/3066922016-10-10T23:51:50Z2017-03-23T00:43:32ZSetting loadLibrary compiler option to C++11<p>I am trying to use a toolbox (specifically, the Intan RHD2000 MATLAB toolbox) in MATLAB R2016a which uses the loadLibrary function to load from a C++ header file. However, I get the error written below.</p><p>It's been suggested that this is a C++ version issue, and that none of my compilers (I've tried MinGW64 and the Windows SDK 7.1) will default to reading what appears to be syntax from C++11. It was suggested that I set the compiler options to C++11, like in <a href = "https://www.mathworks.com/matlabcentral/answers/290173-how-to-enable-compiler-options-for-iso-c-2011-standard-in-matlab-r2016a">this answer</a>. However, this suggestion uses mex directly to compile a .c file. Is there a way I can set this option when calling loadLibrary?</p><p>As you can tell, I'm very unfamiliar with C++ and mex, so I appreciate your help!</p><p>Full error text</p><pre class="language-matlab">Warning: Message from C preprocessor:
C:\Program Files\MATLAB\R2016a\toolbox\local\rhd2000 matlab toolbox\+rhd2000\RHD2000Toolbox.h:10:9:
warning: #pragma once in main file
#pragma once
^
</pre><pre class="language-matlab">> In loadlibrary
In rhd2000.Driver (line 36)
Warning: Warnings messages were produced while parsing. Check the functions you intend to use for
correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary
In rhd2000.Driver (line 36)
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) Close ( BOARDREF boardRef' original input '( __cdecl__ )) Close ( BOARDREF boardRef '
Found on line 24 of input from line 28 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) Configure16DigitalOutputs ( BOARDREF boardRef' original input '( __cdecl__ )) Configure16DigitalOutputs ( BOARDREF boardRef '
Found on line 29 of input from line 33 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) EndImpedanceMeasurement ( BOARDREF boardRef' original input '( __cdecl__ )) EndImpedanceMeasurement ( BOARDREF boardRef '
Found on line 79 of input from line 83 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) Stop ( BOARDREF boardRef' original input '( __cdecl__ )) Stop ( BOARDREF boardRef '
Found on line 89 of input from line 93 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) RunContinuously ( BOARDREF boardRef' original input '( __cdecl__ )) RunContinuously ( BOARDREF boardRef '
Found on line 91 of input from line 95 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) Flush ( BOARDREF boardRef' original input '( __cdecl__ )) Flush ( BOARDREF boardRef '
Found on line 93 of input from line 97 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) ResetBoard ( BOARDREF boardRef' original input '( __cdecl__ )) ResetBoard ( BOARDREF boardRef '
Found on line 94 of input from line 98 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) FreeDataBlock ( DATABLOCKREF datablockRef' original input '( __cdecl__ )) FreeDataBlock ( DATABLOCKREF datablockRef '
Found on line 102 of input from line 106 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) DiscoverBoards1 ( int * numChars' original input '( __cdecl__ )) DiscoverBoards1 ( int * numChars '
Found on line 141 of input from line 145 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) SelfTest ( BOARDREF boardRef' original input '( __cdecl__ )) SelfTest ( BOARDREF boardRef '
Found on line 145 of input from line 149 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) Reset (' original input '( __cdecl__ )) Reset ('
Found on line 146 of input from line 150 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) MeasureAllImpedances ( BOARDREF boardRef' original input '( __cdecl__ )) MeasureAllImpedances ( BOARDREF boardRef '
Found on line 147 of input from line 151 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
</pre><pre class="language-matlab">Failed to parse type '( __cdecl__ )) CloseSaveFile ( BOARDREF boardRef' original input '( __cdecl__ )) CloseSaveFile ( BOARDREF boardRef '
Found on line 159 of input from line 163 of file C:\\Program Files\\MATLAB\\R2016a\\toolbox\\local\\rhd2000 matlab toolbox\\+rhd2000\\RHD2000Toolbox.h
Error parsing argument for function __attribute__ function may be invalid.
*********
Error using loadlibrary
Building RHD2000m_thunk_pcwin64 failed. Compiler output is:
C:\MATLAB\SupportPackages\R2016a\MW_MinGW_4_9\bin\gcc -I"C:\Program
Files\MATLAB\R2016a\extern\include" -fexceptions -fno-omit-frame-pointer
-I"C:\Users\Gittis\Documents\MATLAB" -I"C:\Program Files\MATLAB\R2016a\toolbox\local\rhd2000 matlab
toolbox\+rhd2000" "RHD2000m_thunk_pcwin64.c" -o "RHD2000m_thunk_pcwin64.dll" -shared
RHD2000m_thunk_pcwin64.c:33:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))Close(BOARDREFboardRefThunk(void fcn(),const char
*callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:42:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))Configure16DigitalOutputs(BOARDREFboardRefThunk(void
fcn(),const char *callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:51:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))EndImpedanceMeasurement(BOARDREFboardRefThunk(void fcn(),const
char *callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:60:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))Stop(BOARDREFboardRefThunk(void fcn(),const char *callstack,int
stacksize)
^
RHD2000m_thunk_pcwin64.c:69:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))RunContinuously(BOARDREFboardRefThunk(void fcn(),const char
*callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:78:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))Flush(BOARDREFboardRefThunk(void fcn(),const char
*callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:87:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))ResetBoard(BOARDREFboardRefThunk(void fcn(),const char
*callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:96:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))FreeDataBlock(DATABLOCKREFdatablockRefThunk(void fcn(),const
char *callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:105:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))DiscoverBoards1(int*numCharsThunk(void fcn(),const char
*callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:114:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))SelfTest(BOARDREFboardRefThunk(void fcn(),const char
*callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:123:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))Reset(Thunk(void fcn(),const char *callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:132:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))MeasureAllImpedances(BOARDREFboardRefThunk(void fcn(),const
char *callstack,int stacksize)
^
RHD2000m_thunk_pcwin64.c:141:37: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')'
token
EXPORT_EXTERN_C long long(__cdecl__))CloseSaveFile(BOARDREFboardRefThunk(void fcn(),const char
*callstack,int stacksize)
^
</pre><pre class="language-matlab">Error in rhd2000.Driver (line 36)
loadlibrary(dll, '+rhd2000\RHD2000Toolbox.h', 'alias', 'RHD2000m');
</pre>Timhttps://es.mathworks.com/matlabcentral/profile/authors/7557420-timtag:es.mathworks.com,2005:Question/3314042017-03-23T00:36:02Z2017-03-23T00:36:02ZJava Heap Space Memory Matlab2009b Windows<p>I keep getting the same error in Matlab2009b about a lack of memory. The specific error message is: Java Heap space memory error. How can I allocate more memory in Matlab?</p>Louise Stolzhttps://es.mathworks.com/matlabcentral/profile/authors/7745849-louise-stolztag:es.mathworks.com,2005:Question/3314032017-03-23T00:35:45Z2017-03-23T00:35:45Zis map.Container included in a matlab trial?<p>is map.Container included in a matlab trial?</p>math manhttps://es.mathworks.com/matlabcentral/profile/authors/9749459-math-mantag:es.mathworks.com,2005:Question/3311512017-03-21T21:56:56Z2017-03-23T00:34:20Zode45 will not run in appdesigner. Any ideas?<p>[t , Y] = ode45(@(t , Y) eom(t, Y, k, CD, CL, g), trange, init);</p><p>methods (Access = private)</p><pre> function f = eom(app, t , Y, k, CD, CL, g)
f(1,1) = Y(2);
f(2,1) = -k * sqrt(Y(2)^2 + Y(4)^2 ) * (CD * Y(2) - CL * Y(4));
f(3,1) = Y(4);
f(4,1) = -k * sqrt(Y(2)^2 + Y(4)^2 ) * (CL * Y(2) + CD * Y(4))- g;
end
end </pre>Jerry Resslerhttps://es.mathworks.com/matlabcentral/profile/authors/3115636-jerry-resslertag:es.mathworks.com,2005:Question/3313052017-03-22T15:20:26Z2017-03-23T00:32:08ZHow to generate a cylinder defined by the profile function 2((sint)^3)?<p>I'm not able to find the appropriate command to plot the cylinder. Please help.
Thanks in advance</p>Aneesh Raohttps://es.mathworks.com/matlabcentral/profile/authors/9024899-aneesh-raotag:es.mathworks.com,2005:Question/3314022017-03-23T00:25:26Z2017-03-23T00:29:02ZWriting output of loop to new file<p>I am trying to create a loop that will run through a set of files in a directory and calculate mean and variance from each (I have commands for this) then save the output of each in a csv file along with labels</p><p>e.g. file1 mean variance
file2 mean variance</p><p>Or ideally each file has the same name but I would like to print only an identifier from each "AB" or "CD"</p>kmriehttps://es.mathworks.com/matlabcentral/profile/authors/9797288-kmrietag:es.mathworks.com,2005:Question/3314012017-03-23T00:12:33Z2017-03-23T00:12:33ZPublish a plot with Tools menu specifications<p>I'm trying to use a linear fit with a my data plot, but when I publish it only plots the data points.</p><p>Is there some code that does the same thing as the Tools menu?</p>Michael Hookshttps://es.mathworks.com/matlabcentral/profile/authors/10000355-michael-hookstag:es.mathworks.com,2005:Question/3314002017-03-23T00:12:07Z2017-03-23T00:12:07ZHow to compare similarity between two binary images in matlab, please? I need to find the percentage of similarity. Thanks.<p>How to compare similarity between two binary images in matlab, please? I need to find the percentage of similarity. Thanks.</p>Ahmad Yahyahttps://es.mathworks.com/matlabcentral/profile/authors/8984285-ahmad-yahyatag:es.mathworks.com,2005:Question/3313992017-03-23T00:06:24Z2017-03-23T00:06:24ZRun 13 binary masks from 13 different grayscale images simultaneously.<p>I am trying to create 13 binary masks of grayscale images. I have the code to do so and it works. However, can I get all 13 to run at the same time, or will this present problems with the code?</p>Kaitlyn Kirklandhttps://es.mathworks.com/matlabcentral/profile/authors/6056698-kaitlyn-kirklandtag:es.mathworks.com,2005:Question/3313982017-03-22T23:58:54Z2017-03-22T23:58:54ZImage processing for CT scan of violin<p>I'm a violin maker and was recently involved in an effort to CT scan a fine old Italian violin to understand better the condition of this violin. The scanning was successful and I now have thousands of .jpg image files in the x, y and z axes. Initially, the images were imported into OsiriX in order to obtain a 3D model.</p><p>There are additional analyses that I would like to perform on these image slices in order to isolate and visualize plate densities, plate arching elevation profiles, and plate thicknesses.
Work like this has been done before on violins and I believe Matlab was utilized. Results have been published in violin journals.</p><p>My experience with Matlab is small, but I'm working hard to learn it. I've been a violin for the last 18 years, I had programming experience in my past life - mostly in c (and Fortran).
I've attached 3 representative image files of the violin that was scanned so you can see what I'm working with.
I've also attached sample images of what I'm trying to achieve - which are, specifically, a plate (top/back) density map, a plate arching elevation profile, and a plate thickness map.</p><p>According to an article in a violin journal that discusses their analyses, an algorithm was devised "that effectively sends a virtual "spider" to delineate the boundaries of wood and air of an instrument and can therefore define an individual plate, Figure 3 (attached) shows the separation of the outside of the plate and air (superior delineation point [SDP]), the inside of the plate and air (inferior delineation point [IDP]), and a third point, which is halfway between the two (medial point [MP]). Using a mixture of each of these, data can be extracted and presented in a way that shows clearly several important "views" of an instrument. Using just the SDP gives elevation maps; using SDP and IDP gives thickness maps; using MP gives median density, etc".
So I think I can understand what the author is describing, but I'm trying to understand how to translate this into Matlab. I've come across functions in Matlab having to do with edge detection, and I think this must have been used to define the plate boundaries, but I'm unclear as to how to put all the slices back together after their edges have been defined.</p><p>This is probably a very large effort so I'm just hoping to get some thoughts that would help narrow my focus.</p><p>Thanks in advance</p>Michael Reishttps://es.mathworks.com/matlabcentral/profile/authors/9965180-michael-reistag:es.mathworks.com,2005:Question/3313772017-03-22T20:47:15Z2017-03-22T23:52:58ZHow do I cut down the size of an array of data?<p>I have a few arrays, with one column each, of different sizes (200127, 200126, 200120, etc.) In order to preform the calculations I want to do, I need them to all be the same length. Is there a way to cut them all down to the smallest array I have?</p>Bennett Torrancehttps://es.mathworks.com/matlabcentral/profile/authors/9587677-bennett-torrancetag:es.mathworks.com,2005:Question/3313972017-03-22T23:46:10Z2017-03-22T23:49:10Zhow to read strings with multiple null (\0) terminators when using calllib functions<p>Hi everyone,</p><p>I've got a problem reading data from a device using external C dlls and calllib function.</p><p>The header file for the reading method is something as below:</p><pre class="language-matlab">int ws_read_configdata ( const char * name , char * buffer , int buffersize , int * nread );
% fcns.name{fcnNum}='ws_read_configdata'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'cstring', 'cstring', 'int32', 'int32Ptr'};fcnNum=fcnNum+1;
</pre><p>The matlab code I used to retrieve the data from the device is like:</p><pre class="language-matlab">bufsize = 10000000;
bufread = 0;
buf = blanks(bufsize);
[rc, a, b, c] = calllib(libname, 'ws_read_configdata', wsname, bufptr, bufsize, 0);
</pre><p>which returns me in variable b, only the first eight CHARS ['37CB39A6']. <b>The remaining of the data is unreachable.</b>
The other returned values are shown below</p><pre class="language-matlab">rc = 0; % error check code, 0 = success
a = 58113; % serial number of device
b = '37CB39A6'; % returned data, WRONG! ONLY FIRST EIGHT CHARS
d = 6061152; % bytes that have been read
</pre><p>when I tried to use libpointers like:</p><pre class="language-matlab">bufsize = 10000000;
bufread = libpointer('int32Ptr', bufsize);
buf = blanks(bufsize);
bufptr = libpointer('string', buf);
[rc, a, bufptr.value, c] = calllib(libname, 'ws_read_configdata', wsname, bufptr, bufsize, bufread);
</pre><p>the problem remains the same.</p><pre class="language-matlab">rc = 0;
a = 58113;
bufptr.value = '37CB39A6';
c = 6061152;
</pre><p>yet now</p><pre class="language-matlab">bufread.value = 6061152
</pre><p>The content retrieved data <b>by other methods (using executable file)</b> is like</p><img src = "/matlabcentral/answers/uploaded_files/73115/Untitled.png"><p>that is to say, the there are \0 characters in the data.</p><p>Any ideas how can I deal with this issue?</p><p>Thanks</p><p>Deming</p>Deming Konghttps://es.mathworks.com/matlabcentral/profile/authors/9874969-deming-kongtag:es.mathworks.com,2005:Question/3313962017-03-22T23:45:29Z2017-03-22T23:45:29ZMotion Tracking pixel coordinates <p>I am testing for strain in a really thin smart material, but I would like to solve for strain by finding the change in position or size from 2 or more images imported into MATLAB.
So, I am trying to create a program that will take in at least 2 pictures. In these two pictures there will be several white dots on a black surface. I am trying to calculate the euclidean distances the white dots travel between the two pictures. From there I can calculate strain, but I do not know how to calculate the distances traveled.</p><p>I am looking to see if anyone has any pointers on how to start this. I have attached what I have so far (not very much) but I am unsure of what the next step is.</p>Richard Owenhttps://es.mathworks.com/matlabcentral/profile/authors/7108294-richard-owentag:es.mathworks.com,2005:Question/3313912017-03-22T22:45:59Z2017-03-22T23:42:06ZCan't launch webwindow content on Linux (CentOS 7)<p>I can't launch any part of matlab which uses "webwindow" functionality. Other windows open up and render properly (Simulink, Matlab windows for example, function as normal).</p><p>I am connecting to this machine over an SSH X tunnel, so this may have something to do with it. (I do have physical access to the machine if needed).</p><p>The issue appears to be just "webwindow" related. Launching the "Get Add-Ons" menu does not result in the add-ons browser window opening. Nothing happens, and sadly no error messages result from this.</p><p>Because I'm trying to install the Raspberry Pi support pack for Simulink, I downloaded the support pack manually. When I run the support pack installer, I finally get an error message:</p><img src = "/matlabcentral/answers/uploaded_files/73105/2017-03-22_18-34-45.png"><p>If anyone could point me in the right direction to get this working, I'd really appreciate it.</p><p>Quick summary:
* WebWindow applications (Get Add-Ons and Install Support Package windows for example) are not opening, or returning error messages and not opening
* I am connecting to the box over an SSH X tunnel
* Matlab version is R2017A (build 9.2.0.538062) 64-bit
* The machine is running CentOS linux 7 64-bit.</p><p>Thanks!</p>BlairLhttps://es.mathworks.com/matlabcentral/profile/authors/8013734-blairltag:es.mathworks.com,2005:Question/3313762017-03-22T20:37:37Z2017-03-22T23:37:12Zconverting uint 8 1D array to Tif<p>I have a 1 by N array uint8 (size: 1*801911) and I would like to convert it to a TIF. The size of the resulting TIF must be 970*830 (=805100).</p><p>I wonder why the size of TIF is greater than the size of the uint 8 array? Could you kindly teach me how to do this conversion from uint 8 to TIF?</p>EMSHhttps://es.mathworks.com/matlabcentral/profile/authors/8531965-emshtag:es.mathworks.com,2005:Question/3215242017-01-23T06:54:55Z2017-03-22T23:34:04ZI want to fit curve on this polar plot around these points,As shown in the image,Can anyone help me please<p>Please can anyone tell me how to do it?Any way will be fine</p>L Khttps://es.mathworks.com/matlabcentral/profile/authors/8487281-l-ktag:es.mathworks.com,2005:Question/3313862017-03-22T22:06:09Z2017-03-22T23:32:50ZHow can I prevent an array getting overwritten?<p>I am pulling data from an Excel file(attached below) into Matlab and I want to do a smoothing function on column 4.
I am able to do it but my data in the SNR array is getting overwritten.I want to save the SNR data for each loop in an array.
I only want to do smoothing on 27 rows and then keep looping it till the end of the file.</p><pre class="language-matlab">data=xlsread('SMA.xlsx');
</pre><pre class="language-matlab">SNR=zeros(length(data),4);
</pre><pre> for x=1:27:297</pre><pre> SNR=data(x:(x+26),:);
mov_avg=smooth(SNR(:,4));</pre><pre> figure();
plot(SNR(:,3),SNR(:,4),'+');
hold all;</pre><pre> plot(SNR(:,3),mov_avg(:),'*');</pre><pre> end</pre>Anand Khttps://es.mathworks.com/matlabcentral/profile/authors/9999837-anand-ktag:es.mathworks.com,2005:Question/3311462017-03-21T21:31:27Z2017-03-22T23:26:42ZVariable "x" change size with every loop iteration, and obtaining equally spaced values. <p>Hi,
I'm trying to solve this equation using Euler's method from the interval 0 to 2 with a step size of 0.05. Here's what I did. I created two files with following code:</p><p>File 1: Fn.m</p><pre> function f = f(t,x)
f = 1-t+4*x;
end</pre><p>File 2: Eular.m</p><pre> function Fn(f,x0,h,t0,tf)
t=t0:h:tf;
x(1)=x0;
for i = 1:10;
x(i+1) = x(i) + h*(feval(f,t(i),x(i)));
end
t=t'
x=x'</pre><p>Then I ran this command:</p><pre> Eular(@f,1,0.05,0,2)</pre><p>It won't compute because it tells me "variable 'x' appears to change size with every loop iteration". My question is:</p><p>1) How do I solve this issue. I have no prior experience with Matlab nor coding, and have absolutely no idea what to do. (Except for "preallocating", but I have no idea how to do that.)</p><p>2) I want it to output 10 values, but in equal spacing in the interval from 0 to 2 (ie. At 0, 0.2, 0.4, 0.6...2). How do I do that? Thanks!</p>Kevin Kuohttps://es.mathworks.com/matlabcentral/profile/authors/9819829-kevin-kuotag:es.mathworks.com,2005:Question/3313332017-03-22T16:47:19Z2017-03-22T23:22:27ZReal-time heart rate calculation<p>I have a real-time(phonocardiograph) plot which displays data from an electronic stethoscope via the COM port. I am trying to calculate the heart rate but having little success. I have created a <i>uicontrol</i> on the figure to display the BPM and have included the formulas to count the peak signals(beat_count). At the momement 'BPM:' displays on the plot figure but without a value so I am unable to get any BPM_avg reading.</p><pre> a = arduino('COM4','Due');
y=0;
hPlot = plot(NaN);
intervalSize = 200;
currentInterval = 200;
t = 1; % number of samples
atInterval = 1;
beat_count = 0;</pre><pre> quitbutton = uicontrol('style','pushbutton',...
'string','Quit', ...
'fontsize',12, ...
'position',[10,2,50,20], ...
'callback','quitit=1;close');
quitit = 0;
bpmtext = uicontrol('style', 'text',...
'string', ['BPM: '],...
'fontsize', 12,...
'position', [80, 2, 100, 20]);</pre><pre> while(1)
k = 1;
while(t<currentInterval)
b=readVoltage(a, 'A0');
y=[y,b];
if ishandle(hPlot)
set(hPlot, 'YData', y);
else
break; % break out of the loop
end
xlabel('Samples')
ylabel('Voltage')
title('Phonocardiogram')
axis([currentInterval - intervalSize,currentInterval,0,3]);
%grid
t=t+k;
pause(0.002)
end
for m = 2 : length(b)-1
if(b(m) > b(m-1) & b(m) > b(m+1) & b(m) > 2.4)
%disp('Prominant peak found');
beat_count = beat_count + 1;
set(bpmtext, 'string', ['BPM: ',...
num2str(BPM_avg,4)]);
end
end
currentInterval = currentInterval + intervalSize;
atInterval = atInterval + 1;
if ~ishandle(hPlot)
break;
end
fs = 500;
N = length(b);
duration_in_seconds = N/fs;
duration_in_minutes = duration_in_seconds/60;
BPM_avg = beat_count/duration_in_minutes;</pre><pre> end </pre>bilal malikhttps://es.mathworks.com/matlabcentral/profile/authors/4821130-bilal-maliktag:es.mathworks.com,2005:Question/3313952017-03-22T23:14:31Z2017-03-22T23:14:31ZFill under lines in plot3<p>Hello,</p><p>I need to fill under the Z-data in a plot3. I have below function.</p><pre class="language-matlab">function mmplot3(x,y,z,c,w,b,d)
%MMPLOT3 3-D color-based plot.
% MMPLOT3(X,Y,Z,C,W,B) or MMPLOT3(X,Y,Z,C,W,B,D), where X, Y, Z and C are
% 4 vectors of the same length, plots a line in 3-space through the points
% whose coordinates are the elements of X, Y and Z with colors
</pre><pre class="language-matlab">defined by
% vector C. W is the width of the line, B is the line brightness while
% solid line plot is used, otherwise it's the marker style and D is the
% indices increment.
</pre><pre class="language-matlab">x = x(:); y = y(:); z = z(:); c = c(:);
</pre><pre class="language-matlab">switch b
case {'.','o','x','+','*','s','d','v','^','<','>','p','h'}
iNaN=find(isnan(x));
if isempty(iNaN), iNaN = length(x); end
i = [1:d:iNaN(1),iNaN(1)];
</pre><pre> x = x(i); y = y(i); z = z(i); c = c(i);
scatter3(x,y,z,w,c,b)
otherwise
plot3(x,y,z,'linestyle','none') % make a blank plot
surface([x, x], [y, y], [z, z], ...
[c, c], 'EdgeColor','flat', 'FaceColor','none', 'linewidth',w, 'EdgeAlpha',b)
end</pre><p>Please see attached. The 3d plot I have is quite is unclear, not like the attached.</p><p>I need to fill under the Z data with white color.</p><p>Also associate each Z-data with each time (X-data) in the plot.</p>Mevahttps://es.mathworks.com/matlabcentral/profile/authors/4934134-mevatag:es.mathworks.com,2005:Question/3261012017-02-21T08:29:55Z2017-03-22T23:08:20Zi wanna generate matrix. the way fixed sum of any matrix. at the same time, will use limiting conditions<p>a=[4 5 5 5 5 5 5 5 5];</p><p>sum of a is '44'</p><p>so, i want to create matrices of sum '44'.</p><p>At the same time,</p><pre> 1) first element is started '4'
2) next element must be '4' and over
3) finally, all matrices is arrayed by ascending order</pre><p>if anyone solve this, i will appreciate it</p>Kyungmin Kimhttps://es.mathworks.com/matlabcentral/profile/authors/8072373-kyungmin-kimtag:es.mathworks.com,2005:Question/3313942017-03-22T23:06:17Z2017-03-22T23:06:17Zfitlm coefficients in rolling window anlaysis<p>I have this code, where windowsize is 36 and number of factors (i.e. variables) in the X matrix is 9.
The variable "weights" indicates the coefficients. after plotting them, it shows weights only for the first factor. I think I am missing something with the subscripts?</p><pre> for i = 2: (T-WindowSize)
InSampleReturns= FactorsReturns(i:i+WindowSize-1,:);
InSampleReturnsHF =Fundaverage(i:i+WindowSize-1);
mdl = fitlm(InSampleReturns,InSampleReturnsHF,'linear','RobustOpts','on');
weights=mdl.Coefficients.Estimate(2:end,1);
OLSptfreturns(i)=weights*OutSampleReturns(i,:)';
end</pre><p>Thanks in advance for the help!</p>helga sinahttps://es.mathworks.com/matlabcentral/profile/authors/5711370-helga-sinatag:es.mathworks.com,2005:Question/930122009-06-27T01:11:00Z2017-03-22T23:04:40ZHow do I decrease the margins around the subplots in my figure in MATLAB?<p>I would like to decrease the white space around my plots because when I copy the figure to a Word document, the margins around the axes reduces the size of the plot and I often have to crop this space out in order to increase the plot's size.</p>MathWorks Support Teamhttps://es.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:es.mathworks.com,2005:Question/3313932017-03-22T22:58:33Z2017-03-22T22:58:33ZBlock truncation coding without using toolboxes or addins<p>Hi all,
I need to write a matlab program to compress an image using the block truncation method and cannot use toolboxes or addons. I have successfully worked out how to convert image to greyscale, and split the image into blocks of 8x8 pixels. I now need to make some nested loops (I think) for each of the 8x8 matrices to take the average and standard deviation, then compare each pixel value in my 8x8 matrix then report the answer in a bitmap, then reconstruct the image.
Can anyone please help?</p><p>clear all
clc</p><p>[imagematrix colourmap] =imread('bird.tiff');</p><p>%gives image matrix size of
%and checks if there's a colourmap present</p><p>if (isempty (colourmap))
fprintf (1, 'Creating greyscale colourmap')
colourmap = [0:255; 0:255; 0:255]'/255;
%for RGB
end
%size of image</p><p>[ImageHeight ImageWidth NumColorPlanes] = size(imagematrix);</p><p>disp('Size of image as read in: ')
size(imagematrix)</p><p>disp('Size of colormap as read in: ')
size(colourmap)</p><p>if( NumColorPlanes == 3 )
%---------------------------------------------------------------
fprintf(1, 'Image has 3 planes, so converting to single-plane grayscale\n');
%---------------------------------------------------------------</p><pre> %---------------------------------------------------------------
ImageMatGrayscale = zeros(ImageHeight, ImageWidth);</pre><pre> % could do whole image as a 3-plane matrix
for p = 1:NumColorPlanes
ImageMatGrayscale = ImageMatGrayscale + double(imagematrix(:, :, p));
end
ImageMatGrayscale = ImageMatGrayscale/NumColorPlanes;</pre><pre> % this replaces the image matrix with the grayscale version
imagematrix = ImageMatGrayscale;
%---------------------------------------------------------------</pre><p>end</p><p>imshow (imagematrix)
%shows converted greyscale bird</p><p>[M,N]=size(imagematrix);
%convert to double
%imagematrix=double(imagematrix);</p><p>%------------- samples to process per block --------------------</p><p>BlockWidth = 8;
BlockHeight = 8;</p><p>NumBlocksX = ImageWidth/BlockWidth
NumBlocksY = ImageHeight/BlockHeight</p><p>Y=zeros(M,N);
%% compression</p><p>% allocate the image block
ImageBlock = zeros(BlockHeight, BlockWidth);
q=zeros(BlockHeight, BlockWidth);
H=zeros(BlockHeight, BlockWidth);
%starts at all black
Blockmean = zeros(NumBlocksX, NumBlocksY);
Blockdev = zeros(NumBlocksX, NumBlocksY);</p><p>% output image
NewImage = zeros(ImageHeight, ImageWidth);</p><p>% reset block pointer along y-axis
YBlockStart = 1;
for YBlock = 1:NumBlocksY
%going down the column</p><pre> %---------------------------------------------------------------
% reset block pointer along x-axis
XBlockStart = 1;
%---------------------------------------------------------------</pre><pre> for XBlock = 1:NumBlocksX
%going scross the rows
%---------------------------------------------------------------
%fprintf(1, 'processing block (x,y) = (%d,%d)\n', XBlock, YBlock);</pre><pre> % extract the block of pixels
ImageBlock = imagematrix(YBlockStart:YBlockStart + BlockHeight-1, ...
XBlockStart:XBlockStart + BlockWidth-1)</pre><pre> ImageBlock=double(ImageBlock);</pre><pre> %take block mean and std dev
Blockmean=mean(ImageBlock)
Blockdev=std(ImageBlock)
q = ImageBlock>Blockmean;
m=ImageHeight*ImageWidth; %length*width of block
a=Blockmean-Blockdev.*(sqrt(q./m-q)); %low mean
b=Blockmean+Blockdev.*(sqrt(m-q./q)); %high mean
H=ImageBlock>=Blockmean; %elements of Bitmap
Y(H)=a(H);
Y(~H)=b(~H);
Y=uint8(Y); %output BTC image
figure,imshow(Y)</pre><pre> %---------------------------------------------------------------</pre><pre> % build up the output image
NewImage(YBlockStart:YBlockStart + BlockHeight-1, ...
XBlockStart:XBlockStart + BlockWidth-1) = ImageBlock;
figure(3);
image(NewImage);
set(gcf, 'MenuBar', 'none', 'Name', 'Processed Image', 'NumberTitle', 'off');
set(gcf, 'Position', [470 70 350 250]);
set(gca, 'DataAspectRatio', [1 1 1]);
set(gcf, 'DoubleBuffer', 'on');
axis('off');
colormap(cmap);
drawnow;</pre><pre> % point to next block along x direction
XBlockStart = XBlockStart + BlockWidth;
%---------------------------------------------------------------</pre><pre> end
%---------------------------------------------------------------</pre><pre> %---------------------------------------------------------------
% point to next block along y direction
YBlockStart = YBlockStart + BlockHeight;
%---------------------------------------------------------------
end </pre>Chris Matthewshttps://es.mathworks.com/matlabcentral/profile/authors/9956912-chris-matthewstag:es.mathworks.com,2005:Question/3313872017-03-22T22:06:18Z2017-03-22T22:58:15ZWriting to a CSV file<p>So I wrote some code and need to output my variables, that are in a cell array, to a csv file. The code below shows how I attempt to do it, but I get the error of, "function is not defined for 'cell' inputs."</p><pre> fid = fopen('Masonry.csv', 'w');
for n = 1:numel(numberRows)
fprintf(fid, '%s', NameofTypeMasonry(n));
fprintf(fid, '%s', CountryofTypeMasonry(n));
fprintf(fid, '%s', CityofTypeMasonry(n));
fprintf(fid, '%d', HeightofTypeMasonry(n));
end</pre><p>does anyone have any idea how to fix this?</p>Christopher Robin Johnsonhttps://es.mathworks.com/matlabcentral/profile/authors/5551057-christopher-robin-johnsontag:es.mathworks.com,2005:Question/3313922017-03-22T22:58:03Z2017-03-22T22:58:03ZDoes someone has the Composite MicroMechanics COMM toolbox? Thanks!<p>Does someone has the Composite MicroMechanics COMM toolbox?
I'm doing a project about RVE, and I want to use this tool to generate the positions of random fibers,Thanks!</p>Richard Lihttps://es.mathworks.com/matlabcentral/profile/authors/10000065-richard-li