https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-01-23T10:42:14Ztag:www.mathworks.com,2005:Question/3215502017-01-23T10:42:14Z2017-01-23T10:42:14ZHow can i convert my audio signal into frames of 10 milli seconds<pre> i am getting for using this code can you send me another one
[X,Fs] = audioread('JFK_ES156.wav');</pre><p>%Calculate how many samples you need to capture 30ms of audio
matSize = Fs*0.3;</p><p>%Pay attention to that apostrophe. Makes sure samples are stored in columns
%rather than rows.
output = vec2mat(x,matSize)';</p><p>%You can now have your audio split up into the different columns of your matrix.
%You can call them by using the column calling command for matrices.</p><p>%Plot first 30ms of audio
plot(output(:,1));</p>vara prasad palurihttps://www.mathworks.com/matlabcentral/profile/authors/9576629-vara-prasad-paluritag:www.mathworks.com,2005:Question/3213712017-01-21T14:43:58Z2017-01-23T10:38:40ZWhy my AC voltage source not provides a sine curve?<p>Hello,
I run simulink to see the voltage graph of AC source but how it shows like this? Do I set some parameters wrong? AC voltage peak value is set at 100v others parameters are left as default.</p><img src = "/matlabcentral/answers/uploaded_files/68023/AC%20simulate.JPG"><img src = "/matlabcentral/answers/uploaded_files/68024/AC%20simulate2.JPG">Patchayatorn Putmeehttps://www.mathworks.com/matlabcentral/profile/authors/9482074-patchayatorn-putmeetag:www.mathworks.com,2005:Question/3215472017-01-23T10:11:04Z2017-01-23T10:29:59Zinternal error:incorrect file<p>After double clicking on the Verified Results ...Polyspace is not showing the results ...instead it is telling "INTERNAL ERROR:INCORRECT FILE Please contact Mathworks.com</p><p>what has happened actually?
how to overcome this issue?</p>Shaku kaahttps://www.mathworks.com/matlabcentral/profile/authors/8452873-shaku-kaatag:www.mathworks.com,2005:Question/3215492017-01-23T10:19:00Z2017-01-23T10:29:36Zhow to import the excel data into matlab simulink model?<p>i have a simulink model of electro hydrostatic actuator. i need to find the values of current by changing the input parameters (resistance and inductance) values. i have 10000 values for R and L in excel.i have to import these values to simulink model by using normrnd command, so it can take any values out of 10000 inputs. anyone pls help me.so i ll be very thankful.</p>Pavithra Vhttps://www.mathworks.com/matlabcentral/profile/authors/9576935-pavithra-vtag:www.mathworks.com,2005:Question/3215462017-01-23T10:04:24Z2017-01-23T10:29:26Zsir i want to run only a particular line in my code<p>i just want to run only a line in my code and specifically that line</p>Ammu Phttps://www.mathworks.com/matlabcentral/profile/authors/7670984-ammu-ptag:www.mathworks.com,2005:Question/3215122017-01-23T05:39:29Z2017-01-23T10:24:02Ztime format as hr:min:sec<p>sir, i have three columns- one containing hour, next minute , third on sec.</p><pre> hr=[10,10,10,10];
min=[00,00,01,01];
sec=[00,30,00,30];</pre><p>i need a single column of time as</p><pre> [10:00:00,10:00:30,10:01:00,10:01:30]</pre><p>what is the method?</p>seema niranhttps://www.mathworks.com/matlabcentral/profile/authors/7334588-seema-nirantag:www.mathworks.com,2005:Question/3215372017-01-23T08:37:49Z2017-01-23T10:20:39ZCan I embed a image in the following algorithm?<p>I have successfully added data into the image using the following code and algorithm image is attached below but now I want to embed an image inside an image (steganography) Please suggest proper method to do it</p><img src = "/matlabcentral/answers/uploaded_files/68100/c1.PNG"><img src = "/matlabcentral/answers/uploaded_files/68101/c2.PNG"><img src = "/matlabcentral/answers/uploaded_files/68102/c3.PNG"><p>instead of data, Please suggest a method</p><pre class="language-matlab">if true
clc;
clear all;
fprintf('The image matrix A-');
fprintf('\n');
A=imread('airplane.bmp');
figure(1), imshow(A); title('Original Image (Cover Image)');
[Z,map]=rgb2ind(A,256);
p=size(Z);
disp(p);
B=Z;
B(2:2:end,:) = fliplr(Z(2:2:end,:));
C=reshape(B',1,[]);
disp(Z)
fprintf('Inverse S-scan of A-');
fprintf('\n');
disp(C);
fprintf('Size Of Inverse S-scan Matrix-');
fprintf('\n');
z=size(C);
t=z(1)*z(2);
disp(t);
for n=1:1:t
if (n==1)
D(n)=C(1,1);
elseif n>1
D(n)=C(1,(n-1))-C(1,n);
end
end
</pre><p>for n=1:1:t
if (n==1)
E(n)=D(1,1);
else
if(D(n)>0)
E(n)=D(1,n)+1;
else
E(n)=D(1,n);
end
end
end</p><p>for n=1:1:t
if(n<2)
F(n)=E(1,n)+1;
else
F(n)=E(n);
end
end</p><p>for n=1:1:t
if(n==1)
G(n)=F(1,1);
else
G(n)=C(1,n-1)-F(1,n);
end
end</p><p>M=reshape(G,p(1),p(2));
M(:,2:2:end)=flipud(M(:,2:2:end));
M=M.';</p><p>N=ind2rgb(M,map);</p><p>figure(2);imshow(N);title('Stego Image');</p><p>peaksnr = psnr(M,B)</p><p>err = immse(M,B)
end</p>akash baishttps://www.mathworks.com/matlabcentral/profile/authors/6639609-akash-baistag:www.mathworks.com,2005:Question/3215482017-01-23T10:12:08Z2017-01-23T10:17:24ZHow to increase PSNR of an Image?<p>I am using a 512x512 image to embed data into the image for steganography, I am getting 2 PSNR which is quite less as i want sequential recovery of the data</p>akash baishttps://www.mathworks.com/matlabcentral/profile/authors/6639609-akash-baistag:www.mathworks.com,2005:Question/3215272017-01-23T07:10:14Z2017-01-23T10:17:08ZHigh memory usage with empty workspace<p>I am having issues with Matlab 2016b using a lot of memory even with an empty workspace as seen below.</p><pre> >> memory
Maximum possible array: 13580 MB (1.424e+10 bytes) *
Memory available for all arrays: 13580 MB (1.424e+10 bytes) *
Memory used by MATLAB: 22663 MB (2.376e+10 bytes)
Physical Memory (RAM): 32768 MB (3.436e+10 bytes)</pre><pre class="language-matlab">* Limited by System Memory (physical + swap file) available.
</pre><p>I was wondering if I can free this or prevent this from happening.</p>Mathias Madsenhttps://www.mathworks.com/matlabcentral/profile/authors/8913805-mathias-madsentag:www.mathworks.com,2005:Question/3212032017-01-20T09:05:32Z2017-01-23T10:10:48Zfinancial time series sum<p>Hi
we have a similar financial series:</p><p>'dates: (20)' 'Apple: (20)' 'Jpm: (20)' 'Cat: (20)' 'Aa: (20)'</p><p>'04-Mar-1994' [ 3830.90] [ 3868.04] [ 3800.50] [ 3832.30]</p><p>'07-Mar-1994' [ 3851.72] [ 3882.40] [ 3824.71] [ 3856.22]</p><p>'08-Mar-1994' [ 3858.48] [ 3881.55] [ 3822.45] [ 3851.72]</p><p>'09-Mar-1994' [ 3853.97] [ 3874.52] [ 3817.95] [ 3853.41]</p><p>how can we sum the 'Apple' with the 'Cat' values for each date?
we tried to use plus (+) but didn't work out, the error was:</p><p>Error using + (line 42)
FINTS objects are not compatible (identical).</p><p>Thank you</p>Chiara Marcangelihttps://www.mathworks.com/matlabcentral/profile/authors/6345941-chiara-marcangelitag:www.mathworks.com,2005:Question/3212762017-01-20T17:09:02Z2017-01-23T10:09:12ZOptimize variable creation from xlsread <p>Hi, how can I optimize the below script so I can create as many of the 5 variables (z,c,w,y,v) as there is available columns to pull from? Currently using below as a discrete method.</p><pre class="language-matlab">M=xlsread(filespec);
</pre><pre class="language-matlab">%Failure Load
z1 = M(:,1);
z2 = M(:,8);
z3 = M(:,15);
z4 = M(:,22);
z5 = M(:,29);
%Stiffness
c1 = M(:,2);
c2 = M(:,9);
c3 = M(:,16);
c4 = M(:,23);
c5 = M(:,30);
%Deformation
w1 = M(:,3);
w2 = M(:,10);
w3 = M(:,17);
w4 = M(:,24);
w5 = M(:,31);
%Length
x1 = M(:,4);
x2 = M(:,11);
x3 = M(:,18);
x4 = M(:,25);
x5 = M(:,32);
%Area
y1 = M(:,5);
y2 = M(:,12);
y3 = M(:,19);
y4 = M(:,26);
y5 = M(:,33);
%Modulus
v1=c1.*(x1./y1);
v2=c2.*(x2./y2);
v3=c3.*(x3./y3);
v4=c4.*(x4./y4);
v5=c5.*(x5./y5);
</pre><p>Currently calling on columns based on knowledge of what the excel file contains. How can I automate to call on all columns with data in (each variable always separated by 7 columns).
Thank you for any offered help.</p>kcinhttps://www.mathworks.com/matlabcentral/profile/authors/8239896-kcintag:www.mathworks.com,2005:Question/3212172017-01-20T10:33:57Z2017-01-23T10:06:13ZMatLab no longer opens - Java error in Windows 10<p>I installed MatLab 2016b last week, and was using it without any issues.
Now when I open it, I get the following errors (see attached screen grab).
The only thing I've changed is connected a second display to my laptop.
I can still launch it with the -nodesktop option.
Any help to fix this would be great, I've searched for a couple of hours and have not found anything yet.</p><img src = "/matlabcentral/answers/uploaded_files/67943/matlab_java_error.png">Graham Triggshttps://www.mathworks.com/matlabcentral/profile/authors/9560172-graham-triggstag:www.mathworks.com,2005:Question/3214942017-01-23T02:43:42Z2017-01-23T10:03:50ZHow to replace a pointer or marker with an object for tracing the desired path?<pre class="language-matlab">figure;
hold on
a=plot([10 10 5 5],[0 10 10 15],'r')
xlim([0 20])
ylim([0 20])
</pre><p>I want an object defined as <i>blue rectangle with dimensions 0.5m*1m</i> to trace the path given in the code.</p><p>How to do ?</p>h bhttps://www.mathworks.com/matlabcentral/profile/authors/4912971-h-btag:www.mathworks.com,2005:Question/3215452017-01-23T10:02:24Z2017-01-23T10:02:24ZHow can I include many uicontrol object definition defined in one .m file into another . m file?<p>My Matlab Program includes many functions definitions and UIcontrol objects definitions. In order to reduce the number of lines of this script, I'd like to transfer all these definitions in an external .m file and recall it inside the main script. How can I proceed?
Thank you for your help.</p>Philippe DI BINhttps://www.mathworks.com/matlabcentral/profile/authors/3806739-philippe-di-bintag:www.mathworks.com,2005:Question/3214832017-01-23T00:08:20Z2017-01-23T09:59:29ZODE45 Event Not Computed When Trying To Solve<p>Hi, I'm trying to implement an event with ODE45 to vary a value (k_mb) based on a value (z(1)) that is integrated within ODE45. I have reviewed the MathWorks documentation and examples within MATLAB, but cannot figure out what is going wrong with my code. Any help would be much appreciated.</p><pre class="language-matlab">function nestttest1
</pre><pre class="language-matlab">r_p = 10; r_g = 10; I_p = 10; m_p = 10; I_g = 10; m_g = 10;
tspan = [0:100];
z0 = [1,0,0,0,0,0,0,0];
A_or_B = [5,10];
V = [0,5,15,20,30,35,45,50,60];
iters = 0;
options = odeset('Events', @events);
</pre><pre class="language-matlab">[t,z,ye,ie] = ode45(@odefunc,tspan,z0, options);
[t,z(:,:)]
[ye,ie]
function zdot = odefunc(t,z)
if iters == 0
k_mb = 5;
end
</pre><pre> zdot(2) = ((r_p*k_mb)/I_p)*(-r_p*z(1)+r_g*z(3)+z(5)-z(7)); % Eq 1ss
zdot(6) = (k_mb/m_p)*(r_p*z(1)-r_g*z(3)-z(5)+z(7)); % Eq 2ss
zdot(4) = ((r_g*k_mb)/I_g)*(-r_g*z(3)+r_p*z(1)+z(7)-z(5)); % Eq 3ss
zdot(8) = (k_mb/m_g)*(-r_p*z(1)+r_g*z(3)-z(7)+z(5)); % Eq 4ss</pre><pre> zdot(1) = z(2); % Eq 5ss
zdot(3) = z(4); % Eq 6ss
zdot(5) = z(6); % Eq 7ss
zdot(7) = z(8); % Eq 8ss
zdot = zdot';</pre><pre> iters = iters + 1;
k_mb % Used to check whether k_mb is being changed.
end</pre><pre> function [k_mb,isterminal,direction] = events(t,z)</pre><pre> lower_index = find(V < z(1), 1, 'last');
even_or_odd = mod(lower_index,2);
k_mb = A_or_B(2 - even_or_odd);</pre><pre> isterminal = 0;
direction = 0;
end</pre><pre class="language-matlab">end
</pre>Tyler Bikaunhttps://www.mathworks.com/matlabcentral/profile/authors/7953706-tyler-bikauntag:www.mathworks.com,2005:Question/3201082017-01-12T09:52:58Z2017-01-23T09:59:27ZAssertion failed: b:\matlab\src\cgir_hdl\target_analysis\characterizationkeygenerator.cpp:45:val <p>I am trying to convert a block to HDL using HDL coder with IPcore genration as an option.It throws assertion failed Chareterizationkeygenerator error.
Error using hdlcoder.pirctx/doCriticalPathEstimation
Assertion failed:
b:\matlab\src\cgir_hdl\target_analysis\characterizationkeygenerator.cpp:45:val</p><p>Error in slhdlcoder.HDLCoder/makehdl</p><p>Error in slhdlcoder.HDLCoder/makehdlturnkey</p><p>Error in downstream.DownstreamIntegrationDriver/runIPCoreCodeGen</p><p>Error in generateIPCore</p><p>Error in Simulink.ModelAdvisor/executeCheckCallbackFct</p><p>Error in Simulink.ModelAdvisor/run</p><p>Error in Simulink.ModelAdvisor/runCheck</p><p>Error in ModelAdvisor.Node/runTaskAdvisor</p><p>This is the error list i got .I thought the error might be an issue in Model advisor being outdated and ran it task.mode. But it still throws the same error. Can anyone explain the reason why this error occcurs?</p><p>I am usinn arrow Sockit with altera Cyclone v .
Thanks in advance</p>suneel kumar Gaddamhttps://www.mathworks.com/matlabcentral/profile/authors/6375493-suneel-kumar-gaddamtag:www.mathworks.com,2005:Question/3215322017-01-23T07:34:37Z2017-01-23T09:58:07ZPlotting equation of two variables<p>Hi,
I'd appreciate some guidance/assistance plotting:
y = -sin^3(theta);
x = cos^3(theta)
All my attempts have produced graphs slightly different than the desired result (see attachment for my graph of reference=desired result).
Could it be that the desired result (my graph of reference) was created trying to plot the equation (its solutions rather) y^2/3 + x^2/3 == 1? Mathematically it appears to be similar yet could it have produced a result somewhat different?</p><img src = "/matlabcentral/answers/uploaded_files/68105/photo.JPG">Yuvalhttps://www.mathworks.com/matlabcentral/profile/authors/4179014-yuvaltag:www.mathworks.com,2005:Question/3215442017-01-23T09:55:38Z2017-01-23T09:55:38ZHow to link System function (S-function) builder designed in Simulink to MATLAB gui during simulation??<p>I wanted to fetch some data to S-function and displays some text/string on GUI during Simulation is in progress. I just have started to work in S-function and GUI.Please help me out!</p>Prajakta tapkirhttps://www.mathworks.com/matlabcentral/profile/authors/3750507-prajakta-tapkirtag:www.mathworks.com,2005:Question/3215432017-01-23T09:55:32Z2017-01-23T09:55:32ZImage Deblurring using Conjugate Gradient Method<p>I am working on debluring and image using the conjugate gradient method and I can seem to make any progress. I get a big issue that I have is that I end up attempting to divide scalar my matrices based on the formulas that I have. If anyone could have a look and lend a hand that'd be great. Or if anyone is aware of a sample of this online that I could take a look at?</p><p>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INPUT u0 = noisy image
% OUTPUT: I(i,j) = denoised image</p><p>% read the noisy data I0 in .jpg format</p><p>Io=imread('figure.jpg'); %opens image and assigns variable Io
Io=double(Io); %returns double precision value for u0
I=Io; %sets u to equal u0 so that u will give a new figure after H1 regularization
[M,N]=size(I); %sets size to equal I
imagesc(Io); axis image; axis off; colormap(gray);</p><p>% PARAMETERS %
%-----------------------------------------------</p><p>% coefficient of the H1 norm (needs to be adapted for each image)
lambda=0.028;</p><p>% space discretization
h=1.;</p><p>% number of iterations (depends on the image)
IterMax=100;</p><p>% needed to regularize at the origin
eps=0.000001;</p><p>%-----------------------------------------------------------
%---------------------------------------------------------------------------</p><p>b = lambda*Io;</p><p>%% Step 1:
%-----------------------------------------------------------
%%initial guess</p><p>for i = 1:length(M)
for i=2:M-1,
for j=2:N-1,</p><pre> r(i,j) = - (I(i,j+1)-2*I(i,j)+I(i,j-1)-(I(i+1,j)-2*I(i,j)+I(i-1,j)));
ep = ones(253,252)*eps;</pre><pre> end
end
end
%% Step 2:</pre><pre> mu = norm(r)*norm(r); %step two
r = ep + r;
p = r;</pre><p>%% Step 3:
%-----------------------------------------------------------
%for Iter=1:IterMax, %1 to 100 for loop</p><p>%Iter</p><p>for Iter=1:IterMax, %1 to 100 for loop</p><p>Iter</p><pre> for i=2:M-1
for j=2:N-1 </pre><pre> q(i,j) = lambda*I(i,j) -(I(i,j+1)-2*I(i,j)+I(i,j-1))-(I(i+1,j)-2*I(i,j)+I(i-1,j));
q(i,j) = q(i,j) + eps;
p(i,j) = p(i,j) + eps;
end
end</pre><pre> for i=2:M-1
for j=2:N-1</pre><pre> alpha =mu./(p(i,j)'*q(i,j)); %(3) alpha = mu/(p*q)
I(i,j) = I(i,j) + alpha * p(i,j); %
r(i,j) = r(i,j) - alpha * q(i,j);
mu_pre = mu;
mu = norm(r)*norm(r);
p(i,j) = r(i,j) + mu/mu_pre*p(i,j);
I(i,j) = I(i,j)-alpha*p(i,j); </pre><pre> end
end</pre><p>%end
%end</p><p>figure
imagesc(I); axis image; axis off; colormap(gray);</p><p>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</p>BGuyhttps://www.mathworks.com/matlabcentral/profile/authors/4766674-bguytag:www.mathworks.com,2005:Question/3214812017-01-22T23:59:03Z2017-01-23T09:50:32ZWhy does my mex file crash ONLY when I run it very frequently?<p>Hi I have implemented an algorithm in c++ and wrapped it into a mex file (named "mxbdlp"). When I want to test its speed, I found Matlab will crash (ask for restart) when I run the following code,</p><pre class="language-matlab">% c_list, Aeq_list, beq_list, lb_list and ub_list are pre-generated data
for i = 1:1000
[x1,fval1,inform1] = mxbdlp(c_list{i},Aeq_list{i},beq_list{i},lb_list{i},ub_list{i});
end
</pre><p>But I found if I add some delay inside the loop,</p><pre class="language-matlab">for i = 1:1000
pause(0.00001)
[x1,fval1,inform1] = mxbdlp(c_list{i},Aeq_list{i},beq_list{i},lb_list{i},ub_list{i});
end
</pre><p>or print something</p><pre class="language-matlab">for i = 1:1000
i
[x1,fval1,inform1] = mxbdlp(c_list{i},Aeq_list{i},beq_list{i},lb_list{i},ub_list{i});
end
</pre><p>MATLAB will not crash and all the results are correct. So what is the possible reason for this?</p><p>P.S. I am using MATLAB R2016b on ubuntu 14.04.</p><p>Thanks in advance!</p>Honglin Yuhttps://www.mathworks.com/matlabcentral/profile/authors/8128353-honglin-yutag:www.mathworks.com,2005:Question/3215422017-01-23T09:50:27Z2017-01-23T09:50:27ZHow to transfer legend from GUI axes to a newly created figure?<p>Hi all,</p><p>I have an axes on my GUI that has a 'button_Down' function.
When I double click on the graph on that axes the 'button_Down' function creates a new figure and copy the graph to that figure. Unfortunately, the legend are not copied.</p><p>The relevant lines in my 'button_Down' function are:</p><pre class="language-matlab">New_Fig = figure;
set(hObject,'Units','normalized'); % hObject is the axes that reacts to the double click
copyobj(hObject,New_Fig);
</pre><p>How can I transfer the legends too?</p><p>Thansk,</p><p>Alon</p>Alon Rozenhttps://www.mathworks.com/matlabcentral/profile/authors/3038003-alon-rozentag:www.mathworks.com,2005:Question/3215392017-01-23T09:14:13Z2017-01-23T09:47:46ZHow to plot an external inflow to a graph?<p>Hi all,</p><img src = "/matlabcentral/answers/uploaded_files/68104/Capture.PNG"><p>I would like to plot an external inflow to my digraph as shown in the figure. This external inflow is distributed over the outgoing edges. Is this possible, if yes, how? =)</p><p>Really looking forward to your reply.</p><p>Kind regards,</p><p>Jaimy Louwaars</p>Jaimy Louwaarshttps://www.mathworks.com/matlabcentral/profile/authors/9560517-jaimy-louwaarstag:www.mathworks.com,2005:Question/3215402017-01-23T09:22:44Z2017-01-23T09:46:01Zwhy my iteration prog doesn't work ?<pre class="language-matlab">% Use NR method f(x)= x^3-5x^2+7x-3
clc
TV=3;
x=(4);
tol=0.0007;
format long
for i=1:5;
fx=(x(i))^3-5*(x(i))^2+7*(x(i))-3;
fxx=3*(x(i))^2-10*(x(i))+7;
x(i+1)=(x(i))-(fx/fxx);
E_T(i)=(abs((TV-x(i+1))/TV))*100;
end
for i=1:5;
e(i)=(x(6))-(x(i));
fx=(x(i))^3-5*(x(i))^2+7*(x(i))-3;
fxx=3*(x(i))^2-10*(x(i))+7;
fxxx=6*(x(i))-10;
e(i+1)=(-fxxx/2*fxx)*(e(i))^2;
end
if abs(TV-(x(i+1)))<tol
disp(' enough to here')
disp(' -----------')
disp(' x(i+1) ')
disp(' -----------')
x;
disp(' -----------')
disp(' T.V ')
disp(' -----------')
E_T;
disp(' -----------')
disp(' E(i+1) ')
disp(' -----------')
e;
disp(' ------------- ')
end
%-----------------------------------------------------------
</pre>khalid boureenyhttps://www.mathworks.com/matlabcentral/profile/authors/9498476-khalid-boureenytag:www.mathworks.com,2005:Question/3215412017-01-23T09:45:13Z2017-01-23T09:45:13Zhow can i reduce the current (ampere) value for DTC for BLDC motor in Simulink?<p>I'm implementing DTC for BLDC motor in Simulink and am doing fine except am having very high current (ampere) value, how can i reduce the current please advice?</p>San Sameerhttps://www.mathworks.com/matlabcentral/profile/authors/7132930-san-sameertag:www.mathworks.com,2005:Question/3215332017-01-23T07:42:09Z2017-01-23T09:31:28Zhow can I do sharpening attack?<p>Hi, I want to do sharpening attack on image but I do not know how can I do it in matlab. is it any function or code for this?</p>nadiahttps://www.mathworks.com/matlabcentral/profile/authors/5841148-nadiatag:www.mathworks.com,2005:Question/879912013-09-23T18:49:00Z2017-01-23T09:12:44Z PSO algorithm for OPF (Optimize power flow) with Matlab code<p>I am finding a matlab code for OPF problem with a certain power network. Please help!</p>dat nguyenhttps://www.mathworks.com/matlabcentral/profile/authors/3708176-dat-nguyentag:www.mathworks.com,2005:Question/3209632017-01-18T17:45:05Z2017-01-23T09:09:44ZCalculating moving standard deviation (bounds) for time series <p>I have a <b>N</b> x 6 matrix and of interest are columns 1 and 5. Column 1 is time data in Excel's serial date format (e.g. 4.264400001156250e+04 = 01-Oct-2016 00:00:00) and Column 5 is Measurement data.</p><p>The time data spans across <b>M</b> days and has interval in seconds (not regular), so the value of N is quite large (~40,000).</p><p>What I would like to do is this:
For a Measurement data on day <b>X</b>, calculate the standard deviation(σ) for that day based on the Measurement data for past <b>Y</b> days. How can I script this out? I can do this in Excel, but due to the sheer number of rows, it tends to get somewhat slow.</p>BenLhttps://www.mathworks.com/matlabcentral/profile/authors/3963340-benltag:www.mathworks.com,2005:Question/3214412017-01-22T13:32:02Z2017-01-23T09:06:25ZTrace Marker Along Line<p>Hi</p><p>I have tried writing the code to trace marker along a line ( form matlab help)to make an animation</p><p>1. it doesn't work</p><p>2. I need to do it with polar function and not plot function</p><p>Can you help?</p><p>The code:</p><pre class="language-matlab">x = linspace(0,10,1000);
</pre><pre class="language-matlab">y = sin(x);
</pre><pre class="language-matlab">plot(x,y)
</pre><pre class="language-matlab">hold on
</pre><pre class="language-matlab">p = plot(x(1),y(1),'o','MarkerFaceColor','red');
</pre><pre class="language-matlab">hold off
</pre><pre class="language-matlab">axis manual
</pre><pre class="language-matlab">for k = 2:length(x)
</pre><pre> p.XData = x(k);</pre><pre> p.YData = y(k);</pre><pre> drawnow</pre><pre class="language-matlab">end
</pre>Shani Galhttps://www.mathworks.com/matlabcentral/profile/authors/1077966-shani-galtag:www.mathworks.com,2005:Question/3215382017-01-23T09:03:14Z2017-01-23T09:03:14ZHow can I get a Class Object of C++, which is created in Mex function, after running the Mex?<p>Hi, I have 2 mex functions compiled from C++. In the first one, it creates Class Object of C++ and the second one does the next work by the same Class Object.
I tried(e.g. used persistent, mexMakeMemoryPersistent), but it seems I can not get the Class Object created in the first mex. Did anyone know how to do?
PS. It works correctly when I combine the two mex functions, but I must separate them in order to call the second one circularly in my script.</p><pre class="language-matlab">//the first mex
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
if(nrhs!=0)
{
mexPrintf("do not need argument!\n");
}
else
{
CBodyBasics * classExample=new CBodyBasics;
HRESULT hr;
hr=classExample->InitializeDefaultSensor();
if (FAILED(hr))
{
printf("err in starting!\n");
return;
}
}
}
</pre>jy baihttps://www.mathworks.com/matlabcentral/profile/authors/9576400-jy-baitag:www.mathworks.com,2005:Question/3215252017-01-23T07:03:46Z2017-01-23T08:56:57Zhow shall I replace "inline" function by anonymous function <pre class="language-matlab">if true
myfunc=inline('beta(1)*x+beta(2)','beta','x');
[~,r]=nlinfit(x,y,myfunc,[1,1]);
end
</pre><p>I code as above and Matlab remind me that "inline" will be replaced by anonymous function and deleted in future;</p><p>Now how shall I replace "inline" function by anonymous function?</p>vx2008https://www.mathworks.com/matlabcentral/profile/authors/4152284-vx2008tag:www.mathworks.com,2005:Question/3212882017-01-20T18:32:19Z2017-01-23T08:51:04ZHow to create a timeline ?<p>I want to have the time (e.g from january to december) on the x-axis and just location on the "y axis".
Example:</p><p>LOCATION</p><p>location 1 x_________ x</p><p>location 2 x <i>__</i> x</p><p>location 3 x x_xx__xxx__xxx</p><p>timline jan ---- juni ---- dec --- > 2016</p>kk1991https://www.mathworks.com/matlabcentral/profile/authors/9562868-kk1991tag:www.mathworks.com,2005:Question/2757822016-03-28T12:12:42Z2017-01-23T08:36:24Zerror finding installer class<p>i tried to install trial version
and i recive the error:
"error finding installer class.
an exception occurred while looking for class."</p>amir roshttps://www.mathworks.com/matlabcentral/profile/authors/7923252-amir-rostag:www.mathworks.com,2005:Question/3215242017-01-23T06:54:55Z2017-01-23T08:27:49ZI 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://www.mathworks.com/matlabcentral/profile/authors/8487281-l-ktag:www.mathworks.com,2005:Question/3206152017-01-16T15:53:54Z2017-01-23T08:21:13ZSyntax error with Fcn block in simulink<p>Dear all,</p><p>I am getting a syntax error in Simulink in a Fcn block:</p><p>u(strmatch('Name',OutList))</p><p>Error:</p><pre> Error using Run_Simu (line 16)
The expression: u(strmatch('Name',OutList))
in 'Directory of the file'
has a syntax error Error using Run_Simu (line 16)</pre><p>I need to find Name from a string array in OutList (sometimes the order of the strings change,
so that "strmatch"). The error is displayed only the first time. But if I need to implement the simulink model in a loop it is imposible due to the error.</p><p>How can I avoid the error or find the string in another way?</p><p>Thanks in advance,
JOE</p>J. Olondrizhttps://www.mathworks.com/matlabcentral/profile/authors/4609180-j-olondriztag:www.mathworks.com,2005:Question/3215202017-01-23T06:34:39Z2017-01-23T08:18:29Zneed help in conversion of matlab code to c language?how to resolve these issues?<p><</p><img src = "/matlabcentral/answers/uploaded_files/68087/Untitled.png"><p>>></p>zahara alihttps://www.mathworks.com/matlabcentral/profile/authors/8214228-zahara-alitag:www.mathworks.com,2005:Question/3215232017-01-23T06:49:38Z2017-01-23T08:16:46ZNot able to open *.mdl file.<p>I am trying to open a *.mdl file by drag and drop in command window but the model is not opening. It shows the uiopen('model path') but still it is not opening. What should I do to open that model to update my logic in it.</p>Snehal Parmarhttps://www.mathworks.com/matlabcentral/profile/authors/6664089-snehal-parmartag:www.mathworks.com,2005:Question/3215362017-01-23T08:13:25Z2017-01-23T08:13:25ZWhy and how does dicomwrite reshape a grayscale matrix X?<p>Hey folks,</p><p>I have a rather delicate problem. I am working on a program to anonymize any sort of patient-related data in a set of DICOM files, i.e. CT slices, a structure set, a radiation plan file and a dose file, all exported from our radiation treatment planning system for one specific patient. So far, everything works fine, the only problem left is that dicomwrite seems to rearrange or reshape the matrix X. It should look like this (screenshot from the dose distribution in the planning system)</p><img src = "/matlabcentral/answers/uploaded_files/68098/Nominal.JPG"><p>but instead looks like this</p><img src = "/matlabcentral/answers/uploaded_files/68099/Actual.JPG"><p>I tried to find out what was going on throughout the process of dicomwrite. In dicom_encode_pixel_cells.m there appears a permute command. Since the matrix X has the size of X, Y, 1, frames, I played around a little with X's 4 dimensions. But even testing all permutations in the ORDER of PERMUTE didn't give me the desired orientation of the matrix. Commenting the permute out didn't help either.
Also, in dicom_prep_ImagePixel.m there is a reshape command at the end of the file. Maybe that is the right spot.
My code is as follows:</p><pre class="language-matlab">try
dicomwrite(X, out_full, to_anonymize, 'CreateMode', 'Copy', 'MultiframeSingleFile', 'true');
catch ME
uiwait(errordlg(ME.message, 'error'));
return
end
</pre><p>Here, X is the matrix, obviously, out_full is the absolute path of the file everything should be saved to (i.e. fullfile(pwd, out_file);) and to_anonymize is the metadata structure that was produced by dicominfo from the input file being read.</p><p>I just cannot figure out what to do about it and how to properly store that matrix X and therefore the dose distribution without having it flipped all over the place.
I also tried checking the shape and orientation of the matrix before importing it into our planning system using Eric Ludlam's fantastic <a href = "http://de.mathworks.com/matlabcentral/fileexchange/764-sliceomatic">Sliceomatic</a>. I'm stuck with this.</p><p>Any sort of help is highly appreciated.</p><p>p.s.: I'm using Matlab R2010b on a 64-bit Windows 7 notebook.</p>Pascalhttps://www.mathworks.com/matlabcentral/profile/authors/5406107-pascaltag:www.mathworks.com,2005:Question/3215132017-01-23T05:47:46Z2017-01-23T08:13:04Z Initialization failed. (No combination of intermediate filters could be found to make the connection.) Error<pre> Initialization failed. (No combination of intermediate filters could be found to make the connection.) Error
using 32-bit matlab</pre>Mohammedashraf Shaikhhttps://www.mathworks.com/matlabcentral/profile/authors/9395642-mohammedashraf-shaikhtag:www.mathworks.com,2005:Question/3215142017-01-23T06:01:12Z2017-01-23T08:05:41ZMatlab related directories took too much of time to compile/build it<p>Hi,</p><p>MATLAB related directories(/xyz/iir) took too much of time( 3-4 hours) to compile it.
After taking too much of time, build will be Succeeded.
We are doing it on Linux Machine.
Example of one directory is given below which is related to MATLAB. <b>Any idea Why it is taking too much of time build directories which is related to MATLab?**</b></p><p><b>*</b> Doing "/vobs/mb/bin/imboot " in /xyz/iir ...</p><p>Sourcing '~/.mrenv.cshrc'...</p><p>% /usr/atria/bin/clearaudit /vobs/mb/bin/imake/imboot.sh -t MATLAB</p><p><b>*</b> Doing "/vobs/mb/bin/mrmake -u" in /xyz/iir ...</p><p>Sourcing '~/.mrenv.cshrc'...
% /usr/atria/bin/clearmake -u -R
/bin/rm -f gradcoil2iir run_gradcoil2iir.sh gradcoil2iir_readme.txt
/vobs/mb/bin/matlab_builder -o gradcoil2iir gradcoil2iir.m -m -I /xyz/iir -I /vobs/tools/matlab/util</p><p>[Warning: Adding path "/xyz/iir" to Compiler path instance.]
[Warning: Adding path "/vobs/tools/matlab/util" to Compiler path instance.]</p><p><b>mrbuild result: succeeded</b>: /xyz/iir</p><p>>>ver</p><p>----------------------------------------------------------------------------------------------------</p><p>MATLAB Version: 9.0.0.341360 (R2016a)
MATLAB License Number: xxxxxx
Operating System: Linux 3.10.0-327.28.3.el7.x86_64 #1 SMP Thu Aug 18 11:09:00 CDT 2016 x86_64
Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot™ 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------</p><p>MATLAB Version 9.0 (R2016a)
MATLAB Compiler Version 6.2 (R2016a)</p>venkatesh guttalhttps://www.mathworks.com/matlabcentral/profile/authors/9575788-venkatesh-guttaltag:www.mathworks.com,2005:Question/3215352017-01-23T08:03:04Z2017-01-23T08:03:28ZAbout weights of neural network<p>I make a neural network, and I used the following data.</p><p>Nodes No. of input data = 1016 //
Nodes No. of hidden layer = 10</p><p>but, net.IW{1,1} matrix is {10x851} double matrix, not {10x1016}.</p><p>Why is this?</p><p>Input data has the same number or a little bit of 0.</p><p>And how can I calculate directly from these weights matrix?</p>eriiharuuehttps://www.mathworks.com/matlabcentral/profile/authors/7898756-eriiharuuetag:www.mathworks.com,2005:Question/882842013-09-26T06:05:23Z2017-01-23T07:57:48ZRemove the spurious edge of skeleton<p>Recently, I've had an object to get it's skeleton,and then simplified the skeleton</p><p>but my problem is how to remove the edge of the skeleton for simplified the skeleton</p><p>here is my few steps:</p><p>First,I've got the skeleton from my object with bwmorph(ima,'skel',Inf)</p><p>here is the object which has been filled and the skeleton below:</p><p>filling the object:</p><img src = "/matlabcentral/answers/uploaded_files/203/4.jpg"><p>the skeleton:</p><img src = "/matlabcentral/answers/uploaded_files/202/1.jpg"><p>Second,for the skeleton, I've mark the branch points and end points</p><p>to mark the branch points and end points,I use bwmorph(skel, 'branchpoints') and</p><p>bwmorph(skel, 'endpoints');</p><p>here is the figure that I marked the points below:</p><img src = "/matlabcentral/answers/uploaded_files/204/2.jpg"><p>the reds are branch points</p><p>the blues are end points</p><p>and the last step,</p><p>from the above figure, I want to remove the edges between branch point and end point (here I call the edge is spurious edge)</p><p>here is the resulting figure that I want</p><img src = "/matlabcentral/answers/uploaded_files/205/3.jpg"><p>my problem is how can I remove the spurious edges</p><p>I've referenced this article</p><p><a href = "http://www.mathworks.com/matlabcentral/answers/5559">http://www.mathworks.com/matlabcentral/answers/5559</a></p><p>and the suggestions are set the threshold of the distance</p><p>but in my situation,the lengths of the spurious edges may have too long or too short...</p>Honghttps://www.mathworks.com/matlabcentral/profile/authors/4631093-hongtag:www.mathworks.com,2005:Question/3210372017-01-19T08:01:53Z2017-01-23T07:49:15Zcan any body help me to make function of this code so that i can convert it into c ..........<pre class="language-matlab">clear all
clc
close all
</pre><pre class="language-matlab">my_root = pwd;
fig_dir = [my_root '/Figures'];
if (exist (fig_dir, 'dir') == 0)
mkdir(fig_dir);
end
subfig = ['a','b','c'];
</pre><pre class="language-matlab">N = 10;
d= 0.5;
Z= (-(N-1)/2:(N-1)/2)';
</pre><pre class="language-matlab">us = 0;
ks = (-2*pi*us)';
vs = exp(-1i*ks'*d*Z);
</pre><pre class="language-matlab">uI = [0.29 0.45];
D = length (uI);
kI = (-2*pi*uI)';
vI = exp(-1i*kI*d*Z')';
</pre><pre class="language-matlab">sigma_n = 1;
INR = 10^(20/10);
sigma_I = INR*sigma_n;
Sn = sigma_I*(vI*vI') + sigma_n*eye(N);
</pre><pre class="language-matlab">SNR = 10.^([30]/10);
S = length(SNR);
</pre><pre class="language-matlab">L = 200;
K = [1 2 3 4 6 10 20 50 100]*N;
u = [0.999];
</pre><pre> sigma_s = SNR *sigma_n;
Sxs = sigma_s*(vs*vs');</pre><pre> sigma_0 = (10.^([10]/10)) * sigma_n;</pre><pre class="language-matlab"> for j = 1 : length(K)
for l = 1 : L
FI = sqrt(sigma_I/2)*randn(D,K(j))+1i*sqrt(sigma_I/2)*randn(D,K(j));
Noise = sqrt(sigma_n/2)*randn(N,K(j))+1i*sqrt(sigma_n/2)*randn(N,K(j));
Fs = sqrt(sigma_s/2)*randn(1,K(j))+1i*sqrt(sigma_s/2)*randn(1,K(j));
X = vs*Fs + vI*FI + Noise;
w = vs/N;
P = (1/sigma_0(o))*eye(N);
lambda = inv(vs'*P*vs);
for k = 2 : K(j)
g = P*X(:,k)/(u + X(:,k)' *P*X(:,k));
P = (P - g *X(:,k)'*P)/u ;
e = Fs(k) - (w(:,k-1)'*X(:,k));
w(:,k) = w(:,k-1) + g*conj(e);
</pre><pre class="language-matlab"> Y(k) = (w(:,k)'*X(:,k));
end
</pre><pre> SINRo(l)=sigma_s*abs(w(:,k+1)'*vs)^2/(real(w(:,k+1)'*Sn*w(:,k+1)));
end</pre><pre> SINRo_RLS_avg(j) = sum(SNIRo)/L;</pre><pre class="language-matlab"> end
</pre>zahara alihttps://www.mathworks.com/matlabcentral/profile/authors/8214228-zahara-alitag:www.mathworks.com,2005:Question/3215342017-01-23T07:45:13Z2017-01-23T07:45:13Zhow to link c code to simulink<p>I have a c code i need to call the functions in the c code using s function in simulink... please someone give me the detailed procedure..</p>sneha bharadwajhttps://www.mathworks.com/matlabcentral/profile/authors/6727954-sneha-bharadwajtag:www.mathworks.com,2005:Question/3173262016-12-18T10:24:56Z2017-01-23T07:36:11ZHow to switch between one plot and two subplots on a GUI?<p>Hi all,</p><p>I created a GUI, using GUIDE, and in it I placed an axes.
I have no problem to reach this axes and plot whatever on it.
In some cases I want to use two subplots where this axes is located.
I tried it and the original axes was deleted while two others, one for each subplot, were created.
Now I can't return to the one axes configuration because it is gone.</p><p>What is the best approach to be able to switch between one plot and two subplots at the same place where the original axes is located?</p><p>Thanks,</p><p>Alon</p>Alon Rozenhttps://www.mathworks.com/matlabcentral/profile/authors/3038003-alon-rozentag:www.mathworks.com,2005:Question/3215152017-01-23T06:01:36Z2017-01-23T07:35:30Zinflection of an unknown polynomial???<p>Hi</p><p>I dont have much experience with this program, at my school they just kind of throw you in so trying to teach myself...</p><p>Can I use the poly or second derivative functions to find inflection points of a quadratic equation with unknown polynomials. I am given f(x)=3Ax^2+2Bx+C</p><p>I understand you would make the vector [3 2 1] if it didnt have the unknown polynomials A B C but that's what throwing me off. Would it be handled the same way in a cubic equation?</p><p>Any help is appreciated!</p>Jettiebhttps://www.mathworks.com/matlabcentral/profile/authors/9575795-jettiebtag:www.mathworks.com,2005:Question/729782013-04-21T09:57:30Z2017-01-23T07:34:34Zminimal polynomials for a galois extension field<p>i have a galois field generated by:</p><pre> primpoly = 1 0 1 1
m = 4( assumed)
indx = [0:1:2.^m-1]; %power index
U = gftuple(indx(:),primpoly,p)
how to find the minimalpolynomials for the field?</pre>Malikhttps://www.mathworks.com/matlabcentral/profile/authors/3697174-maliktag:www.mathworks.com,2005:Question/3215302017-01-23T07:26:46Z2017-01-23T07:31:46ZHow to count zeros between not zero<p>I want to count the number of zeros between 1 in each columns.</p><p>14X3 matrix</p><img src = "/matlabcentral/answers/uploaded_files/68094/z.jpg"><p>So, results should be 3,2 in first column, 4 in second column and 2,3 in third column
Please, help me.</p>TaeWoo Kimhttps://www.mathworks.com/matlabcentral/profile/authors/8478673-taewoo-kimtag:www.mathworks.com,2005:Question/3215312017-01-23T07:28:15Z2017-01-23T07:28:15ZRun simulink model (slx format) in m-file<p>Hello
I have a model in simulink and need to set constant parameters from m file.
the names of the model and mfile are different.
instead of values in the content box in the model I used the variable name: 'H_move'
I used the simset() function to import the values but got these errors:</p><p>Unrecognized property name 'H_move'.
or this one
block_diagram does not have a parameter named 'H_move'</p><p>I searched a lot but could not recognize the problem.
Best Regards
Amin</p>aminhttps://www.mathworks.com/matlabcentral/profile/authors/3569315-amintag:www.mathworks.com,2005:Question/3215292017-01-23T07:24:09Z2017-01-23T08:00:52ZFind intersect of two step function<p>Find intersect of two step function?</p><pre class="language-matlab">buy=[18 4;16 3;14 3;12 3;10 4;9 3]
sell=[1 1;1.5 2;2 3;3 2;5 4;7 3;11 3;15 4]
plot(sell_qq,sell_pp)
hold on
plot(buy_qq,buy_pp)
</pre>Reza Sharifihttps://www.mathworks.com/matlabcentral/profile/authors/9576040-reza-sharifitag:www.mathworks.com,2005:Question/3215282017-01-23T07:16:49Z2017-01-23T07:27:26Zmatlab code for r(t)=Rm(1+K sinD(2πf0t+θ)sin(2πf0t + Ka sin(2πfmt) + θ )<p>Please tell me how to write code for that equation</p>MURALI KRISHNAhttps://www.mathworks.com/matlabcentral/profile/authors/6792893-murali-krishna