https://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-03-27T14:36:32Ztag:nl.mathworks.com,2005:Question/3319992017-03-26T16:02:36Z2017-03-27T14:30:42ZHow to remove shadow from image ?<p>I am building a braille dots recognition program. After i acquire image through the camera and convert it into binary, the shadow also becomes significant and hence the result gets affected. Can you suggest me a code to avoid the effect of shadows??
Here is the example image(shadow is on the bottom half part of the image):</p><img src = "/matlabcentral/answers/uploaded_files/73425/66.jpg"><p>Here is the Binary image:</p><img src = "/matlabcentral/answers/uploaded_files/73427/untitled111.jpg"><p>Histogram of the Orignal Image:</p><img src = "/matlabcentral/answers/uploaded_files/73430/zaq.bmp">Zaheer Abbashttps://nl.mathworks.com/matlabcentral/profile/authors/9354031-zaheer-abbastag:nl.mathworks.com,2005:Question/3321372017-03-27T13:23:26Z2017-03-27T14:28:54ZHow to compare one column of one matrix with all columms of other matrix one by one? matlab 2014b<p>suppose N is 7x8 matrix, M is 7x8 matrix. both are different
i want N(:,1)-M(:,1);N(:,1)-M(:,2);N(:,1)-M(:,3)...........N(:,2)-M(:,1);N(:,2)-M(:,2) and so on.
how to do that? please help me. I am using matlab version 2014b.</p>Pooja Patelhttps://nl.mathworks.com/matlabcentral/profile/authors/8400021-pooja-pateltag:nl.mathworks.com,2005:Question/3321442017-03-27T13:56:43Z2017-03-27T14:27:54Z can anyone explain this code? what is meant by imagesc?<pre> for a = 1:size(video,4)
imagesc(video(:,:,:,a));
axis image off
drawnow;
end;</pre>sai likhitha GOdinahttps://nl.mathworks.com/matlabcentral/profile/authors/10029881-sai-likhitha-godinatag:nl.mathworks.com,2005:Question/3321062017-03-27T09:38:29Z2017-03-27T14:25:26ZFilterdesign of a given magnitude response<p>Hi,
I have a given Magnitude Response <tt>H(f)</tt> which is derived from an analytical equation. Now I want to amplify/damp my Signal x(t) with it, but I don't really know how. If I can get the z-Transform of my curve, I could filter my Signal. Or maybe I should design a filter somehow which fits my curve best.
Any advice is appreciated. Cheers</p>Gabriel kaindlhttps://nl.mathworks.com/matlabcentral/profile/authors/8540115-gabriel-kaindltag:nl.mathworks.com,2005:Question/3320522017-03-27T00:12:17Z2017-03-27T14:20:50Zintersection point between 2-d plot and a line <p>Hi,</p><p>I have 2-d plot that is based on data (two vectors) and a horizontal line function (using fplot).</p><p>I am trying to find intersection point of outer most line of 2-d plot(blue) and red line, in other words I want to get the intersection point where red line hits the first and the last. Then I want to find difference between intersection points of x axes, that is x2 - x1. How should I proceed?</p><p>Thank you</p><img src = "/matlabcentral/answers/uploaded_files/73457/Capture.PNG">Mike Leehttps://nl.mathworks.com/matlabcentral/profile/authors/5106932-mike-leetag:nl.mathworks.com,2005:Question/3320342017-03-26T21:15:14Z2017-03-27T14:18:07ZIs there an efficient bsxfun representation for pairwise distances with different metrics?<p>Let's say I have two matrices</p><pre class="language-matlab">X = rand(d,n) % n d-dimensional vectors
Z = rand(d,m) % m d-dimensional vectors
</pre><p>where I'm looking for pairwise distances matrix, D,</p><pre class="language-matlab">[n, m] = size(D)
</pre><p>For squared Euclidean distances (p=2), the implementation of bsxfun makes sense. Is there a general way to calculate a distance matrix for any value of p using bsxfun? How would this look? Or does this only work for p=2?</p><p>Thanks!</p>Bradley Flynnhttps://nl.mathworks.com/matlabcentral/profile/authors/7566873-bradley-flynntag:nl.mathworks.com,2005:Question/3319302017-03-26T02:16:36Z2017-03-27T14:12:46ZCan anyone explain why Matlab gets slower and slower until restart if large cell or struct arrays are allocated and cleared repeatedly, but only on Windows, not Linux?<p>I am experiencing a serious performance problem with some matlab code that I have simplified with the attached example. I would appreciate any help in explaining how to avoid or workaround this issue, and also anyone who can run my example and confirm that they see the same result. I am very surprised at how badly this affects performance and how simple it is to reproduce (How many people are suffering from this unknowingly?). Here are some properties of this issue I've noticed:</p><ol><li>execution time increases fairly linearly with each reinitialization of a large cell array or struct array.</li><li>execution time remains slow until Matlab is restarted.</li><li>execution time of other unrelated code with different variables that also meet the criteria is affected until restart.</li><li>Only occurs if both the cell or struct array containers are large enough (around 2000 elements or more)</li><li>Only occurs if each cell element or struct array element contains a large matrix (around 200 x 200 or more)</li><li>Only occurs on Windows (Linux runs the same example code without issues). I am using Windows 7 64 bit (16GB ram)</li><li>Occurs on all recent versions of Matlab that I have tried (R2015b through R2017a)</li><li>Occurs in a script (See SlowingExecutionIssueSimple.m or the code pasted below)</li><li>Occurs in a function, but with slightly different conditions. Does not occur if the variable is persistent for certain initialization methods. Occurs if the variable is not persistent regardless of initialization method. See SlowingExecutionIssue.m for easy testing of all these cases.</li><li>After many iterations of the outer loop, the growth in execution time eventually seems to level off, but at a completely unusable level of performance compared to the first iteration.</li><li>Occurs even with fully preallocated arrays (in some cases, it occurs <i>especially</i> if fully preallocated - see struct array example in SlowingExecutionIssue.m for case where incomplete preallocation avoids this problem)</li><li>"clear all" and "clear classes" have no effect.</li></ol><p>Thanks in advance for any help with this. So far I have only been able to work around it in my application code by making variables persistent inside a function and avoiding reinitialization (i.e. reinitializing only one element at a time inside the innermost loop). It is not always possible to work around it and requires constant use of the memory that could otherwise be freed. Is this a bug in how Matlab manages memory?, or an unavoidable side effect of windows memory management? If it doesn't get fixed soon, I may have to switch permanently to Linux to avoid this issue.</p><pre class="language-matlab">iter = 10000;
for i = 1:10
tic;
a0 = ones(221,241);
a = a0;
% c=cell(iter,1);%Cell array example. The problem only occurs if c is reinitialized each time
f = repmat(struct('a',a),1,iter);%Struct array example. Struct array with all elements populated with "a"
for j=1:iter
%a has to change each iteration or the issue doesn't show up
a=a+1;%Change the variable
a=a-1;%Change the variable back to original value
% c{j}=a;%This causes serious slowdown with each run
f(j).a = a;%This causes serious slowdown with each run
% c{j}=a0;%This runs fast even though a0 is identical in size, type, and value to a
% f(j).a = a0;%This runs fast
end
toc
end
</pre><p>Here is the output I get from this script:</p><pre class="language-matlab">>> SlowingExecutionIssueSimple
Elapsed time is 1.227035 seconds.
Elapsed time is 1.336831 seconds.
Elapsed time is 1.349026 seconds.
Elapsed time is 1.426942 seconds.
Elapsed time is 1.568531 seconds.
Elapsed time is 1.779247 seconds.
Elapsed time is 2.051785 seconds.
Elapsed time is 2.412232 seconds.
Elapsed time is 2.857880 seconds.
Elapsed time is 3.500180 seconds.
>> clear all
>> clear classes
>> SlowingExecutionIssueSimple
Elapsed time is 2.254901 seconds.
Elapsed time is 4.609098 seconds.
Elapsed time is 5.811552 seconds.
Elapsed time is 6.322061 seconds.
Elapsed time is 6.974427 seconds.
Elapsed time is 7.242437 seconds.
Elapsed time is 7.527272 seconds.
Elapsed time is 7.704636 seconds.
Elapsed time is 8.079658 seconds.
Elapsed time is 8.315676 seconds.
>>
</pre>Reedhttps://nl.mathworks.com/matlabcentral/profile/authors/6808-reedtag:nl.mathworks.com,2005:Question/3321482017-03-27T14:11:10Z2017-03-27T14:11:10ZPlot validation and training error for convolutional neural networks<p>Is there any way to plot the validation and training error for a conv net, similar to the plotperform function for "normal" neural nets?</p>Simonhttps://nl.mathworks.com/matlabcentral/profile/authors/4044652-simontag:nl.mathworks.com,2005:Question/3318672017-03-25T12:12:43Z2017-03-27T14:08:35ZHow to crop an image into blocks and store blocks in an array or matrix ? <p>I need to crop an image into blocks an store the blocks in a matrix because I need to apply BoxCounting algorithm on each block.</p>Preda Virgil Ionuthttps://nl.mathworks.com/matlabcentral/profile/authors/9242989-preda-virgil-ionuttag:nl.mathworks.com,2005:Question/3321472017-03-27T14:08:11Z2017-03-27T14:08:11Zsingle side band modulation using filtering method matlab code<p>1. Determine the expression for SSB Modulated signal in both time domain and frequency domain.
1. Sketch the modulating signal m(t) and its spectrum.
2. Sketch the carrier signal c(t) and its spectrum.
3. Sketch the SSB Modulated signal (USB/(LSB) SSB (t) and their spectra.
4. Identify the USB / LSB) spectrum.
5. Determine the maximum and minimum amplitudes of the envelope.</p>ruffuddeen bashahttps://nl.mathworks.com/matlabcentral/profile/authors/10026819-ruffuddeen-bashatag:nl.mathworks.com,2005:Question/3312202017-03-22T07:21:50Z2017-03-27T14:04:28Z Segmentation violation detected ?<p>Everytime I am opening saved scripts, Matlab is crashing with below given error. However the same code can be run from command line without opening the code.</p><p>Please help.</p><p>------------------------------------------------------------------------
Segmentation violation detected at Wed Mar 22 12:31:47 2017
------------------------------------------------------------------------</p><p>Configuration:
Crash Decoding : Disabled
Default Encoding : windows-1252
MATLAB Architecture: win64
MATLAB Root : C:\Program Files\MATLAB\R2013a
MATLAB Version : 8.1.0.604 (R2013a)
Operating System : Microsoft Windows 8
Processor ID : x86 Family 6 Model 37 Stepping 2, GenuineIntel
Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode
Window System : Version 6.2 (Build 9200)</p><p>Fault Count: 1</p><p>Abnormal termination:
Segmentation violation</p><p>Register State (from fault):
RAX = 0000000000000000 RBX = 0000000000000000
RCX = 0000000000000000 RDX = 0000000015269e50
RSP = 000000017c02fcd0 RBP = 000000017c02fdd0
RSI = 00000000625fb660 RDI = 0000000015399d68</p><pre> R8 = 0000000000000068 R9 = 00007ffbe21bd718
R10 = 00007ffbe21bd710 R11 = 000000017c02fc60
R12 = 0000000000000000 R13 = 0000000000000000
R14 = 0000000000000000 R15 = 00000000625fb6bc</pre><pre class="language-matlab">RIP = 00007ffbda58349d EFL = 00010246
</pre><pre> CS = 0033 FS = 0053 GS = 002b</pre><p>Stack Trace (from fault):
[ 0] 0x00007ffbda58349d C:\Windows\System32\CompPkgSup.DLL+00013469 UnregisterServerForPMP+00001085
[ 1] 0x00007ffbda58425e C:\Windows\System32\CompPkgSup.DLL+00016990 GetNetworkRequestCount+00000926
[ 2] 0x00007ffbda581d00 C:\Windows\System32\CompPkgSup.DLL+00007424
[ 3] 0x00007ffbda581892 C:\Windows\System32\CompPkgSup.DLL+00006290
[ 4] 0x00007ffbda5819a9 C:\Windows\System32\CompPkgSup.DLL+00006569
[ 5] 0x00007ffbe12b8364 C:\WINDOWS\System32\KERNEL32.DLL+00033636 BaseThreadInitThunk+00000020
[ 6] 0x00007ffbe25270d1 C:\WINDOWS\SYSTEM32\ntdll.dll+00422097 RtlUserThreadStart+00000033</p><p>If this problem is reproducible, please submit a Service Request via:
<a href = "http://www.mathworks.com/support/contact_us/">http://www.mathworks.com/support/contact_us/</a></p><p>A technical support engineer might contact you with further information.</p><p>Thank you for your help.</p>PUNIT BANSALhttps://nl.mathworks.com/matlabcentral/profile/authors/2875612-punit-bansaltag:nl.mathworks.com,2005:Question/3306692017-03-19T12:50:38Z2017-03-27T14:03:21ZI can use “phased.SumDifferenceMonopulseTracker”to create a MonoPulse tracker, but how to plot the Sum or Difference beam?<pre class="language-matlab">ha = phased.URA('Size',4);
hstv = phased.SteeringVector('SensorArray',ha);
hmp = phased.SumDifferenceMonopulseTracker2D('SensorArray',ha);
x = step(hstv,hmp.OperatingFrequency,[60.1; 19.5]).';
est_dir = step(hmp,x,[60; 20]);
*_ _I want to see the Sum or Difference beam,how to do?__*
</pre>gaoyuan1238https://nl.mathworks.com/matlabcentral/profile/authors/9964210-gaoyuan1238tag:nl.mathworks.com,2005:Question/3321462017-03-27T14:02:11Z2017-03-27T14:02:11ZSynchronous Demodulation in the Presence of Noise matlab code<p>1. Add the noise variance such that the signal to noise ratio (SNR) of noisy SSB modulated signal is 20 dB.
2. Use noisy upper side frequency band and lower side frequency bands separately for demodulation purpose. If necessary use band pass filter.
3. Sketch noisy SSB modulated signal SSB (t) n(t) and its spectrum.</p><p>4. Sketch the demodulated output</p><p>mˆ (t)</p><p>and its spectrum.</p><p>5. Find the output SNR and corresponding figure of merit.
6. Repeat the above steps for SNR = 10 dB, 30dB and 40dB and compare. Comment on the results.</p>ruffuddeen bashahttps://nl.mathworks.com/matlabcentral/profile/authors/10026819-ruffuddeen-bashatag:nl.mathworks.com,2005:Question/3316962017-03-24T09:09:12Z2017-03-27T14:00:55ZCode for connecting two Simscape blocks <p>I am trying to connect two Simscape blocks.
My first step is to get the corresponding handles for both blocks with e.g.</p><p>>> A=get_param('Pressure/FixedOrifice','LineHandles')</p><p>and analog for the second block.</p><p>Then I try to connect the blocks via</p><p>>> add_line(A.RConn(1,2),B.LConn(1,2))</p><p>since the blocks have more than one RConn/LConn. This gives me an error. How do I adress the ports correctly?</p><p>Thank you for your help.</p>Alicia Roderhttps://nl.mathworks.com/matlabcentral/profile/authors/9877992-alicia-rodertag:nl.mathworks.com,2005:Question/3321452017-03-27T13:58:55Z2017-03-27T13:58:55Zskew detection and correction<p>i have an image like below and i want to detect and correct the skew can anyone help me?
<a href = "</matlabcentral/answers/uploaded_files/73516/skew.jpg"></matlabcentral/answers/uploaded_files/73516/skew.jpg</a>></p>oza sanhttps://nl.mathworks.com/matlabcentral/profile/authors/9868204-oza-santag:nl.mathworks.com,2005:Question/3320682017-03-27T05:24:10Z2017-03-27T13:54:14Zfigure not coming up<p>I have written a code in which i have created a rectangular surface using patch command and i m rotating this surface about z axis using the angles i get from my mobile's gyro using udp object.But as irun the code no errors show up but also there is no figure coming up.My code is</p><pre> instrreset</pre><pre class="language-matlab">a=[1 ,-1 ,-1, 1, 1];
b=[1 ,1 ,-1, -1,1];
z=zeros(1,5);
x=zeros(1,5);
y=zeros(1,5);
</pre><p>%Creating UDP object
UDPComIn=udp('192.168.173.154','LocalPort',12345);
set(UDPComIn,'DatagramTerminateMode','off')</p><pre class="language-matlab">while 1
</pre><pre> fopen(UDPComIn);
csvdata=fscanf(UDPComIn);
scandata=textscan(csvdata,'%s %f %f %f %f %f','Delimiter',',');
data=[scandata{4},scandata{5},scandata{6}];</pre><pre class="language-matlab">fclose(UDPComIn);
alph=data(1);
</pre><pre> for i=1:1:4
t1=[cosd(alph) ,(-sind(alph));sind(alph) ,cosd(alph)];
k=[a(i); b(i)];
m=t1*k;
x(i)=m(1);
y(i)=m(2);
x(5)=x(1);
y(5)=y(1);
end</pre><pre> view(3);</pre><p>patch(x',y',z');</p><pre> xlabel('XXX');
ylabel('YYY');
zlabel('ZZZ');</pre><pre class="language-matlab">k=k+1;
%CodeEnd
end
</pre><p>but when i run the same patch command while not receiving data from udp just giving angles through for loop it shows no error and figure is also visible.Can anyone plz help me with this problem?</p>taher azimhttps://nl.mathworks.com/matlabcentral/profile/authors/6755192-taher-azimtag:nl.mathworks.com,2005:Question/3321152017-03-27T10:28:59Z2017-03-27T13:54:07Zmimo channel block is found in which matlab version<p>hii,
Can you please help me to find the matlab version which has a mimo channel block in it.I am using matlab 2013 version .It dosen't have mimo channel in it.</p>ammu chandranhttps://nl.mathworks.com/matlabcentral/profile/authors/8767292-ammu-chandrantag:nl.mathworks.com,2005:Question/3321132017-03-27T10:21:51Z2017-03-27T13:52:59ZDifference between Download Installer and Download MATLAB software version ?<p>If I need to install and activate MATLAB software in my PC, do I need to download only the 'Installer' (option in Install and Activate tab) or I need to download the requisite MATLAB version software first, and then the installer ?</p>Ashwin Anil Kumarhttps://nl.mathworks.com/matlabcentral/profile/authors/6976322-ashwin-anil-kumartag:nl.mathworks.com,2005:Question/3319882017-03-26T14:37:01Z2017-03-27T13:51:35ZHello, could anyone help me? I have problem to synchronize zoom in a GUI:<p>How to do this with different axes in a GUI, not with subplot.</p><pre class="language-matlab">figure
ax1 = subplot(2,1,1);
RGB = imread('peppers.png');
I = rgb2gray(RGB);
imshow(I);
ax2 = subplot(2,1,2);
RGB = imread('peppers.png');
imshow(RGB);
linkaxes([ax1,ax2],'xy')
</pre>Denilsonhttps://nl.mathworks.com/matlabcentral/profile/authors/5901095-denilsontag:nl.mathworks.com,2005:Question/3321432017-03-27T13:51:25Z2017-03-27T13:51:25ZHow to do a semi-manual segmentation of a tumor from ultrasound 3D data?<p>How to do a semi-manual segmentation of a tumor from ultrasound 3D data? Until now I was using freehand to outline tumor on every slice (around 50 of them per tumor) but it is very time consuming. I'm looking for a method which based on couple of freehand drawn outlines will approximate tumor throughout the rest of the slices. I will appreciate any help with that.</p>Agnieszka Drzalhttps://nl.mathworks.com/matlabcentral/profile/authors/9405736-agnieszka-drzaltag:nl.mathworks.com,2005:Question/3321422017-03-27T13:51:19Z2017-03-27T14:09:28ZHow to plot reference lines of a slope in matlab?<p>I am solving a ode numerically I also plot discrete L2 norm in order to check the convergence of my numerical scheme now i want to plot reference line for slope 2,3 in my figure so that one can see the convergence of numerical solution to the exact one. is there some one to tell me the solution. I also attached my convergence plot here.</p><p>Thanks in advance.</p>Bibigulhttps://nl.mathworks.com/matlabcentral/profile/authors/4105093-bibigultag:nl.mathworks.com,2005:Question/2859532016-05-26T14:20:18Z2017-03-27T13:45:57ZI am getting exceptions every time I start up Matlab 2016b or save a file: Undefined function or variable 'rmiml.visibleInToolstrip'.<p>There are no other exceptions, but this is listed 6 or 7 times.</p><p>"Undefined function or variable 'rmiml.visibleInToolstrip'."</p>eashehttps://nl.mathworks.com/matlabcentral/profile/authors/4024611-eashetag:nl.mathworks.com,2005:Question/3321412017-03-27T13:44:58Z2017-03-27T13:44:58ZPolyphase channeliser for FDM<p>Please find the attached word file and in that I have explained each detail please give advice on that thanks.</p><p>anyone can guide on this how to proceed on this polyphase filter requirement.</p><p>aim is to generate a 50 channel FDM separated by 192kHz centers containing symbols modulated at 128 kHz by square root nyquist filters with 50 percent excess bandwidth
so task is to baseband channelizer all 50 channels and output data samples from ach channels at 256 ks/s which is two samples per symbol</p>MANISH SINGHhttps://nl.mathworks.com/matlabcentral/profile/authors/4580036-manish-singhtag:nl.mathworks.com,2005:Question/1254422014-04-11T16:56:46Z2017-03-27T13:44:58ZI am going to classify multispectral remote sensing image using SVM . <p>I have written a code for classifying three crops using SVM training , The three crops are cotton ,wheat and gram. Now to get more accuracy I want to optimize the training data using genetic algorithm then I wish to train the optimized data using SVM train and then want the classification result . First want to compare the result with simple SVM algorithm , I am attaching the codes here please help me to correct that code so that i could get the better kappa coefficient .ore if u suggest some other parameters of comparison of two techniques . One more thing is please suggest me how to use kernels in SVMtrain instruction ..!</p>Priyanka Athawalehttps://nl.mathworks.com/matlabcentral/profile/authors/4641532-priyanka-athawaletag:nl.mathworks.com,2005:Question/3313592017-03-22T19:03:02Z2017-03-27T13:36:34ZIs there any way to get a list of variables required for simulating a Simulink model?<p>I want to get a list of variables needed to run a Simulink simulation, for documentation purposes.</p>Damon Delorenzishttps://nl.mathworks.com/matlabcentral/profile/authors/6122529-damon-delorenzistag:nl.mathworks.com,2005:Question/766152013-05-22T09:15:11Z2017-03-27T13:34:05ZCopyfile with long path names<p>There seems to exist a limitation for the length of the file path when using the copyfile-command (something like 260 characters), because I get an 'Unknown error' when I want to copy to a destination with a longer path.</p><p>This seems to be related to a problem with the Windows copy+paste command (because I cannot even manually copy the files to that location). I googled the problem and it seems that there exist some workarounds for manual copy+paste. Do you know of any workarounds for this problem in Matlab?</p><p>My system:
Windows 7 64-bit
Matlab R2013a</p>Christophhttps://nl.mathworks.com/matlabcentral/profile/authors/3362221-christophtag:nl.mathworks.com,2005:Question/3321302017-03-27T13:03:44Z2017-03-27T14:36:32ZWorkaround for initial high memory usage?<p>I'm currently working on a master thesis in statistical mechanics where I'm looking at the 3D ising model. This uses the Metropolis Monte Carlo methods, and I generate quite alot of data. My problem is that when computing on my university's cluster, the initial memory usage, which can be of order 2GB (6%), really dampens how many cores I can use without blocking others out from the cluster. But after some time, the memory usage drops down to 1%. Is there a way to not spike the memory usage in the beginning of the script? Maybe something like running a small system in order to have the routines set up before embarking on a large system?</p><p>Cheers!</p><p>EDIT: Been asked to submit code, so it is found below. I have not shown every function, but below the script are the functions that handles most of the data.</p><pre class="language-matlab">clear variables
close all
%Constants (boltzmann constant set to k = 1)
%Following sets are as follows: [Jz,Jz',J1,J2], negative signs = AFM
JKobayashi = [0.6015,0,-0.0508,-0.038];
JCabrera1 = [2.19,-0.29,-0.031,0.77*0.031];
JCabrera2 = [2.4,-0.36,-0.036,0.75*0.036];
Jsets = [JKobayashi/JKobayashi(1);JCabrera1/JCabrera1(1);JCabrera2/JCabrera2(1)];
Temp = [0.1,0.15,linspace(0.2,0.8,100),linspace(0.85,2.0,10)]; %Temperature measured in units of J [K];
Sweeps = 400000; %Number of sweeps done for measurements
NBoot = 100; %Number of means calculated in error analysis
EquilibriumTime = 25000; %Twice the number of sweeps before equilibrium
UseSet = 2;
</pre><pre class="language-matlab">Constants = Jsets(UseSet,:);
LatticeSize = 16; %Specifying the lattice as a LatticeSize X LatticeSize X LatticeSize
</pre><pre class="language-matlab">%colors = ["red";"blue";"green";"black";"cyan";"magenta"];
</pre><pre class="language-matlab">States = zeros(LatticeSize,LatticeSize,LatticeSize,length(Temp));
[E,E2,M,M2,Mabs,M4,HeatCap,MagSus,...
SEHeatCap,SEMagSus,SEMag,SEMagAbs,Corrtimes]=...
deal(zeros(length(Temp),1));
</pre><pre class="language-matlab">parfor i=1:length(Temp)
%Setting up a random state
rng(123)
IsingState = (rand(LatticeSize,LatticeSize,LatticeSize) > 0.5)*2-1;
</pre><pre> %Equilibration of the random state
IsingState = ...
Equilibration(IsingState,Constants,Temp(i),EquilibriumTime*LatticeSize^3);</pre><pre> %Metropolis
[MagnetizationArray,EnergyArray,IsingState]=...
Metropolis(IsingState,Constants,Temp(i),Sweeps);
States(:,:,:,i) = IsingState;</pre><pre> %Calculating the correlation time and gathering uncorrelated
%measurements
[EnergyArray,MagnetizationArray,Corrtimes(i)] = ...
Measurements(EnergyArray,MagnetizationArray,EquilibriumTime);</pre><pre> %Calculating means and standard error in the means
[ E(i),E2(i),M(i),M2(i),Mabs(i),M4(i),HeatCap(i),...
MagSus(i),SEHeatCap(i),SEMagSus(i),SEMag(i),SEMagAbs(i) ] =...
Observables(EnergyArray,MagnetizationArray,Temp(i),NBoot,LatticeSize);</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">titles = ...
{sprintf('Kobayashi %gx%gx%g %g',LatticeSize,LatticeSize,LatticeSize,Sweeps)...
,sprintf('Cabrera et al 1 %gx%gx%g %g',LatticeSize,LatticeSize,LatticeSize,Sweeps)...
,sprintf('Cabrera et al 2 %gx%gx%g %g',LatticeSize,LatticeSize,LatticeSize,Sweeps)};
figure(1)
subplot(2,2,1)
errorbar(Temp,HeatCap,SEHeatCap,'O')
xlabel('kT/J')
ylabel('C_v(T)')
title('Heat Capacity')
subplot(2,2,2)
errorbar(Temp,MagSus,SEMagSus,'O')
title('Magnetic Susceptibility')
xlabel('kT/J')
ylabel('chi(T)')
subplot(2,2,3)
errorbar(Temp,M,SEMag,'O')
title('Magnetization')
xlabel('kT/J')
ylabel('Magnetization')
subplot(2,2,4)
errorbar(Temp,Mabs,SEMagAbs,'O')
title('|Magnetization|')
xlabel('kT/J')
ylabel('|Magnetization|')
suptitle(char(titles(UseSet)))
saveas(figure(1),char(titles(UseSet)))
save(char(titles(UseSet)))
% figure()
% LatticePlot(States(:,:,:,15))
% view(0,87)
</pre><p>Metropolis, Observables, Measurements:</p><pre class="language-matlab">function [ MagnetizationArray,EnergyArray,IsingState ]...
= Metropolis( IsingState,J,Temp,Sweeps )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
Emptymatrix = zeros(10,1);
LatticeSize = length(IsingState);
Magnetization = sum(sum(sum(IsingState)));
Energy = -sum(sum(sum(IsingState.*...
(J(4)*(circshift(IsingState,[1,0,0])...
+circshift(IsingState,[-1,0,0])...
+circshift(IsingState,[-1,-1,0])...
+circshift(IsingState,[1,1,0]))...
+J(3)*(circshift(IsingState,[0,1,0])...
+circshift(IsingState,[0,-1,0]))...
+J(1)*(circshift(IsingState,[0,0,-1])...
+circshift(IsingState,[0,0,1]))...
+J(2)*(circshift(IsingState,[0,0,-2])...
+circshift(IsingState,[0,0,2]))...
))))/2;
State = IsingState;
EnergyArray = zeros(Sweeps,1);
MagnetizationArray = zeros(Sweeps,1);
for l = 1:Sweeps
spinsites = randi(LatticeSize^3,LatticeSize^3,1);
randomprob = rand(LatticeSize^3,1);
for j =1:LatticeSize^3
DeltaE = EnergyDifference( IsingState,J,spinsites(j),Emptymatrix,LatticeSize);
if DeltaE <= 0 || exp(-DeltaE/Temp) >= randomprob(j)
IsingState(spinsites(j)) = -IsingState(spinsites(j));
Energy = Energy + DeltaE;
Magnetization = Magnetization...
+2*IsingState(spinsites(j));
end
State = State + IsingState;
end
EnergyArray(l) = Energy;
MagnetizationArray(l)= Magnetization;
end
IsingState = (State/(Sweeps*LatticeSize^3+1)>zeros(LatticeSize,LatticeSize,LatticeSize))...
+ (State/(Sweeps*LatticeSize^3+1)<zeros(LatticeSize,LatticeSize,LatticeSize))*(-1);
%MagnetizationArray = abs(MagnetizationArray)/LatticeSize^3;
end
</pre><pre class="language-matlab">function [ E,E2,M,M2,Mabs,M4,HeatCap,...
MagSus,SEHeatCap,SEMagSus,SEMag,SEMagAbs ] =...
Observables( Energy,Magnetization,Temp,NBoot,LatticeSize)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
E = mean(Energy);
E2 = mean(Energy.^2);
M = mean(Magnetization);
M2 = mean(Magnetization.^2);
Mabs = mean(abs(Magnetization));
M4 = mean(Magnetization.^4);
</pre><pre class="language-matlab">HeatCap = 1/(LatticeSize^3*Temp^2)*(E2-E^2);
MagSus = 1/(LatticeSize^3*Temp)*(M2-M^2);
SEHeatCap = ErrorHeatCap(Energy,NBoot,LatticeSize,Temp);
SEMagSus = ErrorMagSus(Magnetization,NBoot,LatticeSize,Temp);
</pre><pre class="language-matlab">M = M/LatticeSize^3;
Mabs = Mabs/LatticeSize^3;
SEMag = ErrorMag(Magnetization,NBoot,LatticeSize);
SEMagAbs = ErrorMag(abs(Magnetization),NBoot,LatticeSize);
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">function [ SEHeatCap ] = ErrorHeatCap(Energy,Nboot,LatticeSize,Temp)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n = length(Energy);
HeatCapTemp = zeros(Nboot,1);
for i = 1:Nboot
j = randi(n,1,n);
Etemp = Energy(j);
E = mean(Etemp);
E2 = mean(Etemp.^2);
HeatCapTemp(i) = 1/(LatticeSize^3*Temp^2)*(E2-E^2);
end
SEHeatCap = sqrt(mean(HeatCapTemp.^2)-mean(HeatCapTemp)^2);
end
</pre><pre class="language-matlab">function [SEMagsus] = ErrorMagSus(Magnetization,Nboot,LatticeSize,Temp)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n = length(Magnetization);
MagSusTemp = zeros(Nboot,1);
for i = 1:Nboot
j = randi(n,1,n);
Mtemp = Magnetization(j);
M = mean(Mtemp);
M2 = mean(Mtemp.^2);
MagSusTemp(i) = 1/(LatticeSize^3*Temp)*(M2-M^2);
end
SEMagsus = sqrt(mean(MagSusTemp.^2)-mean(MagSusTemp)^2);
end
</pre><pre class="language-matlab">function [ SEMag ] = ErrorMag( Magnetization,Nboot,LatticeSize )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n = length(Magnetization);
Magtemp = zeros(Nboot,1);
for i = 1:Nboot
j = randi(n,1,n);
Magtemp(i) = mean(Magnetization(j))/LatticeSize^3;
end
SEMag = sqrt(mean(Magtemp.^2)-mean(Magtemp)^2);
end
</pre><pre class="language-matlab">function [ EnergyArray,MagnetizationArray,CorrTime ] = Measurements( Energy,Magnetization,EquilibriumTime )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
Sweeps = length(Magnetization);
CorrFunc = autocorr(Magnetization,Sweeps-1);
zerocorr = find(CorrFunc<0,1);
</pre><pre class="language-matlab">if isempty(zerocorr)==1
CorrTime = 1;
elseif zerocorr >= EquilibriumTime/2
CorrTime = 2*ceil(trapz(...
CorrFunc(1:EquilibriumTime/2)));
else
CorrTime = 2*ceil(trapz(...
CorrFunc(1:zerocorr)));
end
</pre><pre class="language-matlab">if isnan(CorrTime)==1
CorrTime = 1;
end
EnergyArray = Energy(1:CorrTime:Sweeps);
MagnetizationArray = Magnetization(1:CorrTime:Sweeps);
</pre><pre> end</pre>Aleksander Selandhttps://nl.mathworks.com/matlabcentral/profile/authors/9723662-aleksander-selandtag:nl.mathworks.com,2005:Question/3321402017-03-27T13:31:43Z2017-03-27T14:28:17ZHow to display MAPE in gui? <p>for example value for mape is 50:</p><p>mape = 50;
set(handles.text10,'String','MAPE = '+mape_2);</p><p>In GUI I have lot of different values, but I need only one value - 50.
Please I need help!</p><p>and mape as text is not here too. I have only this on my gui - picture</p>Dominika Fedorováhttps://nl.mathworks.com/matlabcentral/profile/authors/6324639-dominika-fedorovatag:nl.mathworks.com,2005:Question/3321392017-03-27T13:31:00Z2017-03-27T13:48:37Zhow can i use a neural network inside knn?<p>i'm using Knn to segment an image and separate pixels into 3 clusters, after that, i wanna detect the infected region in the leaf of olive (my image is an olive leaf) automatically without humain intervention. So, should i use a neural network inside the Knn, (i don't know if that's possible),or does someone have another idea?
thank you</p><img src = "/matlabcentral/answers/uploaded_files/73514/Sans%20titrem.png">mahmoud ghorbelhttps://nl.mathworks.com/matlabcentral/profile/authors/8420041-mahmoud-ghorbeltag:nl.mathworks.com,2005:Question/3321032017-03-27T09:19:50Z2017-03-27T13:30:58ZCell in cell in cell...... versus multiDimensional cell<p>Hi all,</p><p>Imagine now I have some data to be stored, say there are 24 matrices I need to store. I have 2 choices:</p><p>1. use cell in cell, e.g.</p><pre class="language-matlab">>> a
a =
{3x1 cell}
{3x1 cell}
>> a{1}
ans =
{4x1 cell}
{4x1 cell}
{4x1 cell}
>> a{1}{1}
ans =
[]
[]
[]
[]
</pre><p>2. use a multiDimensional cell, e.g.</p><pre class="language-matlab">>> a = cell(2, 3, 4)
a(:,:,1) =
[] [] []
[] [] []
a(:,:,2) =
[] [] []
[] [] []
a(:,:,3) =
[] [] []
[] [] []
a(:,:,4) =
[] [] []
[] [] []
</pre><p>and store each matrix in each cell element.</p><p>Which one is better and why? Personally I like the second way because it's clearer. The first way always confuses me.</p>Xh Duhttps://nl.mathworks.com/matlabcentral/profile/authors/6684822-xh-dutag:nl.mathworks.com,2005:Question/3236232017-02-06T17:21:42Z2017-03-27T13:28:03ZHow to increase the speed of a FOR loop?<p>Hi,
I have a problem with few lines of a for loop. It seems that it takes forever to finish. After one hour of waiting the for loop wasn't executed to the end, so I interrupted it manually.
Also some variables within the loop are to big in size, one of them is class double 558082904 bytes and one is struct array of 4646641536 bytes in size.
After this loop finishes I should have one 20x1 struct arrays with 4 fields. Each field is a matrix 33x20001x11.
The other struct array is 20x1 with one field that is also 33x20001x11.</p><p>This is the code</p><pre> for p = 1:nPop</pre><pre> for i=2:n</pre><pre> for j = 1:length(beam_transverse);</pre><pre> %Effective loads
EffectiveLoad(p).Pe(:,i,j) = ImpactForce(:,i-1) + theta * ...
(ImpactForce(:,i)-ImpactForce(:,i-1)) + MASS_EB_W *...
(a0*ResponseVar(p).displ(:,i-1,j) + a2*ResponseVar(p).vel(:,i-1,j)...
+ 2*ResponseVar(p).acc(:,i-1,j)) + DAMPING_PSO(p).DAMPING_EBW_SD*(a1*...
ResponseVar(p).displ(:,i-1,j) + 2*ResponseVar(p).vel(:,i-1,j) + ...
a3*ResponseVar(p).acc(:,i-1,j));</pre><pre> ResponseVar(p).dispth(:,i,j)=EffectiveStiff(p).Ke\EffectiveLoad(p).Pe(:,i,j);</pre><pre> %Calculate the displacements, velocities and accelerations at time t+dt.
%Calculate the reponse for every hammer impact</pre><pre> %Accelerations
ResponseVar(p).acc(:,i,j) = a4*(ResponseVar(p).dispth(:,i,j) - ResponseVar(p).displ(:,i-1,j)) + ...
a5*ResponseVar(p).vel(:,i-1,j) + a6*ResponseVar(p).acc(:,i-1,j);</pre><pre> %Velocity
ResponseVar(p).vel(:,i,j) = ResponseVar(p).vel(:,i-1,j) + a7*(ResponseVar(p).acc(:,i,j)...
+ ResponseVar(p).acc(:,i-1,j));</pre><pre> %Displacements
ResponseVar(p).displ(:,i,j) = ResponseVar(p).displ(:,i-1,j) + dt*...
ResponseVar(p).vel(:,i-1,j) + a8*(ResponseVar(p).acc(:,i,j) + 2*ResponseVar(p).acc(:,i-1,j));</pre><pre> end</pre><pre> end</pre><pre> end</pre><p>nPop is 20, n is 20001 and j is 11.</p><p>I am not sure that this loop is the best way of formulating my problem.
Do you have any suggestions to formulate this in a different way to avoid the indefinite time for calculation to finish?</p><p>Thanks in advance!</p>EBhttps://nl.mathworks.com/matlabcentral/profile/authors/6704537-ebtag:nl.mathworks.com,2005:Question/3321382017-03-27T13:27:14Z2017-03-27T13:27:14ZWhat is the relationship between the version of MATLAB,CUDA and VS?<p>In the win8 system, my matlab version is 2014a, the CUDA version is 8.0, the VS version is 2015, the matlab program report an error when using the GPU acceleration.The error is "CUDA_ERROR_LAUNCH_TIMEOUT". I would like to ask whether the version of MATLAB,CUDA and VS is right,if the answer is no, how should I select them?</p><img src = "/matlabcentral/answers/uploaded_files/73512/1.png">tong zhanghttps://nl.mathworks.com/matlabcentral/profile/authors/10026492-tong-zhangtag:nl.mathworks.com,2005:Question/3320812017-03-27T07:10:21Z2017-03-27T13:24:55Zwhy dosen't this work ? i need a (:,4) cell. but 90 % of my result is empty spaces.<pre class="language-matlab">PLS = [PIDSorted; NameSorted; ExamSorted; DateSorted];
</pre><pre class="language-matlab">NewPL = cell(size(PLS,1),4); %Patients sorted
</pre><pre class="language-matlab">for n=1:size(PLS,1);
</pre><pre> if size(PLS{n,:},1)==1 ;
NewPL{1,n} = PIDSorted(n,:);
NewPL{2,n}= NameSorted{n};
NewPL{3,n}=ExamSorted{n};
NewPL{4,n}=DateSorted{n};
end
end </pre><p>I tried to use NewPL = NewPL(~cellfun('isempty',NewPL))
but then I have my result in only one column</p>Annehttps://nl.mathworks.com/matlabcentral/profile/authors/3046744-annetag:nl.mathworks.com,2005:Question/3321112017-03-27T10:06:27Z2017-03-27T13:23:15ZWhy using textscan, if i use more than 4 columns, i get the first 4 columns with 2301 rows and the rest with 2300?<p>This is the code:</p><pre class="language-matlab">clc; clear all;
</pre><pre class="language-matlab">nt=2;
dname=uigetdir('C:\Users\"user"\Downloads\');
dname=[dname,'\'];
files=dir([dname,'*.csv']);
</pre><pre> file=[dname, files(1).name];</pre><pre> fid = fopen(file,'r') ;
I=textscan(fid,'%s %s %s %s %s %s %s','delimiter',',');
fclose(fid);</pre><p>The file is the P1_T2 in the attach.</p><p>Thank You</p>joao ribashttps://nl.mathworks.com/matlabcentral/profile/authors/10028310-joao-ribastag:nl.mathworks.com,2005:Question/3320382017-03-26T22:01:16Z2017-03-27T13:23:00ZHow do i clean the image<p>I would like to now how do you clean this image. Which filters do i need to use to stay only with the QR codes and bar codes intact.</p><p>Can you explain with code please?</p>Luís Sousahttps://nl.mathworks.com/matlabcentral/profile/authors/10025043-luis-sousatag:nl.mathworks.com,2005:Question/3321362017-03-27T13:20:43Z2017-03-27T13:21:50Zproblem with programm that use Newton-Raphson method to solve nonlinear equation system<p>I have to solve a nonlinear equation system with the Newton-Raphson method, and I wrote a code according to a literature. I have tried this code with simply equations, and it works very well. But wenn I use the same code to solve my own equations, here is the problem: the results changed with different precisions(for example 1e-6 and 1e-10) or guess values, and the diefference between the results is very big (1e-3 times). How can I fix that?</p><p>The function to creat the equation system (fun=myfun(g)) is very complicated and very long, I will paste it if it's necessary.</p><pre class="language-matlab">% Jacobi matrix
function dfun=Jacobi(g);
syms U_mn V_mn W_mn phi_xmn phi_ymn
g=[U_mn; V_mn; W_mn; phi_xmn; phi_ymn];
fun=myfun(g);
dfun=[diff(fun,U_mn);diff(fun,V_mn);diff(fun,W_mn);diff(fun,phi_xmn);diff(fun,phi_ymn)];
dfun=conj(dfun');
</pre><pre class="language-matlab">% Newton-Raphson method
clc
clear all
g0=[0.000001 0.000001 0.000001 0.000001 0.000001]; % guess value
eps=1e-6; % precision
it_max=50; % maximal iteration steps
con=0; % convergence
iter=1
for i=1:it_max;
fun=myfun(g0);
dfun=Jacobi(g0);
fun=subs(fun,{'U_mn' 'V_mn' 'W_mn' 'phi_xmn' 'phi_ymn'},{g0(1) g0(2) g0(3) g0(4) g0(5)});
dfun=subs(dfun,{'U_mn' 'V_mn' 'W_mn' 'phi_xmn' 'phi_ymn'},{g0(1) g0(2) g0(3) g0(4) g0(5)});
g=g0-fun/dfun;
if norm(g-g0)<eps
con=1;
break;
end
g0=double(g)
iter=iter+1
end
format long
g=double(g)
</pre>Yanhong Mihttps://nl.mathworks.com/matlabcentral/profile/authors/7197733-yanhong-mitag:nl.mathworks.com,2005:Question/3314372017-03-23T04:30:25Z2017-03-27T13:20:25ZMATLAB takes a long time to run the same code on my laptop compared to my desktop.<p>I'm quite new to MATLAB. I need to tune a PID controller for my project using Differential Evolution algorithm. The code for the same takes about 200 secs to run on my desktop, for 100 generations. (2 secs for 1 gen) The same code on my laptop takes about 1000 secs. (10 secs for 1 gen) though it is very new. What could be the problem? I bought this laptop for educational purposes and obviously I want it to be fast and quick. Here's the specifications of my laptop and desktop:</p><p>Desktop</p><ul><li>2nd Gen. Intel Core i3 2100 @ 3.10 GHz</li><li>4 GB DDR3 RAM</li><li>500 GB HDD</li></ul><p>Laptop</p><ul><li>7th Gen. Intel Core i7 7500U @ 2.70 GHz (base) upto 3.50 Ghz</li><li>12 GB DDR4 RAM</li><li>256 GB NVME PCIe M.2 SSD</li></ul><p>I know desktops are faster than their laptop counterparts. But come on, it's a 7th Gen Core i7 against a 2nd Gen Core i3 and still it loses the battle. Is there something that can be done to decrease the run time?</p><p>Thanks in advance.</p>Brathindara Sureshhttps://nl.mathworks.com/matlabcentral/profile/authors/10001379-brathindara-sureshtag:nl.mathworks.com,2005:Question/2599372015-12-11T19:39:13Z2017-03-27T13:19:53ZCsvwrite a matrix with header<p>Hi,</p><p>I have a huge matrix (3000x3000) and I can write to a csv file with csvwrite('filename', cMatrix);
But I also have a header defined in cellarray of strings as 'cHeader'.
How should I save the matrix with header? In addition, I would also like to transpose the cHeader
array to be the first column of the matrix. Is that possible?</p><p>Thanks,</p><p>Jennifer</p>JFzhttps://nl.mathworks.com/matlabcentral/profile/authors/6201072-jfztag:nl.mathworks.com,2005:Question/3319162017-03-25T20:28:32Z2017-03-27T13:18:44ZPlotting from a mat file<p>I need to plot some data which is contained within the mat file Podaci.mat that is attached. The file contains 7 structures,each one is a different type of measurement. Structures are 6332x25(5). Now i need to plot all of those 6332 data(for all 7 structures,data in their fifth column),where on the y-axis there will be those data and on the x-axis dates,from 1991 to 2008. Can anybody help me?</p>Emil Eterovichttps://nl.mathworks.com/matlabcentral/profile/authors/9561878-emil-eterovictag:nl.mathworks.com,2005:Question/3319752017-03-26T12:52:01Z2017-03-27T13:18:32ZHow to read image data sets from a folder at once ?<p>Hello. I have 40 datasets in a folder in C drive. I need to convert those files from RGB to grayscale and should resize it but i am unable to read the file and cant convert all the files from RGB to gray at once and cant resize all the images at once and should save the converted and resized images. Can anyone help me with the coding of that please</p>Tousif Ahmedhttps://nl.mathworks.com/matlabcentral/profile/authors/9853263-tousif-ahmedtag:nl.mathworks.com,2005:Question/3321252017-03-27T11:34:17Z2017-03-27T13:17:54ZHow to measure and display the difference in colors of two images?<p>Dear community,
I want to analyse and compare the results of chroma keying software (I'm referring to tools used for removing green screens, blue screens etc. in the context of editing/compositing video).
I have two images: One is a reference image (a 'regular' image where no green screen was involved, with static foreground elements and a printed background plate), and a second image, that is a composite and the result of a keying-process trying to mimic the reference image as much as possible (..the background plate will not sit pixel-perfect at the same spot though..)
I am now trying to find ways to measure and display how close the two images are in terms of colors in certain relevant areas – meaning especially on the edges where foreground objects transition into the background (like e.g. a strand of hair or clothes transitioning into the background).
Because of the two pictures not being aligned pixel-perfect (..but close to..), I think I have to somehow calculate mean/average deviations..
I would be hugely grateful for any kind of ideas, workflow tips, tips for tools, etc. on how to best tackle this problem. Or maybe even a whole other approach..? Thanks very much in advance!
Sebastian</p>Sebastianhttps://nl.mathworks.com/matlabcentral/profile/authors/10028900-sebastiantag:nl.mathworks.com,2005:Question/3321352017-03-27T13:16:57Z2017-03-27T13:16:57ZEdge detection and counting of PWM Signal using matlab Package for Arduino<p>Hello,</p><p>I am programming the arduino using Matlab with <b>MATLAB Support Package for Arduino Hardware</b>, I want to count the number of falling edges that comes from a flow sensor (PWM Signal 2.500 Pulses <a href = "--">--</a> 1 L), i need to know how to detect the edge and how use the Interrupt, so i can limit my interval and do the counting.</p>Mohamed Amine Msalmihttps://nl.mathworks.com/matlabcentral/profile/authors/9603104-mohamed-amine-msalmitag:nl.mathworks.com,2005:Question/3321342017-03-27T13:15:07Z2017-03-27T13:15:07ZSend PWM Signal and change Duty Cycle, Arduino with Matlab, serial communication<p>Hello,</p><p>I am programming the arduino using Matlab with <b>the Serial communication</b>, I want to send a PWM signal to several pins and change the duty cycle, i can't use the Arduino package for Matlab because i need the interrupt and the edge detection fonctions. So can you please help me!!!</p>Mohamed Amine Msalmihttps://nl.mathworks.com/matlabcentral/profile/authors/9603104-mohamed-amine-msalmitag:nl.mathworks.com,2005:Question/3321332017-03-27T13:13:47Z2017-03-27T13:13:47Zremove background and unwanted area<p>I am interested in removing background from the image, as i only want tyre part, that is the full tyre, and remove everything else from image. Below attached is the image.</p><img src = "/matlabcentral/answers/uploaded_files/73508/WhatsApp%20Image%202017-03-27%20at%206.33.22%20PM.jpeg">Ayush https://nl.mathworks.com/matlabcentral/profile/authors/6593495-ayushtag:nl.mathworks.com,2005:Question/3321322017-03-27T13:07:00Z2017-03-27T13:07:00ZHow can I design a cascaded IIR bandpass butterworth filter for my data x?<p>I have data with the intention to filter them offline. I would like to apply a cascaded IIR bandpass butterworth filter. I have a Fs of 5000 and would like to filter low pass (12 Hz) and high pass (10 Hz), order is 3. If I am correct, I have to use the sosfilt function?
My current code is:</p><p>[c,b,a] = butter(3,[0.004 0.0048]/(5000/2), 'bandpass');</p><p>sosbp = zp2sos(c,b,a)</p><p>x_filter = sosfilt(sosbp, x);</p><p>However, something is wrong since data are not filtered to the desired cut-off frequencies? Can anyone provide help?</p>Patrick Wiegelhttps://nl.mathworks.com/matlabcentral/profile/authors/10029116-patrick-wiegeltag:nl.mathworks.com,2005:Question/3319182017-03-25T21:02:18Z2017-03-27T13:06:55ZConvert .txt/.mat to .wav format<p>I have a .txt and a .mat file, both containing the same data. I would like to convert either one(whichever is easier) to a .wav file so that I can play the sound and carry out audio processing. I understand 'wavwrite' is one way of doing this but so far I have been unsuccessful.
I have tried:</p><pre class="language-matlab">>> load('data.mat')
>> hfile='data.wav';
>> wavwrite(y, Fs, hfile)
</pre><p>But when I run the code, it displays:</p><pre class="language-matlab">Undefined function or variable 'y'.
</pre><p>Does anyone know the solution to this problem or even an alternative method to convert a .txt/.mat file to .wav? Thanks</p>bilal malikhttps://nl.mathworks.com/matlabcentral/profile/authors/4821130-bilal-maliktag:nl.mathworks.com,2005:Question/3321292017-03-27T13:03:40Z2017-03-27T13:10:58ZIndex exceeds matrix dimensions. Raspi() using Matlab2016a with Raspberry Pi 3, Rasbian linux version 4.4.50-v7+<p>I failed to communicate with my Raspberry Pi 3. When creating raspi object I get the following:</p><p>Index exceeds matrix dimensions.</p><p>Error in raspi/getLEDConfiguration (line 684)
trigger = ret{1};</p><p>Error in raspi/getAvailablePeripherals (line 897)
obj.LED.(id).Trigger = getLEDConfiguration(obj,name);</p><p>Error in raspi (line 202)
getAvailablePeripherals(obj);</p><p>Please advise for the solution..</p>Alexandre Bousaidhttps://nl.mathworks.com/matlabcentral/profile/authors/6972458-alexandre-bousaidtag:nl.mathworks.com,2005:Question/3318752017-03-25T14:14:33Z2017-03-27T13:06:13ZHow to read data/number from dynamically added text boxes by 'for' loop using GUI ?<p>I have created a GUI which dynamically (during the run time) adds text boxes on the interface as per the requirement of the user by using 'for' loop. Now, I am interested in writing the values (user entered) from the dynamically added text boxes to Excel sheet by using 'for' loop.
Problem that I am facing is that I am not able to retrieve the data from dynamically added text boxes by using loop..as they don't have tag names to refer.
What shall I do to retrieve the data from dynamically added text boxes?</p><p>Thanks in Advance.</p>Vysser Dhttps://nl.mathworks.com/matlabcentral/profile/authors/8770992-vysser-dtag:nl.mathworks.com,2005:Question/3321312017-03-27T13:03:55Z2017-03-27T13:03:55ZHow to give out the output as an interval in Simulink?<p>Hello,</p><p>how is it possible to give an output as an interval?
For examble, if you have two inputs (x1,x2) and the output y. So if x1=1 and x2=0 then y should represent the interval between 0 and 60 .</p>Hasan Dilekhttps://nl.mathworks.com/matlabcentral/profile/authors/9492870-hasan-dilektag:nl.mathworks.com,2005:Question/3321282017-03-27T13:03:18Z2017-03-27T13:03:18ZReverberator Reverb Time in seconds?<p>Hi all,</p><p>I'm currently trying to implement the MATLAB Reverberator construction to an acoustic calculator that i made.</p><p>However, the values of the reverb are specific to the decay time in seconds, while the Reverberator only accepts 'Real Positive Scalar Values Between 0 and 1.'</p><p>Does anybody know how i is possible to convert my time values to a positive scalar value that will be the correct representation of the reverb time?</p><p>Any help with this would be greatly appeciated!!</p><p>Thanks</p>Tobias Welbyhttps://nl.mathworks.com/matlabcentral/profile/authors/8177890-tobias-welby