https://uk.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-03-27T18:29:46Ztag:uk.mathworks.com,2005:Question/3318922017-03-25T16:48:33Z2017-03-27T18:29:46ZMATLAB timer code, STOP button to clear graph and bar graph whilst having real time data<p>Hello,</p><p>I am new to Matlab and am seeking help regarding stopping a timer function. I apologise in advance if I use the wrong terminology.</p><p>I have both a start and stop button. I have been able to create the timer and both buttons. When I press the start button the timer function begins and starts EEG data following in. I want the timer function to be stopped in another call back, which is the stop button. When I press stop I want the timer to stop.</p><p>I am struggling to code this. Please find attached the code.</p><p>Thanks in advance for any help provided.</p><p>Cheers</p>sufyan patelhttps://uk.mathworks.com/matlabcentral/profile/authors/9170995-sufyan-pateltag:uk.mathworks.com,2005:Question/3313332017-03-22T16:47:19Z2017-03-27T18:27:55ZReal-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://uk.mathworks.com/matlabcentral/profile/authors/4821130-bilal-maliktag:uk.mathworks.com,2005:Question/3318962017-03-25T17:31:24Z2017-03-27T18:26:21ZThe Pitch of signal <p>Hello sir,
According to my knowledge pitch of any signal is nothing but its frequency, so if i keep the same frequency of any signal then the audio that we hear should be same right? While I was working with matlab, what I did is, I kept the frequency same but changed the sampling rate(for the same sinusoid), the result is I got the different sound for 2 different sampling rates. How can that be possible? can you please explain it to me?</p><p>Thank you</p>Nachiket Patkihttps://uk.mathworks.com/matlabcentral/profile/authors/6912172-nachiket-patkitag:uk.mathworks.com,2005:Question/3319482017-03-26T07:08:56Z2017-03-27T18:26:18ZAttempted to access x(3); index out of bounds because numel(x)=2<p>Hi! I'm encountering an error while attempting to do an optimization, the error being this: 'Attempted to access x(3); index out of bounds because numel(x)=2'. I'll put the code below, but i tried looking online with other people who've have had this problem and it seems to occur on their first iteration of a loop. From what I understand, I'm encountering it on the second iteration. Any insight as to what's wrong and how i can fix it would be greatly appreciated!</p><pre class="language-matlab">function f = optimizeSquash(x)
</pre><pre class="language-matlab">f = 400*x(1) + 300*x(2) + 250*x(3);
</pre><pre class="language-matlab">end
</pre><p><i>______________________________________</i></p><pre class="language-matlab">function [c,ceq] = constraintsSquash(x)
</pre><pre class="language-matlab">profit = [60000*x(1) 50000*x(2) 10000*x(3) -900000];
</pre><pre class="language-matlab">units = [1*x(1) 2*x(2) 1*x(3) -50];
</pre><pre class="language-matlab">maint = [2*x(1) 1.5*x(2) 1*x(3) -35];
</pre><pre class="language-matlab">matrix = [profit;units;maint];
</pre><pre class="language-matlab">c = matrix;
</pre><pre class="language-matlab">ceq = [];
</pre><pre class="language-matlab">end
</pre>Samvit Bakhshihttps://uk.mathworks.com/matlabcentral/profile/authors/7826303-samvit-bakhshitag:uk.mathworks.com,2005:Question/3321812017-03-27T18:00:00Z2017-03-27T18:22:48ZProblem in FFT and harmonics analysiation<p>Hi everybody. I am new to analysis field . I have ust started working on Vibration analysis .I got my datas recorded for mislignment of shaft and want to convert these datas to frequency domain.I tried using FFT to get frequency domain using this</p><p>% read data
data = xlsread('Healthy20Hztime');</p><p>%Frequency Analysis</p><p>time = data(:,1); % sampling time</p><p>signal = data(:,2); % signal data in Time-Domain</p><p>L=length(signal); % Length of signal</p><p>Ts=time;</p><p>Fs=20000; % sampling frequency</p><p>NFFT = 2^nextpow2(L); % Next power of 2 from length of y</p><p>Y = fft(signal,NFFT)/L;</p><p>a =2*abs(Y(1:NFFT/2+1));</p><p>f = Fs/2*linspace(0,1,NFFT/2+1);</p><p>figure(1),</p><p>plot(f,2*abs(Y(1:NFFT/2+1))); % Plot single-sided amplitude spectrum.</p><p>grid off</p><p>title(' Healthy 20Hz');</p><p>xlabel('Frequency (Hz)');</p><p>ylabel('|Y(f)|');</p><p>xlim([0 1000]);</p><p>Now I would like to get 1x 2x 3x harmonics of these data . Can somebody help me in getting my codes right as well help me find out the harmonics 1x 2x 3x.</p><p>Thanks</p>s phttps://uk.mathworks.com/matlabcentral/profile/authors/9990666-s-ptag:uk.mathworks.com,2005:Question/1282832014-05-05T07:26:53Z2017-03-27T18:22:32ZVideo compression code working - Please explain the code<pre class="language-matlab">ImFolder=uigetdir;
</pre><pre class="language-matlab">pngFile = dir(strcat(ImFolder,'\*.png'));
</pre><pre class="language-matlab">S = [pngFile(:).datenum];
</pre><pre class="language-matlab">[~,S] = sort(S);
</pre><pre class="language-matlab">pngFiles = pngFile(S);
</pre><pre class="language-matlab">VideoFile=strcat(ImFolder,'\Video');
</pre><pre class="language-matlab">writeObj = VideoWriter(VideoFile);
</pre><pre class="language-matlab">fps= 15;
</pre><pre class="language-matlab">writeObj.FrameRate = fps;
</pre><pre class="language-matlab">open(writeObj);
</pre><pre class="language-matlab">for t= 1:length(pngFiles)
</pre><pre class="language-matlab">Frame=imread(strcat(ImFolder,'\',pngFiles(t).name));
</pre><pre class="language-matlab">writeVideo(writeObj,im2frame(Frame));
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">close(writerObj);
</pre><p>Above is the code i have used to compress the video,</p><p><b>Execution Steps:</b></p><p>1) Initially i recorded a video of 10seconds(Resolution - 160*120) size of video 8mb</p><p>2) I extracted all the frames from the video and saved in a folder</p><p>3) In this step i used above code</p><pre> After executing above code i selected the directory where all the frames had been stored</pre><p>4) After execution i got a video file of size 550Kb and of the same length as the original video</p><p>So original video is reduced to 550kb from 8mb, code is working good for my project, please help me the analyze the above code, how actually the compression is done by the code.</p><p>Thank You</p>naveen Vhttps://uk.mathworks.com/matlabcentral/profile/authors/5012650-naveen-vtag:uk.mathworks.com,2005:Question/3321772017-03-27T17:43:41Z2017-03-27T18:20:51ZNumerical solution of linear ODE involving function defined point-wise<p>I need to solve a differential equation of the form
y'(t)=1/z(t)-y^2 z(t)
where z(t) does not have an analytical form, but is defined point-wise as a list of values. Is there any integrator in Matlab that can handle this direcly?</p>Stefano De Nicolahttps://uk.mathworks.com/matlabcentral/profile/authors/6605985-stefano-de-nicolatag:uk.mathworks.com,2005:Question/3321842017-03-27T18:16:54Z2017-03-27T18:16:54ZHow can I complete summation of variable named matrices in loop?<p>If matrices are variable (1:N) with names s_1:s_N how can I complete summation of the matrices. Below is my current script which errors out for matrix dimensions do not agree. I understand this error and I understand I cannot call matrices using ['s_', num2str(i)] but still not sure how to move forward with summation.</p><p>%% s_1, s_2, s_3, s_4 are all known matrices with values 3500x4 double. Matrices will vary - created 4 just for debugging.</p><pre class="language-matlab">N = 4
</pre><pre class="language-matlab">sumCST1 = zeros(size(s_1));
</pre><pre class="language-matlab">for i = 2:N
</pre><pre> sumCST1 = sumCST1 + ['s_', num2str(i)] </pre><pre class="language-matlab">end
</pre><p>Error using +
Matrix dimensions must agree.</p>Branden Chamnesshttps://uk.mathworks.com/matlabcentral/profile/authors/6441251-branden-chamnesstag:uk.mathworks.com,2005:Question/3321822017-03-27T18:00:22Z2017-03-27T18:14:32ZSpecific timestamp to date format using datetime<p>I have data with a certain timestamp, being yyyymmddHHMM and I want to convert this to time format in matlab:</p><p>For example:</p><p>Given a timestamp of 201502171000 I want to get 2015-02-17 10:00.</p><p>PS: I have to manage a lot of data for a given time unit and my aim is to identify my measurements for that certain time unit. And thats why I thought that time format could be helpful.</p>André Bernal Garcíahttps://uk.mathworks.com/matlabcentral/profile/authors/9854639-andre-bernal-garciatag:uk.mathworks.com,2005:Question/2366892015-08-26T14:43:23Z2017-03-27T18:13:22ZBootstrap wind data to account for autocorrelation and obtain new slope<p>Hi there,</p><p>I have a sample dataset (12783x2) containing the time and wind speed values overs 35 years (6 hour intervals). I have noted that there is a large amount of autocorrelation in the wind data and thus I would like to use bootstrapping re-sampling to perform a new regression on the data with time to find a new slope that describes the long term trend in the wind speeds.</p><p>I have been trying a few options with bootstrap but cannot get my polyfit function to output a new slope for the resampled dataset. Instead I get multiple slopes and intercepts.</p><pre class="language-matlab">bootstrp(1000,@polyfit,test(:,1),test(:,2),1);
</pre><p>I know I am writing this code incorrectly. Any idea how I can just get one new slope of the bootstrapped data?</p><p>I will also like to perform the wblft() function on the data as well to see if the resampled data with bootstrp has a similar distribution to the original.</p>mashtinehttps://uk.mathworks.com/matlabcentral/profile/authors/4739967-mashtinetag:uk.mathworks.com,2005:Question/3321832017-03-27T18:12:26Z2017-03-27T18:14:36ZUseParallel Option with fmincon<p>Hello,</p><p>I am using fmincon to solve a large dimensioned problem (thousands of variables) and want to turn on the 'UseParallel' option to reduce computational time. Currently I supply fmincon with objective and constraint functions (nonlinear equality) as well as the gradients for these two functions. Before I run fmincon I establish a parallel pool on my local machine using parpool('local') which begins a parallel pool connected to two workers. Next, I run fmincon with the "UseParallel" option set to true. When I do this I receive no errors, however I observe no reduction in speed or any other evidence fmincon is actually computing anything in parallel. It was my understanding that by turning this option on fmincon would compute the gradient and constraints in parallel, but this doesn't seem to be happening. Am I misunderstanding something?</p>repritchett92https://uk.mathworks.com/matlabcentral/profile/authors/7985009-repritchett92tag:uk.mathworks.com,2005:Question/430772012-07-09T05:22:28Z2017-03-27T18:11:47ZNumerical approximation of projectile motion with air resistance<p>For a school project, I need to estimate the maximum distance of a projectile without neglecting air resistance. I'm following the procedure outlined here:</p><p><a href = "http://wps.aw.com/wps/media/objects/877/898586/topics/topic01.pdf">http://wps.aw.com/wps/media/objects/877/898586/topics/topic01.pdf</a></p><p>On the second page it shows a nice, step by step process to find a numerical approximation. I am trying to reproduce the trajectory of the baseball that is shown on the last page in order to verify my model. However, the plot shows that the baseball will travel over 100 meters, while my model shows that it will travel about 80. Here is my code:</p><pre class="language-matlab">clear
clc
close all
</pre><pre class="language-matlab">%Constants for Baseball
m=.145 %kg
A=pi*(.0366*2)^2/4 %m^2
C=.5 %Drag Coefficient of a sphere
rho= 1.2 %kg/m^3 (density of air)
D=rho*C*A/2
g=9.81 %m/s^2 (acceleration due to gravity)
</pre><pre> %Initial Conditions
delta_t= .001 %s
x(1)=0
y(1)=0
v=50 %m/s
theta=35 %deg
vx=v*cosd(theta)
vy=v*sind(theta)
t(1)=0 </pre><pre> %Start Loop
i=1
while min(y)> -.001
ax=-(D/m)*v*vx;
ay=-g-(D/m)*v*vy;
vx=vx+ax*delta_t;
vy=vy+ay*delta_t;</pre><pre> x(i+1)=x(i)+vx*delta_t+.5*ax*delta_t^2;
y(i+1)=y(i)+vy*delta_t+.5*ay*delta_t^2;
t(i+1)=t(i)+delta_t;</pre><pre> i=i+1;
end</pre><pre> plot(x,y)
xlabel('x distance (m)')
ylabel('y distance (m)')
title('Projectile Path')</pre><p>If anyone has a few minutes to take a look at this, I'd really appreciate it. I can't seem to find the problem. Thank you!</p>Danhttps://uk.mathworks.com/matlabcentral/profile/authors/1605184-dantag:uk.mathworks.com,2005:Question/3321792017-03-27T17:52:20Z2017-03-27T18:10:49ZGet Color histogram of an image<p>Hi,</p><p>How can I get one color histogram of an image? I don't want three RGB histograms. I want one histogram. X-axis represents the color.</p><p>Thanks!</p>Chen Zhuhttps://uk.mathworks.com/matlabcentral/profile/authors/9872329-chen-zhutag:uk.mathworks.com,2005:Question/3321742017-03-27T17:13:52Z2017-03-27T18:10:32ZCompute correlation of two NaN-containing vectors<p>Hi all! If I need to find the correlation between two NaN-containing vectors by using corrcoef() or corr(), is it possible? How should I set up the parameters? and if not how is it possible to find the correlation between them? Thank you!</p><p>Here are two vectors:</p><img src = "/matlabcentral/answers/uploaded_files/73525/Screen%20Shot%202017-03-27%20at%2012.11.38%20PM.png"><img src = "/matlabcentral/answers/uploaded_files/73526/Screen%20Shot%202017-03-27%20at%2012.11.16%20PM.png">Zhonghao Liaohttps://uk.mathworks.com/matlabcentral/profile/authors/8813880-zhonghao-liaotag:uk.mathworks.com,2005:Question/3252572017-02-15T05:00:00Z2017-03-27T18:04:16ZWhy do I see an "HTTP response code" error in my installer log file when installing the RTL-SDR Support Package?<p>Why can't I install the RTLSDR support package using the add-on manager? I have tried both the online installation and "Download Only" workflows.</p><p>When installing a Support Package, I see the following error:</p><p>There was a problem installing the third-party software. To resolve this issue, contact Technical Support.</p><p>If I look in my MATLAB installer log file, I also see this error:</p><p>HTTP response code: 500 for URL: <a href = "http://sdr.osmocom.org/trac/raw-attachment/wiki/rtl-sdr/RelWithDebInfo.zip">http://sdr.osmocom.org/trac/raw-attachment/wiki/rtl-sdr/RelWithDebInfo.zip</a></p><p> </p>MathWorks Support Teamhttps://uk.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:uk.mathworks.com,2005:Question/3321782017-03-27T17:46:35Z2017-03-27T17:58:52ZHow does one plot a histogram from the histogram counts?<p>I have produced an array of counts, specifically produced with:</p><pre class="language-matlab">histcounts
</pre><p>the reason I do this is because storing the actual data is way to expensive in terms of storage. So on the fly I update my histcount. Now that I have them, how do I plot the histogram?</p><p>----</p><p>demo code:</p><pre class="language-matlab">W_hist_counts = zeros(1,D);
for i=2:iter+1
W = get_vector_we_want_stats(W)
%
W_hist_counts = W_hist_counts + histcounts(W,nbins);
end
</pre>Brando Mirandahttps://uk.mathworks.com/matlabcentral/profile/authors/2706824-brando-mirandatag:uk.mathworks.com,2005:Question/3321802017-03-27T17:54:00Z2017-03-27T17:54:00ZHow can I position the side of a port in simevents<p>In earlier SimEvents Versions (e.g. Matlab R2012) it was possible to position SimEvents Ports on the left or right side of a Subsystem. In R2017a this seems to be not possible, since there are no more special SimEvents Ports, but only the normal IN/OUT Ports. Is there still the possibility to position the Ports of a Subsystem for SimEvents?</p>Lucashttps://uk.mathworks.com/matlabcentral/profile/authors/3141362-lucastag:uk.mathworks.com,2005:Question/3320922017-03-27T08:10:17Z2017-03-27T17:50:51Zhow to perform FFT on multivalued bit string?<p>hi,</p><p>i have a bit string of size 560*1 of values 0 and 1 and some cells contains both 0 and 1 values.. now, i need to apply FFT on this bit string.. to do so, first i need to convert cell values to double values by making use of Cell2mat function (bcz FFT function can be applied on double values only).. so, i used cell2mat function and i applied fft on it... i got wrong results... i.e., if a cell in bit string contains [0,1] ,then after using cell2mat function the values 0 and 1 are being splitted and size of bit string is being increased...</p><p>code for binary string :</p><pre class="language-matlab">new_len = 576;
old_len = length(a);
mapped_index = 1 + mod((1:old_len) - 1, new_len);
b = accumarray( mapped_index(:), a(:), [new_len 1], @(L) {unique(L.')} ) .';
B1=cell2mat(b);
b2=B1';
</pre><p>i got error: undefined function fft for input arguments of type cell...</p><p>Can anyone help me with this..</p>Jyothi Alugoluhttps://uk.mathworks.com/matlabcentral/profile/authors/9669677-jyothi-alugolutag:uk.mathworks.com,2005:Question/3320762017-03-27T06:48:28Z2017-03-27T17:50:40ZHow do I use uicontrol to assign a value to a variable?<p>If i have a uicontrol pushbutton, how do I make it so that when a button is depressed, it changes the value of a variable?</p>Marcus Blackburnhttps://uk.mathworks.com/matlabcentral/profile/authors/8782700-marcus-blackburntag:uk.mathworks.com,2005:Question/3319162017-03-25T20:28:32Z2017-03-27T17:50:27ZPlotting 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://uk.mathworks.com/matlabcentral/profile/authors/9561878-emil-eterovictag:uk.mathworks.com,2005:Question/3321762017-03-27T17:22:30Z2017-03-27T17:48:22ZFind Minimum Value Between a specific column of a matrix and a vector<p>I have a matrix and a vector. The vector which is 24x1 and one which has experimental data being 3678x25. The first column of the experimental data is the time, and the other columns are the corresponding data at each time for different points of interest. I want to find the value in the first column of the 3678x25 matrix which is closest to the desired time, in the vector. I need to do this for every value in the vector.</p><pre class="language-matlab">clear all; close all; clc;
Timex=csvread('timex_ThinWall.csv');
TimeAtHit=csvread('TimeAtHit.csv');
min=zeros(24,1);
difference=zeros(3678,24);
for i=1:24
for j=1:3678
difference(j,i) = (TimeAtHit(i)-Timex(j,1));
end
min(i)=min(difference(:,i));
end
</pre><p>This is how I was originally trying to store these minimum values, but I am encountering indexing errors for the minimum function.</p><p>I also would like to output the index in the difference equation at which this minimum value is achieved if possible.</p><p>Thank you</p>Glenn Hatalahttps://uk.mathworks.com/matlabcentral/profile/authors/9780417-glenn-hatalatag:uk.mathworks.com,2005:Question/3321752017-03-27T17:19:16Z2017-03-27T17:39:12Z the 2nd to 6th digits of the number 'b'. The number 'a': a.=.295651038618078950965228298151082746232326934519155273592235377946274187817593263983741792828764812967993923022255613216311113448416190053443755465698988235432772385156170171830565398<p>I need help</p>Lily Holsthttps://uk.mathworks.com/matlabcentral/profile/authors/10031630-lily-holsttag:uk.mathworks.com,2005:Question/3307772017-03-20T06:10:55Z2017-03-27T17:39:07Zhow to perform Many to one mapping<p>hello,</p><p>i am having a bit string (say 'a') of size 756*1...and another bit string (say b) of size 576*1...now, i want many to one mapping to be performed on this bit string..</p><p>for example: the operation to be performed is shown below</p><pre> b(k)= a(j) j=1....756, k= j mod 576...</pre>Jyothi Alugoluhttps://uk.mathworks.com/matlabcentral/profile/authors/9669677-jyothi-alugolutag:uk.mathworks.com,2005:Question/3320132017-03-26T17:32:13Z2017-03-27T17:36:57Zfind doesn't work with tables<p>hello</p><p>I'm trying to find the index vector of where appears a value in a one column of a table (not an array nor a cell).</p><p>However, "find" gives me the error shown on the snapshot.</p><img src = "/matlabcentral/answers/uploaded_files/73436/error.png"><p>Any ideas</p>Abdelmoumen Bacettihttps://uk.mathworks.com/matlabcentral/profile/authors/2067162-abdelmoumen-bacettitag:uk.mathworks.com,2005:Question/2892152016-06-10T12:23:07Z2017-03-27T17:35:40ZHow to calculate frequency dispersion around median frequency in power spectral density ?<img src = "/matlabcentral/answers/uploaded_files/53995/aa.JPG"><p>Hi,
I need help in finding frequency dispersion around the median frequency. i have plotted the PSD using pwelch. I figured out I can find the median frequency using 'medfreq'. How do I find the frequency dispersion such that 68% of the total power lies in that range. The image shows the type of output I need to calculate. The blue dot represents the median frequency. The blue lines indicate the frequency dispersion such that 68% of the total power lies within the boundaries.
Sampling rate is 30Hz
Data length is around 450 points.
I have zero padded before obtaining fft and psd. I also subtracted the mean from the data before zero padding.
Any help in this regard would be helpful.
Thanks in advance.
Disclaimer : The image belongs to Matthew J.Johnson</p>Habib Alihttps://uk.mathworks.com/matlabcentral/profile/authors/7368148-habib-alitag:uk.mathworks.com,2005:Question/2467902015-10-05T04:28:31Z2017-03-27T17:35:27ZHow to classify brain tumor.<p>Hi, i am working on a project Brian tumor Segmentation and classification, i tried but didn't find a training Dataset for malignant and benign, please help me how to classify and which classifier is best for tumor classification, also if possible please provide me the link to download the Dataset for malignant and benign tumor.
Thanks</p>Muhammad Shoaibhttps://uk.mathworks.com/matlabcentral/profile/authors/6619683-muhammad-shoaibtag:uk.mathworks.com,2005:Question/600062013-01-27T10:00:54Z2017-03-27T17:34:40ZCan i install matlab 2012b on windows 7 32bit?<p>i have windows 7 ultimate N home edition with 32 bit. i want to install matlab 2012b on it. is it possible? because it seems that matlab 2012b support only 64bit os.</p>majidhttps://uk.mathworks.com/matlabcentral/profile/authors/3758773-majidtag:uk.mathworks.com,2005:Question/2964912016-07-20T11:39:09Z2017-03-27T17:22:58Zproblems with matlab windows (both editor and command line windows) when using R2016a on ubuntu 16.04 <p>I'm using matlab R2016a on ubuntu 16.04 (64 bits). I'm having problems with the matlab windows (both editor and command line windows). The problem occurs quite reliably every time I use the debugger.</p><p>In that case, when I write on the command line or just scroll it up and down, overlapped characters and images appear which make it basically unusable (please see attached png).</p><p>There is also a similar problem happening with the editor window: when I use breakpoints, edit the code in the editor window and scroll it up and down, overlapping symbols appear in the "line number" tab (please see attached png; actually I only have one or two breakpoints, all the other symbols are due to the bug).</p><p>I use metacity but I also tried other windows manager for ubuntu (compiz, unity) and the problem persists.</p><p>Thank you for any help</p><p>Screenshots of the command line window:</p><img src = "/matlabcentral/answers/uploaded_files/56401/command_line.png"><p>and</p><img src = "/matlabcentral/answers/uploaded_files/56402/command_line2.png"><p>Screenshots of the editor window:</p><img src = "/matlabcentral/answers/uploaded_files/56403/editor.png">Fabiano Baronihttps://uk.mathworks.com/matlabcentral/profile/authors/6317908-fabiano-baronitag:uk.mathworks.com,2005:Question/3318752017-03-25T14:14:33Z2017-03-27T17:18:42ZHow 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://uk.mathworks.com/matlabcentral/profile/authors/8770992-vysser-dtag:uk.mathworks.com,2005:Question/3305742017-03-18T18:42:16Z2017-03-27T17:18:28ZHow do I plot the nearest neighbour algorithm in a matrix?<p>Hi,</p><p>X = [0 0 0 0 0; 0 0 1 0 0; 0 0 0 0 1]</p><p>I would like to produce a coloured grid that displays the matrix elements equal to one as red. Yellow for the elements at a neighbourhood of 8 connectivity to the non-zero elements and green for the elements further away from 1.</p><p>Should I be using brute force or knnsearch or is there a better/ faster way to go about it?</p><p>Thanks</p>Riah Wilkinsonhttps://uk.mathworks.com/matlabcentral/profile/authors/7418631-riah-wilkinsontag:uk.mathworks.com,2005:Question/3321732017-03-27T17:12:19Z2017-03-27T17:16:09ZHow to substract an image?<p>rgbImage = imread(fullFileName);</p><p>I want to only get the top 20% of the image. How can I do it?</p><p>For example, for this image</p><img src = "/matlabcentral/answers/uploaded_files/73522/0010.jpg"><p>I only want to get</p><img src = "/matlabcentral/answers/uploaded_files/73523/%E6%90%9C%E7%8B%97%E6%88%AA%E5%9B%BE17%E5%B9%B403%E6%9C%8827%E6%97%A51311_4.jpg"><p>Thanks!</p>Chen Zhuhttps://uk.mathworks.com/matlabcentral/profile/authors/9872329-chen-zhutag:uk.mathworks.com,2005:Question/3297072017-03-14T04:06:02Z2017-03-27T17:10:17ZCan anyone explain how MinPeakProminence works in findpeaks?<p>I'm currently working on digital signal processing on PPG signal. Can anyone explain about minpeakprominence. I hace read through the examples given but i still dont have clear idea on that. thanks in advance.</p>Gobala krishnan P Sivaganamhttps://uk.mathworks.com/matlabcentral/profile/authors/9204881-gobala-krishnan-p-sivaganamtag:uk.mathworks.com,2005:Question/3319882017-03-26T14:37:01Z2017-03-27T17:09:03ZHello, 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://uk.mathworks.com/matlabcentral/profile/authors/5901095-denilsontag:uk.mathworks.com,2005:Question/3320342017-03-26T21:15:14Z2017-03-27T17:01:37ZIs 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://uk.mathworks.com/matlabcentral/profile/authors/7566873-bradley-flynntag:uk.mathworks.com,2005:Question/549522012-11-27T16:05:58Z2017-03-27T17:01:12Zfunction superposed epoch analysis<p>Someone has a function to perform superposed epoch analysis?
thank you!!!</p>Erika Meerhoffhttps://uk.mathworks.com/matlabcentral/profile/authors/2788868-erika-meerhofftag:uk.mathworks.com,2005:Question/3321722017-03-27T16:59:54Z2017-03-27T16:59:54Z1.Consider a visible wavelength imaging system that uses an f/4 lens with a focal length of l=15 mm. The focal plane array (FPA) is 1 cm x 1 cm in total size with 5 um pitch detectors. a. What is the angular field of view of the sensor in radians a<p>1.Consider a visible wavelength imaging system that uses an f/4 lens with a focal length of l=15 mm. The focal plane array (FPA) is 1 cm x 1 cm in total size with 5 um pitch detectors.
a. What is the angular field of view of the sensor in radians and in degrees?
b. What is the spatial field of view at 2km?</p>Marwa Ahmeidhttps://uk.mathworks.com/matlabcentral/profile/authors/9494839-marwa-ahmeidtag:uk.mathworks.com,2005:Question/3321712017-03-27T16:59:08Z2017-03-27T16:59:08ZSteps to train a classifier?<p>My project is to detect a specific weed from a corn field. A robot will move inside a corn field, taking video with a Raspberry Pi camera. I have the weed image as "positive" and corn field image as "negative". What are the steps? How do I train a classifier and detect this weed from video?</p>md khanhttps://uk.mathworks.com/matlabcentral/profile/authors/8986386-md-khantag:uk.mathworks.com,2005:Question/3321702017-03-27T16:49:33Z2017-03-27T16:49:33Zcolormap option does not work with imshow in MATLAB 2017a<p>colormap option does not work with imshow in MATLAB 2017a.</p>Vishwa Parekhhttps://uk.mathworks.com/matlabcentral/profile/authors/4191596-vishwa-parekhtag:uk.mathworks.com,2005:Question/3321692017-03-27T16:48:45Z2017-03-27T16:48:45ZR2013a Linux Mint + LibreOffice<p>I am fairly new to matlab and transitioned to linux mint a few days ago.
Whenever i use the xlsread() function on a spreadsheet (does not change whether I use .ods .xlsx or other formats) to import data I get NaN entries for some values. Furthermore it seems that Matlab does not import the whole data set.
I tested this with a .xlsx file containing 70 values dived ed in two columns. When i defined x using x=xlsread('path','','','basic') Matlab showed only every 5th value, starting with the 5th one. The rest was shown as NaN and the values 1-5 didn't even show up. I did exactly the same 1 week ago on a windows PC and everything went just fine. Additionally Matlab wont allow me to import just using the explorer, always telling me: "index exceeds matrix dimensions"</p>f24https://uk.mathworks.com/matlabcentral/profile/authors/10031383-f24tag:uk.mathworks.com,2005:Question/3317792017-03-24T17:16:28Z2017-03-27T16:57:48ZUsing containers.Map as a Class's property<p>I am having a problem in Matlab while using container.Map as a property of a class. I have a class Sensor with one property which is an object of containers.Map. The problem is, I cannot modify this property for one Sensor object without modifying map in other Sensor object. This property looks to be shared among objects of class Sensor. See below for explanation.</p><pre class="language-matlab">classdef Sensor
properties
id
map=containers.Map;
end
end
</pre><pre class="language-matlab">s1=Sensor;
s2=Sensor;
</pre><pre class="language-matlab">s1.map('key1')='value1';
</pre><pre class="language-matlab">s2.map
</pre><p>At this point s2.map also has same content as s1.map.</p><p>Has anyone faced this before or any particular solution. I just changed from table to containers.Map because of the flexibility and speed.</p><p>Thanks
Saurav</p>Sauravhttps://uk.mathworks.com/matlabcentral/profile/authors/5137964-sauravtag:uk.mathworks.com,2005:Question/3321662017-03-27T16:12:34Z2017-03-27T16:40:04ZImporting big data from txt/excel file<p>Hi all,</p><p>I have quite large number of battery test data which contain hundreds of thousands data from each 13 columns (totally million of them). I generally convert them into txt and/or excel. However, when importing the file by using <i>xlsread</i> or <i>import</i>; it takes a few hours.</p><p>I'm looking for a more easy way to import txt or excel file in a shorter time. My purpose is to draw a 2D plot choosing any 2 columns of them.</p>Burak Dermencihttps://uk.mathworks.com/matlabcentral/profile/authors/6679298-burak-dermencitag:uk.mathworks.com,2005:Question/3321582017-03-27T15:19:55Z2017-03-27T16:37:52ZCellfun to extract arrays from multi-dimensional cell<p>Hi all,</p><p>Imagine I have a 2-d cell, each cell element is a m by n matrix, I apply SVD on each element such that they are decomposed into left singular vectors, singular values and right singular vectors. Here's an example:</p><pre class="language-matlab">clear; clc;
</pre><pre class="language-matlab">a = 2;
b = 3;
matL = 5;
matW = 4;
</pre><pre class="language-matlab">myCell = cell(a, b);
</pre><pre class="language-matlab">myCell = cellfun(@(v) rand(matL, matW), myCell, 'UniformOutput', false);
</pre><pre class="language-matlab">[myCellL, myCellSig, myCellR] = ...
cellfun(@(v) svd(v, 'econ'), myCell, 'UniformOutput', false);
</pre><p>Now I'd like to extract the first vector of myCellL, first value of myCellSig, first vector of myCellR, put these into one cell element, and repeat for the second, third...... I can write a loop to do this (continue the above script):</p><pre class="language-matlab">myOtpt = cell(a, b, matW);
</pre><pre class="language-matlab">for i = 1:a
for j = 1:b
for k = 1:matW
myA = myCellL{i, j}(:, k);
myB = myCellSig{i, j}(k, k);
myC = myCellR{i, j}(:, k);
myOtpt{i, j, k} = {myA, myB, myC};
end
end
end
</pre><p>The second part of script (for loops) seems also is a repeat operation on cells 'myCellL, myCellSig, myCellR', is it possible to write these with cellfun, such that for loop is avoided?</p><p>Many thanks!</p>Xh Duhttps://uk.mathworks.com/matlabcentral/profile/authors/6684822-xh-dutag:uk.mathworks.com,2005:Question/3321682017-03-27T16:35:04Z2017-03-27T16:35:04ZIs it possible to make a console application using MATLAB 2015. I have tried it with deploytool but seems like there is no option available for console application, only standalone executable option available.<pre> I have tried it with deploytool but seems like there is no option available for console application, only standalone executable option available.</pre>Zain ul Aabidinhttps://uk.mathworks.com/matlabcentral/profile/authors/2672593-zain-ul-aabidintag:uk.mathworks.com,2005:Question/3320442017-03-26T22:44:53Z2017-03-27T16:35:02Ztake a Neural Network and create a new NN that gives the gradient. <p>I found this function on the file exchange that does what I want but it is no longer compatible with the neural network toolbox functions. <a href = "https://www.mathworks.com/matlabcentral/fileexchange/28415-gradient-from-neural-network/content/Submission/NN_GradientFunction.m">FEX function</a></p><p>Ideas on how to get the gradient or make the FEX function compatible with recent toolbox functions?</p><p>BTW, I do not want staticderiv, which computes the gradient of performance with respect to the network's weights and biases. I want the gradient of the output wrt to the input of the neural net.</p>Robert Alvarezhttps://uk.mathworks.com/matlabcentral/profile/authors/5360475-robert-alvareztag:uk.mathworks.com,2005:Question/3321632017-03-27T15:52:06Z2017-03-27T16:34:01Zhow to display the entropy of an grayscal image?<p>hi, i hope you're doing well image analystes ;)
for my thesis i have to use levelset method to segmentate X-ray images , and for that i need to use the entropy before the levelset !!
after using the entropy , the result is a scalar , but i want to use the raster scan or loop to apply the entropy on every single point of the image and the result will be an image with enhanced boundaries !!
i tried to use this program before but the result was a point , not the enhanced image !</p><pre class="language-matlab">clear all;
close all;
clc;
x = imread('circuit.tif');
p = imhist(x);
[m,n] = size(p);
E = 0;
for i = 1:m
for j = 1:n
if(p(i,j) > 0)
E = E - (p(i,j) .* log2(p(i,j)));
end
end
end
ex = entropy(p);
figure,
imshow(E)
</pre><p>and the entropy that i want to use for every window ( in case we use a moving window ) is :</p><p>E(i,j)=-sum(k(0 255) [p(k) log2 (p(k))]</p>sofcha23https://uk.mathworks.com/matlabcentral/profile/authors/8056404-sofcha23tag:uk.mathworks.com,2005:Question/3321672017-03-27T16:31:41Z2017-03-27T16:31:41ZRight stereo images rectification<p>I want to do the rectification for the right image of my stereo images, I have the Intrinsic and Extrinsic Camera Parameters, I already tried to use rectifyStereoImages in Matlab but I didn't,t manage to fill the structure stereoParams that this function asked for, So anyone knows how to do the rectification with Matlab ?</p><p>Thanks</p>Razielhttps://uk.mathworks.com/matlabcentral/profile/authors/6585777-razieltag:uk.mathworks.com,2005:Question/3147092016-11-30T10:41:58Z2017-03-27T16:26:33Zhow can i generate .xml file to my simulink model...........?<p>i want to convert my .mdl file to .xml. will you please suggest me ?</p>chinna naiduhttps://uk.mathworks.com/matlabcentral/profile/authors/9290294-chinna-naidutag:uk.mathworks.com,2005:Question/3320942017-03-27T08:25:01Z2017-03-27T16:13:06Zode solver results not as expected<p>Hello,</p><p>I am trying to solve differential equations numerically, but the results I obtain are not as expected. I should be able to plot an increasing exponential as a solution, but instead I get only a zero vector.</p><p>This is my differential equation:</p><p>dY/dt=(ßY^n)/(K^n+Y)^n)-αY</p><img src = "/matlabcentral/answers/uploaded_files/73489/Simple%20Gene%20Regulation.png"><p>This is the script I am using:</p><p>%Plot of Simple Gene Regulation and NAR</p><p>clear all;</p><p>tspan = [0 100];
Y0 = 0;
X0 = 0;
beta = 8;
alfa = 0.101;
n = 4;
k = 9;
N = 1;</p><p>Yss = beta/alfa;
%Xss = k*((beta/alfa)*k)^(1/(n+1));
Xss = k;</p><p>[t1,Y] = ode23(@(t,Y) (beta/(1+(k/Y)^N)-alfa*Y), tspan, Y0); %Simple Reg
[t2,X] = ode45(@(t,X) (beta/(1+(X/k)^n)-alfa*X), tspan, X0); %NAR</p><p>%plot(t1,Y./Yss,t2,X./Xss);
plot(t1,Y);
grid on;
title('Comparison between Simple Gene Regulation and NAR');
xlabel('Time t'); ylabel('Normalized Steady States');
%legend('Simple Regulation','NAR');
hold on;</p><p>The answers I get are good if I use simulink to calculate the solutions only:</p><img src = "/matlabcentral/answers/uploaded_files/73491/Comparison.png"><p>I should be able to obtain the same plots by using the command line ode solvers, but there is something wrong I might be missing.
Any help would be greatly appreciatted.
Thank you very much.</p><p>Best regards,</p><p>Alejandro</p>Alejandro Abrahamhttps://uk.mathworks.com/matlabcentral/profile/authors/9832453-alejandro-abrahamtag:uk.mathworks.com,2005:Question/3309552017-03-21T01:43:05Z2017-03-27T16:12:28ZHow can I use the find function for cell arrays to search for particular cell vector values<p>Suppose I have a cell array:</p><p>EC = {[1,2,1,1] [1,3,1,1] [1,4,1,1] [1,1,1,2]}</p><p>I need a way to index where the values of the cells = [1,3,1,1] or [1,1,1,2]
such that MATLAB returns: [2,4] for the 2nd and 4th cells of array EC.</p><p>I've been trying to use the find function, but it doesn't appear you can use that for cell arrays...</p>Kevinhttps://uk.mathworks.com/matlabcentral/profile/authors/6198528-kevintag:uk.mathworks.com,2005:Question/1556272014-09-21T00:22:44Z2017-03-27T16:02:41Zcolorbar ticklabel location set up<p>The default setting put the ticklabel to the left side the colorbar. How do I set it up so that it will appear to the right side of the colorbar?</p><p>Thank you.</p>Leonhttps://uk.mathworks.com/matlabcentral/profile/authors/3133287-leon