https://uk.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-10-17T01:50:21Ztag:uk.mathworks.com,2005:Question/3616462017-10-17T00:24:25Z2017-10-17T01:50:21ZBest way to seperate a very large array of numbers into different variables based on a value tat is given in the first column? <p>I have a variable that contains experimental data, it is 96x300001. (however the size will change every time I run my script). The first column gives a value which represents a certain group (e.g group 1, group 2 group 3 etc. The variable kinda looks like this =</p><pre class="language-matlab">1 0.021 0.0433 0.656,
2 0.00321 0.335 0.605,
3 0.1 0.035 0.625. etc etc
</pre><p>I want to tell MATLAB "numbers next to the number 1 go into variable "group1" and numbers next to the number 2 go into a variable called "group2" and so on, but I have no idea how to do this!</p>Marissa Holdenhttps://uk.mathworks.com/matlabcentral/profile/authors/8304524-marissa-holdentag:uk.mathworks.com,2005:Question/3616542017-10-17T01:45:22Z2017-10-17T01:45:22ZIn an array or a matrix, how to I find the position of a largest number. and print the postion<p>In an array or a matrix, how to I find the position of a largest number. and print the postion</p>masterblasterhttps://uk.mathworks.com/matlabcentral/profile/authors/11263588-masterblastertag:uk.mathworks.com,2005:Question/3446082017-06-13T18:35:17Z2017-10-17T01:39:49ZLicense Manager Error -9 Your username does not match the username in the license file. <p>Hello,
I changed my operating system from windows to ubuntu and reinstalled MATLAB (on the same laptop). I'm using a students license and when I was asked for my User Id, which is 'abc' I typed 'Abc92'. Is there a way of changing it? Because when I want to start Matlab the following Error:
'License Manager Error -9
Your username does not match the username in the license file.'
appears.</p><p>Thanks in advance :)!</p><p>EDIT:
I just created a user 'Abc92' and here I can start Matlab, but I want to change the username to 'abc'.</p>OK92https://uk.mathworks.com/matlabcentral/profile/authors/4441522-ok92tag:uk.mathworks.com,2005:Question/3616382017-10-16T22:30:38Z2017-10-17T01:38:33ZHelp with signal processing<p>Hi,</p><p>I'm trying to extract features from some signals. I have 5 different signals, and I've acquired data from different subjects. I have 15 subjects, each of them with their corresponding 5 signals. All of them are sampled at 1000Hz, but their length is different. I know in order to compare the data for all the subjects, I need to organize my data in buffers. I already did this, like this:</p><pre class="language-matlab">for c = 1:5
for r = 1:length(M)
buff{r,c} = buffer(M{r}(:,c), 256, 64)';
end
end
</pre><p>M is a cell array with my data, it is a 1x15 cell array, and in each cell there is a length(signal)x5 matrix (as I have 5 different signals). So I'm storing each buffer in a 15x5 cell array.</p><p>Now, I have a function for extracting my features (I've already defined the features I need to extract):</p><pre class="language-matlab">function feat = featuresFromBuffer(emg, eda, atx, aty, atz, fs)
%code
end
</pre><p>As the signals of each subject have different lengths I have to compare buffer by buffer, right? but for the feature extraction I need the features of the whole signal, how can I do this considering the buffers?</p>Catalina Duplathttps://uk.mathworks.com/matlabcentral/profile/authors/7738330-catalina-duplattag:uk.mathworks.com,2005:Question/3614612017-10-16T02:12:28Z2017-10-17T01:36:30ZBacteria Growth and Interpretation (How can you create this using matlab)<p>You can see that doing this with a for loop can be easier than repeatedly typing the same commands for every Mariem Ahmedhttps://uk.mathworks.com/matlabcentral/profile/authors/10932808-mariem-ahmedtag:uk.mathworks.com,2005:Question/3616532017-10-17T01:28:39Z2017-10-17T01:28:39ZCalculating standard deviation in simulating Chandra Fermi<p>Hello, I am working with the code below. There are 3 for loops (unfortunately). I define a grid (called k), raise it to a power index (par.p) and call it g, multiply random phase (phi) into it, and do Fourier transforms and call the grid f.</p><p>This code is to simulate: alfven waves in a molecular cloud, polarization angles (chi) of light that travels through the molecular cloud, and finally the standard deviation in chi.</p><p>The code should produce a loglog plot of the standard deviation in chi vs a variable defined as par.vaBins=logspace(-0.5, 1.5, 100).</p><p>I expect the code to give me two plots with different slopes for the two different power indices (-1/3 and 1/3) that I use. Yet the plots fall exactly on each other. I have tried other power indices, but the same thing happens.</p><p>The random row of phase angles (phi) is defined and multiplied into the grid in the innermost loop. Weirdly, when I comment out or set it equal to zero, the plots for different power indices have different slopes and do not overlap. But adding a random phase is an important part of my work, without which I will not have turbulence in the code. I wonder if anyone can help me find the error in this code please. Thank you in advance.</p><p>function CF_8
par=setup;
N=2^par.nk+1;
k=linspace(-par.kMax,par.kMax,N);
par.gamma0=par.gamma0_list(1);
chi=[];
cg0=cos(par.gamma0); sg0=sin(par.gamma0);</p><p>for a=1:length(par.p)
g=(abs(k)/par.kMax).^par.p(a)-1;
g((N+1)/2)=0;</p><p>for v=length(par.vaBins):-1:1</p><pre> par.sigma_over_va=1/par.vaBins(v);</pre><pre> for t=par.NTrial:-1:1</pre><pre> % Generate turbulence.
phi=2*pi*rand(1,N);
g=g.*exp(1i*phi);</pre><pre> f=fftshift(ifft(ifftshift(g)));
f=real(f);
f=f/std(f);
index=ceil(rand*N);
f=f-f(index);</pre><pre> fz=f; fy=0;
dBz_over_Bx=par.sigma_over_va*fz;
dBy_over_Bx=par.sigma_over_va*fy;</pre><pre> % Geometry.
tan_psi=dBz_over_Bx./(cg0-sg0*dBy_over_Bx); % alpha and psi are equal.
tan_gamma=(sg0+cg0*dBy_over_Bx)./(cg0-sg0*dBy_over_Bx);
cos_sq_gamma=1./(1+tan_gamma.^2);
denom=1+tan_psi.^2;
cos2psi=(1-tan_psi.^2)./denom;
sin2psi=2*tan_psi./denom;</pre><pre> % Calculate chi.
chi(v,t)=0.5*atan2(sum(sin2psi.*cos_sq_gamma), sum(cos2psi.*cos_sq_gamma));
end
chi_std(v)=std(chi(v,:)); disp(v);
end</pre><p>loglog(180/pi*chi_std, par.vaBins);
xlabel('std(\chi) (deg)');
ylabel('v_A/\sigma');</p><p>function par=setup</p><p>par.NTrial=1e4; %should be 1e6 in actual runs
par.nk=8; % should be 10 in actual runs
par.gamma0_list=linspace(0, pi/2, 15);
par.kMax=1;
par.p=[-1/3 1/3];
par.B0=1;
par.vA_min=0.01;
par.vA_max=100;
par.N_vA=100;
par.N_chiBins=100;
par.chiBins=linspace(-1.65,1.65,par.N_chiBins);
par.vaBins=logspace(-0.5,1.5,par.N_vA);</p>Bashirhttps://uk.mathworks.com/matlabcentral/profile/authors/2579548-bashirtag:uk.mathworks.com,2005:Question/3616442017-10-17T00:06:51Z2017-10-17T01:25:23ZUndefined function 'log10' for input arguments of type 'embedded.fi'.<p>Dear All,</p><p>Can you help me to understand this error message and how to avoid these errors?</p><p>Here is the longer version of the message:</p><pre class="language-matlab">Undefined function 'log10' for input arguments of type 'embedded.fi'.
</pre><pre class="language-matlab">Error in parameterFun (line 9)
part2 = log10(part1);
</pre><pre class="language-matlab">Error in procDataFit>@(x,f)parameterFun(x,f)
</pre><p>The error emerges when I try to use the optimization toolbox to do a curve fitting. The equation for this work is stored in a separate function file (the code is below) and I call the function as</p><pre class="language-matlab">x = [fr(i),g0,K,offset];
fun = @(x,f)parameterFun(x,f);
x = lsqcurvefit(fun,x,fi,RINData);
</pre><p>------------ the code of annonymous function parameterFun.m -----------</p><pre class="language-matlab">function minRin = parameterFun(x,f)
dFactor = ( x(2) + x(3));
part1 = ((f.*1e6).^2+(dFactor./(2.*pi)))
part2 = log10(part1);
minRin = x(4) + 10*part2;
</pre>Pavlo Ivanovhttps://uk.mathworks.com/matlabcentral/profile/authors/7475202-pavlo-ivanovtag:uk.mathworks.com,2005:Question/3612792017-10-14T04:27:26Z2017-10-17T01:23:31ZHow to specify a specific constant for a multiple linear regression? <p>I would like to know if it is possible to specify a certain constant to a multiple linear regression abd how?</p>Khaled Ahmathttps://uk.mathworks.com/matlabcentral/profile/authors/11240189-khaled-ahmattag:uk.mathworks.com,2005:Question/3616512017-10-17T01:23:23Z2017-10-17T01:23:23Zhow to draw a candle chart with a series <p>hi,
I got a candle matrix and another matrix with a series. The x axis of the series is 1,2,3,4,5,8,10,12,13,14.... So you can see that sometimes a number is skipped. I would like to draw the x axis with the aforementioned serial. Both matrices (candle and series) have the same number of rows.</p><p>thanks,</p>AAhttps://uk.mathworks.com/matlabcentral/profile/authors/5703029-aatag:uk.mathworks.com,2005:Question/1739752015-01-31T16:45:06Z2017-10-17T01:20:08ZHow do I interpolate X values from Y values? (Standard Curve)<p>I have a set of data that I fitted with a linear fit to create a standard curve and now I'm trying to interpolate unknown x-values for known y-values. I tried using polyval and I'm pretty sure I'm doing it wrong because polyval is returning two numbers instead of three for each data set I'm trying to interpolate. Also, so far I've found lots of info on how to interpolate y, but I'm not sure how to interpolate x. Any help is greatly appreciated!</p><p>My data:</p><pre class="language-matlab">x = [10, 5, 2.5, 1.25, 0.625, 0.312, 0.156,0]
</pre><pre class="language-matlab">y = [41564.9, 21531.9, 15086.9, 9249, 3175.9, 1781.9, 1320.9, 182.9]
</pre><pre class="language-matlab">p = polyfit(x,y,1)
</pre><pre class="language-matlab">%Data set 1
</pre><pre class="language-matlab">%x1 = interpolated data
</pre><pre class="language-matlab">y1 = [609.9, 1085.9, 2157.9]
</pre><pre class="language-matlab">x1 = polyval(y1,p)
</pre><pre class="language-matlab">%Data set 2
</pre><pre class="language-matlab">%x2 = interpolated data
</pre><pre class="language-matlab">y2 = [1308.9, 2514.9, 4797.9]
</pre><pre class="language-matlab">x2 = polyval(y2,p)
</pre>Anastasiya Martytshttps://uk.mathworks.com/matlabcentral/profile/authors/6126682-anastasiya-martytstag:uk.mathworks.com,2005:Question/3616452017-10-17T00:15:51Z2017-10-17T01:13:55ZError while evaluating UIControl Callback<pre class="language-matlab">function gcopt_Callback(hObject, eventdata, handles)
gen = str2num(get(handles.generator,'String'));
rate = str2num(get(handles.rating,'String'));
outage = str2num(get(handles.outage,'String'));
</pre><pre class="language-matlab">Data = cell(gen+1, 4);
Data(:,1) = num2cell((0:gen).');
</pre><pre class="language-matlab">for v = 1:gen+1
Data(v,2) = rate * Data(v,1);
end
</pre><pre class="language-matlab">f = figure('Position',[440 500 461 146]);
t = uitable(f);
t.ColumnName = {'User Input','Capacity Out','Capacity Available','Probability'};
t.Data = Data;
set(t,'ColumnWidth',{120});
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
</pre><p>I'm having this error when I'm trying to multiply the data in the for loop.</p>Kim Lopezhttps://uk.mathworks.com/matlabcentral/profile/authors/11253486-kim-lopeztag:uk.mathworks.com,2005:Question/3614202017-10-15T16:03:27Z2017-10-17T01:12:29ZAdding items in the legend as the number of curves on the plot increases<p>I'm running a loop which generates multiple plots on the same figure (using for n=1:N to generate N curves on the figure). Say I have 3 curves in the same figure, and I've already done the format specification for sprint and would like name the curves via a legend, so I would type:</p><p>legend(sprint(formatSpec,a(1)),sprint(formatSpec,a(2)),...sprint(formatSpec,a(N)))</p><p>But the number of curves on the graph changes with N, is there a way to get the figure to name all the curves with a legend as I change N?</p>Bryan Wonghttps://uk.mathworks.com/matlabcentral/profile/authors/5788198-bryan-wongtag:uk.mathworks.com,2005:Question/3614662017-10-16T03:01:30Z2017-10-17T01:10:15ZTransform non-square matrices diagonally <p>when the matrices have same dimension nXn the calculating is easy.</p><p>Here we want to find the overlap area while transforming 2 non-square matrices diagonally from corner to corner.</p>Mohammad Al Nagdawihttps://uk.mathworks.com/matlabcentral/profile/authors/1586786-mohammad-al-nagdawitag:uk.mathworks.com,2005:Question/653462013-02-28T13:07:54Z2017-10-17T01:08:04Z8 neighbours of a pixel after converting to 1D array<p>Hi</p><p>Is there a simple way to access the 8 neighbours of a pixel x(i,j) given by x(i-1,j-1), x(i-1,j), x(i-1,j+1), x(i,j-1), ... ,x(i+1,j+1) after converting x into a 1D array?
I have been using for loops to achieve this but it's quite slow if the matrix x is large.</p><p>Thanks.</p>zepphttps://uk.mathworks.com/matlabcentral/profile/authors/2452076-zepptag:uk.mathworks.com,2005:Question/3575992017-09-20T16:15:34Z2017-10-17T01:06:32Zapplying thresholds simultaneously in SimpleColorDetectionByHue()<p>I'm trying to use this program to detect not one but three different colors (red green blue) at the same time, applying three different thresholds. Is there a way?
Try to explain each little step because I haven't used Matlab for a while and I'm a bit rusty.
Thank you all!</p>giacomohttps://uk.mathworks.com/matlabcentral/profile/authors/3091880-giacomotag:uk.mathworks.com,2005:Question/3616432017-10-16T23:39:09Z2017-10-17T01:05:49ZSort & Index matrix for highest values in row<p>Hi,
I have a 5 x 5 matrix, A.</p><p>How can I create a matrix that has 1's for the largest two values in each row, and all remaining elements are zero? (I created a sort index by sort(A,2,'descend)...but am lost...).</p><p>The output matrix is a 5 x 5 matrix with 1's for the largest two values in each row.</p><p>Any help would be appreciated. Thanks!</p><p>Dan</p>dan berkowitzhttps://uk.mathworks.com/matlabcentral/profile/authors/1073383-dan-berkowitztag:uk.mathworks.com,2005:Question/3616222017-10-16T20:28:39Z2017-10-17T01:05:29ZWhy does not line appear over plot<p>I am trying to draw a skeleton over an RGB image. pos2D is a cell which holds the x,y coordinates of the body.</p><pre class="language-matlab">for w= 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
c.im = imshow(color,[]);
%set(c.im,'CData',color);
</pre><pre> skeleton = pos2D{1,w};
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
line(X1,Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
end</pre><p>Outside the loop it works perfecty, i.e. if i change the w index by hand and do step by step, the line appears. However, when I do these nested loops it does not work. It only appears in the last frame before closing the loop. I tried hold on and off several times. What am I missing?</p><p>Thanks!</p>Andrés Méndezhttps://uk.mathworks.com/matlabcentral/profile/authors/10268662-andres-mendeztag:uk.mathworks.com,2005:Question/3463052017-06-26T15:17:43Z2017-10-17T01:03:57ZHow to integrate an acceleration/time curve?<p>Hello, I have the following, x=time, y=acceleration.</p><img src = "/matlabcentral/answers/uploaded_files/81501/bJwjRuOoTeK5zesGhdosZw.png"><p>I want to integrate it twice so I can get x=time, y=position. I've tried to use ccumtrapz and the trapezoidal method but It doens't seem to apply to my curve. Any help?</p><p>The curve was obtained with the data given by two rows from excell.</p>Adriano Moraishttps://uk.mathworks.com/matlabcentral/profile/authors/8164586-adriano-moraistag:uk.mathworks.com,2005:Question/3616422017-10-16T23:36:43Z2017-10-17T00:57:29Zi need to make a function that takes an input of an array and finds the median, mode, and mean without using the built in commands<p>need to make it with a function that takes a one-dimensional array.</p>kohlton bakerhttps://uk.mathworks.com/matlabcentral/profile/authors/10788120-kohlton-bakertag:uk.mathworks.com,2005:Question/3613072017-10-14T11:20:31Z2017-10-17T00:55:30ZHow do I include my simulink model in a live script<p>I have created a live script that calls a simulink model. The live script calls the simulink model just fine and it runs well, but I want to include the simulink model inside the live script. Is this possible? Thanks and have a great day!</p>Christopher Smithhttps://uk.mathworks.com/matlabcentral/profile/authors/8808782-christopher-smithtag:uk.mathworks.com,2005:Question/3616502017-10-17T00:52:47Z2017-10-17T00:52:47Zhow do one weight lsqcurvefit with standard error from dependent data?<p>I ran into this post about weighted lsqcurvefit:</p><p>https://www.mathworks.com/matlabcentral/answers/48802-nonlinear-fit-with-constraints-in-r2012b</p><p>Shouldn't the weight from:</p><pre class="language-matlab">Weights = 1./(N.*SE.^2);
</pre><pre class="language-matlab">nonlinmodelW = @(B,t) Weights .* nonlinearmodel(B,t);
</pre><pre class="language-matlab">x = lsqcurvefit(nonlinmodelW,x0,xdata,ydata,lb,ub);
</pre><p>Be:</p><pre class="language-matlab">Weights = 1./(N.*SE);
</pre><pre class="language-matlab">nonlinmodelW = @(B,t) Weights .* nonlinearmodel(B,t);
</pre><pre class="language-matlab">x = lsqcurvefit(nonlinmodelW,x0,xdata,ydata.*Weights,lb,ub);
</pre><p>I noticed it did mentioned earlier in the post the weight ydata as well. The reason I don't square SE is because the function value return:</p><pre class="language-matlab">sum([(nonlinmodelW(B,xdata) - ydata)/(N*SE)].^2);
so if you weight with Weights = 1./SE it will returns the above equation, rather than:
the quadrature of the weight:
sum([(nonlinmodelW(B,xdata) - ydata)/((N*SE).^2)].^2);
</pre><p>Also, on the standard error of the fitted parameters, I found other source that it can be found by:</p><pre class="language-matlab">v=residuals from nonlinear least squares;
J=jacobian;
Q_xx = resnorm*inv(J'*J)/length(ydata);
</pre><pre class="language-matlab">% Precision measures ,i.e. the standard deviation of each parameter
Precision_of_solved_parameters = sqrt(diag(Q_xx));
</pre><p>Can anyone confirm this standard deviation? The code Star Strider provided will give error.</p>Arbolhttps://uk.mathworks.com/matlabcentral/profile/authors/9644129-arboltag:uk.mathworks.com,2005:Question/3523662017-08-11T00:23:54Z2017-10-17T00:48:00ZExtracting multiple envelopes from a signal<p>I have a signal which when observed carefully shows a three individual sinusoidal signals (figures attached). I want these three individual signals to be extracted in terms of amplitude, frequency and phase. Please help!</p>First Lasthttps://uk.mathworks.com/matlabcentral/profile/authors/10545297-first-lasttag:uk.mathworks.com,2005:Question/3616492017-10-17T00:42:34Z2017-10-17T00:45:54ZDid have "Build Model" icon or command in 'Simulink trial'?<p>I want simulink model convert to 'C code' but never seen that icon before to know.
maybe trial impossible to use.. right?</p>BumGeon Parkhttps://uk.mathworks.com/matlabcentral/profile/authors/10868853-bumgeon-parktag:uk.mathworks.com,2005:Question/3614922017-10-16T06:57:47Z2017-10-17T00:44:30ZGetting MD5 hash of files with "bad" names (Windows, NTFS)<p>I tryed several variants of getting MD5 hash of files with "bad" names
(e.g. 'C:\wrongname.' (with trailing dots); 'C:\wrongname ' (with trailing spaces); (path)names with accents like 'é', 'é' which occur in French, German, Hungarian; containing various forms of dashes (–) etc.).</p><p>None is working, except Var5, but is <b>too slow</b> (calculates a 10Mb file within 10 min).</p><p>Can you suggest any working variant, or how to speed up Var 5?</p><p>OS: Windows 10, File system: NTFS, Matlab 2015a</p><p>% Var 1 ---------</p><pre class="language-matlab">% dirinfo(i).name - is string containing full pathname (e.g. 'C:\myfolder\myfile.ext')
</pre><pre class="language-matlab">Opt.Format = 'HEX'; Opt.Method = 'MD5'; Opt.Input='file';
hash(i) = DataHash(['\\?\' dirinfo(i).name], Opt); % ERROR - not working with "bad" names
% DataHash.m - https://www.mathworks.com/matlabcentral/fileexchange/31272-datahash
</pre><p>%Var 2 ----------</p><pre class="language-matlab">hash(i)=mMD5(['\\?\' dirinfo(i).name]); % fast, works on 'C:\wrongname.' (with ending dots), 'C:\wrongname ' (with ending spaces), but do NOT works with file names (or pathes) with accents like 'é', é'
% (mMD5.c, see https://www.mathworks.com/matlabcentral/fileexchange/7919-md5-in-matlab)
</pre><p>% Var 3 ---------</p><pre class="language-matlab">mddigest = java.security.MessageDigest.getInstance('MD5');
bufsize = 8192;
[fid,errmsg] = fopen(['\\?\' dirinfo(i).name]); % ERROR here - matlab fopen don't understand "bad" names
if fid>=3 % if success
while ~feof(fid)
[currData,len] = fread(fid, bufsize, '*uint8');
if ~isempty(currData)
mddigest.update(currData, 0, len);
end
end
fclose(fid);
hash(i) = reshape(dec2hex(typecast(mddigest.digest(),'uint8'))',1,[]);
else
disp('can't open file');
end
</pre><p>% Var 4 ---------</p><pre class="language-matlab">file = java.io.File(['\\?\' dirinfo(i).name]);
digestream = java.security.DigestInputStream(file,mddigest);
file_bytes = typecast(org.apache.commons.io.FileUtils.readFileToByteArray(file),'uint8'); % ERROR: out of memory if BIG file
if ~isempty(file_bytes)
mddigest.update(file_bytes, 0, numel(file_bytes));
end
hash(i) = reshape(dec2hex(typecast(mddigest.digest(),'uint8'))',1,[]);
</pre><p>% Var 5 --------</p><pre> mddigest = java.security.MessageDigest.getInstance('MD5');
filestream = java.io.FileInputStream(java.io.File(['\\?\' dirinfo(i).name]));
digestream = java.security.DigestInputStream(filestream,mddigest);
while(digestream.read() ~= -1), end % TOO LONG - never goes out this cycle
hash(i)=reshape(dec2hex(typecast(mddigest.digest(),'uint8'))',1,[]);</pre>bbb_bbbhttps://uk.mathworks.com/matlabcentral/profile/authors/8958491-bbb_bbbtag:uk.mathworks.com,2005:Question/3615342017-10-16T11:00:30Z2017-10-17T00:36:42ZHow to change the x axis of hue histgram from number to degree value?<p>I used HSV color transformation to segment an image according to hue channel. I used histogram function to find the hue values for each image. The x axis of hue ranged from 0.1 to 1. I need to show these values in the hue degree i.e. from 0 to 360 degree. Is there any way to implement that?</p>Susan Smithhttps://uk.mathworks.com/matlabcentral/profile/authors/4662675-susan-smithtag:uk.mathworks.com,2005:Question/3616082017-10-16T19:17:11Z2017-10-17T00:26:53ZSpeed of looped operation on a GPU depending on number of iterations in loop?<p>This is a question that I think will get a bit into the weeds of MATLAB's JIT and GPU toolbox.
I will be including a MWE sample code below, and it should be stated that I am using 2017a and have a Titan-X 12GB Pascal GPU.</p><p>The basic issue is this: I am performing a looped operation (e.g. an interpolation) on the GPU, and if the number of iterations in the loop is small, the operation is very fast. However, once the number of iterations passes some threshold, each operation slows way down (a factor of >100 in my case).</p><p>To illustrate this, I used my minimum working example (MWE) below. It produced on my machine these two figures.</p><p>The first shows the average time per numerical operation versus the number of iterations in the loop. At values n<200 the operations take on the order of 1E-4 s/op. After that threshold is passed, they take around 2E-2 s/op, a massive slowdown.</p><img src = "/matlabcentral/answers/uploaded_files/91191/TimePerOp.png"><p>The second shows the total time for the loop. Again, we see a change in behavior where the number of iterations doesn't affect the total time (this is why I think its a JIT thing) until the threshold around n = 200, and then it increases linearly as expected.</p><img src = "/matlabcentral/answers/uploaded_files/91193/TotalTime.png"><p>Finally, for each loop I output the time spent on each individual operation. For 150 iterations, We see that the time/operation is fairly constant in the 1E-4 s range, but for 200 iterations there is a sudden massive change in the time partway through the loop.</p><img src = "/matlabcentral/answers/uploaded_files/91194/n3.png"><img src = "/matlabcentral/answers/uploaded_files/91195/n4.png"><p>The questions are:</p><ul><li>(A) Why is this sudden change in speed occurring?</li><li>(B) Is there a way to code this so that it does not occur (pre-allocation didn't seem to work, nor variable clearing).</li><li>(C) If I cannot avoid it, can I predict it? In many cases I have the flexibility of changing the number of iterations in a loop through other means, so if keeping that number of iterations below some magic number will make my processing 400x faster, I will work on it.</li></ul><p>My MWE code is below; it should be noted that this code shows this behavior on my machine, but it may not on yours. Also, the numerical operation being used here is a stand-in for an actual looped process and is just being used to illustrate the speed issue.</p><pre> % =========================================================================
% MWE
% =========================================================================
% Clean up
clear all
close all
clc
% Set up some demo data and interpolating spaces
times2 = cell(10,1);
times1 = zeros(10,1);
x = (1:4000).';
y = (1:240);
v = rand(240,4000);
xi = 4000*rand(500);
xi = repmat(xi,1,1,240);
[Mf,Nf,~] = size(xi);
yi = repmat(y,Mf,1,Nf);
yi = permute(yi,[1,3,2]);
% Put it all on the GPU
x = gpuArray(x);
y = gpuArray(y);
v = gpuArray(v);
xi = gpuArray(xi);
yi = gpuArray(yi);
% Outer loop - changes number of iteration used in inener loop
for nn = 1:10
t1 = tic;
nn
timesIn = zeros(50*nn,1);
% Inner loop, perform our interpolation n-times
for ii = 1:50*nn
tI = tic;
vi = interp2(x,y,v,xi,yi);
vi = sum(vi,3);
timesIn(ii) = toc(tI);
end
% Plot the current time/op and save times
figure(1)
plot(timesIn); title(nn); drawnow;
times1(nn) = toc(t1);
times2{nn} = timesIn;
toc(t1)
end
% Make Figures
for nn = 1:10
mTimes(nn) = mean(times2{nn});
end
figure; plot((1:10)*50,mTimes); title('Mean time/operation'); ylabel('Time'); xlabel('n-Iterations');
figure; plot((1:10)*50,times1); title('Total Loop Time'); ylabel('Time'); xlabel('n-Iterations');</pre>Daniel Plotnickhttps://uk.mathworks.com/matlabcentral/profile/authors/7040802-daniel-plotnicktag:uk.mathworks.com,2005:Question/3616482017-10-17T00:24:35Z2017-10-17T00:24:35ZUsing fprintf to format a diagonally dominant matrix<p>I have a code that uses the jacobi method to solve an equation system. For instance:</p><img src = "/matlabcentral/answers/uploaded_files/91213/Jacobi%20method.png"><p>I want to sort the sequence of steps performed in the algorithm and send them to a diagonally dominant matrix. I was thinking of using fprintf but could think of a way to make it.</p><p>Help is greatly appreciated</p>Paola Ariztihttps://uk.mathworks.com/matlabcentral/profile/authors/11263137-paola-ariztitag:uk.mathworks.com,2005:Question/3616472017-10-17T00:24:28Z2017-10-17T00:24:28ZDid 'Simulink Trial' have 'Build Model' icon or commander?<p>I want simulink model convert to 'C code' and I know that must need 'Build model' function but for me using a trial never seen it before to now. really don't have in trial?</p>BumGeon Parkhttps://uk.mathworks.com/matlabcentral/profile/authors/10868853-bumgeon-parktag:uk.mathworks.com,2005:Question/3615992017-10-16T18:26:56Z2017-10-17T00:09:31Zhow to plot vertical dotted line ??<p>i want plot vertical dotted line on the same figure(scale 25), at samples: 180 and 220 the length of my ecg is 2000??</p><pre> load ecg.m;
subplot(221);
plot(ecg); title ('ECG');
xlabel('samples'); ylabel('magnitude');</pre><pre> fs=360;
subplot(222)
CWTcoeffs = cwt(ecg,20:55,'sym4','plot');
colormap jet; colorbar;
subplot(223);
qrs_thr_end=220;
qrs_thr_on=180;
plot(CWTcoeffs(25,:)); title('Scale 25');</pre>khiter hindhttps://uk.mathworks.com/matlabcentral/profile/authors/9404109-khiter-hindtag:uk.mathworks.com,2005:Question/3614892017-10-16T06:37:36Z2017-10-16T23:54:43ZCode documentation neural networks<p>Hi!</p><p>I'm using the neural network package in order to try out different models. However, all information I read about and all examples I see is concerning the GUI where you are very limited. There are some youtube videos on Mathworks page but they seem more 'inspirational'.</p><p>I want to build both shallow and deep nets, with mixed layers (i.e. mix RNN with MLP). I also want to be able to adjust all hyperparameters by myself. Where can I find good examples and good documentation on how to start coding this? I'm familiar with coding in e.g. TensorFlow and it would be great to find documentation more like TF or Keras.</p><p>Thanks!</p><p>KD
Magnus</p>Magnus Hanssonhttps://uk.mathworks.com/matlabcentral/profile/authors/11254579-magnus-hanssontag:uk.mathworks.com,2005:Question/3616202017-10-16T20:16:58Z2017-10-16T23:45:10Znot sure how to answer this question, class has no matlab book and is only 40 min a week.<p>In petroleum industries, it is common that the molecular weight of an oil fraction is unknown and thus must be estimated by using a correlation. A correction that is widely used is developed by Riazi and Daubert, which is also referred to as the API (American Petroleum Institute) method. The correlation can be applied to hydrocarbons with molecular weight ranging from 70-700, which is nearly equivalent to boiling point range of 300-850K, and the API gravity range of 14.4-93. This molecular weight (M) correlation is givenas a function of the average boiling point (Tb) and the specific gravity at 60 °F (SG) of the oil fraction of interest as follows:</p><pre class="language-matlab">M=42.965*exp(2.097x10^-4 *Tb-7.78712SG+2.08476x10^-3 *TbxSG)Tb^1.26007SG^4.98308
</pre><p>where Tb is in K and SG is related to the API gravity (API)
SG=141.5/(API+131.5)</p><p>a) Estimate the molecular weight of an oil fraction that has an average boiling point of 344.7 °C and an API gravity of 50.</p><p>b) Plot on the same graph M vs. Tb(400≤Tb≤600K) with API gravity=20, 40, and 60.</p><p>i'm pretty sure i figured out part a) but not sure how to get the different API on to the same graph</p>mikeghttps://uk.mathworks.com/matlabcentral/profile/authors/11261957-mikegtag:uk.mathworks.com,2005:Question/3616332017-10-16T21:51:09Z2017-10-16T23:34:06ZI wish to sum up every 12th value in a time series. I want the value from 1-12, 13 - 24 , 25-36 and so on through the whole time series.<p>This is to extract the annual value form a monthly time series.</p><p>Can anybody help me out here?</p><p>Many thanks!</p>Ola Sveenhttps://uk.mathworks.com/matlabcentral/profile/authors/10748897-ola-sveentag:uk.mathworks.com,2005:Question/3616312017-10-16T21:44:29Z2017-10-16T23:33:31ZWhat is distance between -7 and 14<p>Calculation</p>Dorothy Garnerhttps://uk.mathworks.com/matlabcentral/profile/authors/11262574-dorothy-garnertag:uk.mathworks.com,2005:Question/3553352017-09-05T23:38:15Z2017-10-16T23:32:25Zconverting .kea to .geotiff in bulk using matlab<p>I need to convert about 100 raster data in .kea format for geotiff.
would be great help if any one can help me in this regard.</p><p>regards
Raj</p>rajasweta dattahttps://uk.mathworks.com/matlabcentral/profile/authors/8451042-rajasweta-dattatag:uk.mathworks.com,2005:Question/3616242017-10-16T20:39:53Z2017-10-16T23:27:53ZHelp with Laplace graphic<p>I have problem with</p><pre class="language-matlab">syms t
</pre><pre class="language-matlab">t = -5*pi:0.01:5*pi
</pre><pre class="language-matlab">y = cos (t) + 4*sin(t - 2*pi)u(t-2*pi)
</pre><pre class="language-matlab">fplot(t,y)
</pre><p>I don't know draw "u(t-2*pi)"</p><p>"u(t-2*pi) is the displacement</p><p>the equation original is:</p><pre class="language-matlab">diff(y,2) + y = 4 d(t - 2*pi)
</pre><p>"d" is the "Dirac Delta"</p><p>Thanks!</p>Carlos Sebastian Castillo Silvahttps://uk.mathworks.com/matlabcentral/profile/authors/9790650-carlos-sebastian-castillo-silvatag:uk.mathworks.com,2005:Question/2650072016-01-24T17:13:59Z2017-10-16T23:26:47ZSend path of image as parameter to matlab function using .net builder C#<p>Hello there,
I'm using .net builder in my ASP.NET MVC App. The Application is hosted on local IIS server. I'm getting this error: " <i>MWMCR::EvaluateFunction error ... proba.jpg does not exist</i>". I tried the same code only in Windows Form Application (project) and it worked fine. Also i tried another matlab function that has some number for parameter and calling it from my MVC App it worked fine also. The code of the matlab function is:</p><pre class="language-matlab">function y = procesiranjeSlika(P)
addpath 'C:\Users\Gjorgji\SkyDrive\Documents\C#\AForge Slika Processing\';
I=imread(P);
Gray = rgb2gray(I);
Canny = edge(Gray, 'canny');
co = clock;
pom=strcat(num2str(co(1)),num2str(co(2)),num2str(co(3)),num2str(co(4)),num2str(co(5)),num2str(round(co(6))));
imwrite(Canny, fullfile('C:\Users\Gjorgji\SkyDrive\Documents\Fakultet\Magisterska\Digitalno Procesiranje na sliki\Procesirani sliki\', ['procesiranjeSlika', pom, '.jpg']));
rez = strcat('C:\Users\Gjorgji\SkyDrive\Documents\Fakultet\Magisterska\Digitalno Procesiranje na sliki\Procesirani sliki\',pom,'.jpg');
y=rez;
</pre><p>And the MVC C# code is:</p><pre class="language-matlab">_input = new MWCharArray[] {"proba.jpg" };
string rez = null;
try
{
tmpClassNative = new procesiranjeSlikaNative.Class1();
rez = tmpClassNative.procesiranjeSlika(_input).ToString();
}
catch (Exception ex)
{
rez = ex.ToString();
return Json(new { rez = rez.ToString() });
}
</pre><p>IT crashes on the 3rd line of the matlab function <b>imread()</b>.
I'm using 64 bit MatLab.</p>Gjorgji Vladimirovhttps://uk.mathworks.com/matlabcentral/profile/authors/7560256-gjorgji-vladimirovtag:uk.mathworks.com,2005:Question/3576532017-09-21T02:08:05Z2017-10-16T23:20:56ZHow to clear gpuArray, which is a property of a class, from memory when deleting an object class instance<p>I need to interpolate the same matrix many different times, and doing so with mex/C is still too slow. Thus, I am trying to create a class that will hold the matrix as a gpuArray and then have a method that allows me to interpolate it, without having to send it to the gpu device each time I interpolate it.</p><p>The problem I am having is clearing the array from the gpu memory when I clear the class object. The gpuArray does not leave memory and my memory constantly increases upon creating more instances of this class. Below is a minimal working class, and below that is an example of calling it and viewing the available device memory.</p><pre class="language-matlab">classdef gpuInterp
properties
Z
Z_d
end
methods
function F = gpuInterp(Z)
F.Z = Z;
F.Z_d = gpuArray(Z);
end
function Zi = interp(obj,xi,yi)
xi_d = gpuArray(xi);
yi_d = gpuArray(yi);
Zi_d = interp2(obj.Z_d, xi_d, yi_d); clear xi_d yi_d
Zi = gather(Zi_d); clear Zi_d
end
end
end
</pre><p>Example calling the class.
First test : create the class, then destroy the class without calling the interp() method. In this test, it appears that the gpuArray in the class is removed as the available memory after clearing the instance is the same as before creating instance.</p><pre class="language-matlab">>> gpuDevice([]);
>> dev = gpuDevice(); % initialize device
>> dev.AvailableMemory % display initial memory
ans =
1563811840
>> F = gpuInterp(rand(5000)); % create instance of class
>> dev.AvailableMemory % display available memory
ans =
1363795968
>> clear F % destroy instance
>> dev.AvailableMemory % display available memory
ans =
1563811840
</pre><p>Second test : create the class, call the interp() method, then destroy the class. In this test, it appears that the gpuArray in the class is not removed as the available memory after clearing the instance is the same as after first creating it.</p><pre class="language-matlab">>> gpuDevice([]);
>> dev = gpuDevice(); % initialize device
>> dev.AvailableMemory % display initial memory
ans =
1526210560
>> F = gpuInterp(rand(5000)); % create instance of class
>> dev.AvailableMemory % display available memory
ans =
1326194688
>> Zi = F.interp(1.5:500.5, (1.5:500.5)'); % call the interp method
>> dev.AvailableMemory % display available memory
ans =
1326097536
>> clear F % destroy instance
>> dev.AvailableMemory % display available memory
ans =
1326097536
</pre><p>Note, I have also tried making a cleanup property as suggested <a href = "https://stackoverflow.com/questions/14057308/matlab-class-destructor-not-called-during-clear">here</a>, that will call a cleanUp function that tries to clear the gpuArray (clear obj.Z_d). I have also tried making it a handle class with a delete method that tried to clear the gpuArray. Neither of these worked.</p><p>Is there a way to do what I am trying to do (store a matrix on a gpu to interpolate it many times without having to send it to the gpu each time)?</p>Jameshttps://uk.mathworks.com/matlabcentral/profile/authors/3554246-jamestag:uk.mathworks.com,2005:Question/3616412017-10-16T23:12:51Z2017-10-16T23:15:05ZIs there a stability analysis command or toolbox to study the stability of solutions to an ODE system?<p>From inspecting the numerical solutions to my state variables in a coupled ODE system (with ode45), I am noticing that one particular state variable settles into a final value, for long time scales. How could I study the stability / instability of this particular state variable with Matlab? Is there a Matlab command or some stability analysis toolbox that I can use? FYI, I have virtually no numerical methods background, although I've read some stuff on stability theory on Wikipedia and other online sources. Thanks,</p>Noobhttps://uk.mathworks.com/matlabcentral/profile/authors/6426532-noobtag:uk.mathworks.com,2005:Question/3578982017-09-22T12:22:33Z2017-10-16T23:06:39Zhow can i fix this error Error using gpuArray/arrayfun Out of memory on device. To view more detail about available memory on the GPU, use 'gpuDevice()'. If the problem persists, reset the GPU by calling 'gpuDevice(1)'.<pre> YTest = classify(cifar10Net, testDigitData);</pre><p>I am using MATLAB 2017a</p><p>with GPU</p><pre class="language-matlab">Name: 'GeForce 920MX'
Index: 1
ComputeCapability: '5.0'
SupportsDouble: 1
DriverVersion: 8
ToolkitVersion: 8
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 2.1475e+09
AvailableMemory: 1.6472e+09
MultiprocessorCount: 2
ClockRateKHz: 993000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
</pre>hadeel manasrahhttps://uk.mathworks.com/matlabcentral/profile/authors/6453642-hadeel-manasrahtag:uk.mathworks.com,2005:Question/3600332017-10-06T17:20:20Z2017-10-16T23:01:22ZCUDA Error - Semantic Segmentation<p>Hello,</p><p>Using semantic segmentation, I want to separate the satellite image into two classes, water and land. I am having this problem: <b>"An unexpected error occurred during CUDA execution. The CUDA error was: CUDA_ERROR_LAUNCH_FAILED"</b></p><p>How can I solve this problem ?</p><p>Here my codes :</p><pre> clear;clc;close all</pre><pre> dataDir = fullfile('C:\Users\firat\Desktop\TEZ\Uygulama\Semantic Segmentation\data');
imDir = fullfile(dataDir,'image');
pxDir = fullfile(dataDir,'imagePixelLabels');</pre><pre> imds = imageDatastore(imDir);</pre><pre> I = readimage(imds,1);
figure
imshow(I)</pre><pre> % imageLabeler(imDir);</pre><pre> classNames = ["Water" "Land"];
pixelLabelID = [1 2];
pxds = pixelLabelDatastore(pxDir,classNames,pixelLabelID);</pre><pre> C = readimage(pxds,1);</pre><pre> B = labeloverlay(I,C);
figure
imshow(B)</pre><pre> buildingMask = C == 'Water';
figure
imshowpair(I, buildingMask,'montage')</pre><pre> % Create a Semantic Segmentation Network</pre><pre> numFilters = 64;
filterSize = 3;
numClasses = 2;
layers = [
imageInputLayer([1024 1024 3])
convolution2dLayer(filterSize,numFilters,'Padding',1)
reluLayer()
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(filterSize,numFilters,'Padding',1)
reluLayer()
transposedConv2dLayer(4,numFilters,'Stride',2,'Cropping',1);
convolution2dLayer(1,numClasses);
softmaxLayer()
pixelClassificationLayer()
]</pre><pre> opts = trainingOptions('sgdm', ...
'InitialLearnRate', 1e-3, ...
'MaxEpochs', 100, ...
'MiniBatchSize', 64);</pre><pre> trainingData = pixelLabelImageSource(imds,pxds);</pre><pre> net = trainNetwork(trainingData,layers,opts);</pre><pre> testImage = imread('C:\Users\firat\Desktop\TEZ\Uygulama\Semantic Segmentation\test\test3.tif');</pre><pre> C = semanticseg(testImage,net);
B = labeloverlay(testImage,C);
figure
imshow(B)</pre>Firat Erdemhttps://uk.mathworks.com/matlabcentral/profile/authors/11161415-firat-erdemtag:uk.mathworks.com,2005:Question/1592942014-10-20T03:22:26Z2017-10-16T22:59:21ZMidpoint numerical integration without a built in function<p>I need some help building a matlab script to solve
dy/dt = y*t^3-1.5*y using the midpoint method. I have solved this using Euler's and the below code</p><pre class="language-matlab">a = 0;
b = 2;
</pre><pre class="language-matlab">h=.5;
T = 0:h:2;
</pre><pre class="language-matlab">y = zeros(1,((b-a)/h+1));
y(1) = 1;
phi1 = y.*T.^3-1.5.*y;
for i = 2:length(T)
phi1 = y(i-1).*T.^3-1.5.*y(i-1);
y(i) = y(i-1) + phi1(i-1).*h;
end
plot(T,y,':bo')
</pre><p>But solving cannot figure out the midpt method as I know the +1/2 intervals are tough on MATLAB.</p><p>Below is what I have for midpoint and I know it is very wrong.</p><p>thanks in advance.</p><pre class="language-matlab">a = 0;
b = 2;
h= .5;
h2 = h/2;
t = 0:h2:2;
</pre><pre class="language-matlab">y = zeros(1,9);
y(2) = 1;
phi3 = y.*t.^3-1.5.*y;
for i = 3:(length(t))
Y2 = y(i-2)+ (y(i-2).*(t).^3-1.5.*y(i-2))*(h/2);
phi3 = Y2.*t.^3-1.5.*Y2;
y(i) = y(i-2) + phi3(i-1).*h;
end
</pre><pre class="language-matlab">plot(t,y);
</pre>Aggiehttps://uk.mathworks.com/matlabcentral/profile/authors/5595231-aggietag:uk.mathworks.com,2005:Question/3591992017-10-01T10:56:42Z2017-10-16T22:58:46ZIs there a Convolutional Neural Network implementation for 3D images?<p>I'm looking for an implementation matlab, in order to process 3D CT scan images. By 3D I mean 3 spatial dimensions (i.e. not 2D+channels or 2D+time). Any advice?
preferrably an accelerated version (that used GPU or mex files) and an easy-to-use pre-trained network like Elektronn but for MATLAB..</p><p>another side question: does Caffe support 3D images? if so, how can it be used through MATLAB ?</p>sallyhttps://uk.mathworks.com/matlabcentral/profile/authors/4599643-sallytag:uk.mathworks.com,2005:Question/3596722017-10-04T16:12:56Z2017-10-16T22:56:04Zhow to identify high-intensity pixel ?<p>Can anyone help me to identify high-intensity regions for segmenting the tumor( image of the brain as the following figure)</p><img src = "/matlabcentral/answers/uploaded_files/91197/2.jpg">marwa zahttps://uk.mathworks.com/matlabcentral/profile/authors/6314589-marwa-zatag:uk.mathworks.com,2005:Question/3587952017-09-28T10:28:36Z2017-10-16T22:54:23ZUsing a system with multiple gpus and multiple users, how can we share resources?<p>I am trying use a system with a Tesla K80 which has multiple GPU devices (8). How can I effectively share these resources without affecting other peoples work?
I am currently selecting a GPU device according to available memory. Unfortunately, this is not foolproof. Several devices show that memory available is 'NaN'.
Any advice on how to implement it properly would be appreciated!</p><p>Extra Info:
Windows Multipoint Server
Accessed via remote desktop</p>Daniel Mosshttps://uk.mathworks.com/matlabcentral/profile/authors/10746320-daniel-mosstag:uk.mathworks.com,2005:Question/3616402017-10-16T22:43:06Z2017-10-16T22:51:58Zis it right?<p>Question is here:Use MATLAB to plot the polynomials y=3x4-6x3+8x2+4x+90 and z=3x3+5x2-8x+70 over the interval -3≤x≤3. Properly label the plot and each curve. The variables y and z represent current in milliamperes; the variables x represents voltage in volts.</p><p>The code is here:</p><pre> clc</pre><pre> clear</pre><pre> x=[-3:3]</pre><pre> y = 3*x.^4-6*x.^3+8*x.^2+4*x+90;</pre><pre> z = 3*x.^3+5*x.^2-8*x+70;</pre><pre> plot(x, y,x,z)</pre><pre> xlabel('Voltage(V)')
ylabel('milliamperes(A)')</pre><pre> if true
% code
end</pre>Mahir Öztürkhttps://uk.mathworks.com/matlabcentral/profile/authors/11251311-mahir-ozturktag:uk.mathworks.com,2005:Question/3606782017-10-10T21:57:22Z2017-10-16T22:46:06ZHow can you create alert when making a digital temperature using arduino on GUI<p>I am trying to create a digital thermometer using Arduino. I also want to make sure there is an alert on high or low-temperature changes. Not sure how to create the alert.</p>Refat Chowdhuryhttps://uk.mathworks.com/matlabcentral/profile/authors/9703196-refat-chowdhurytag:uk.mathworks.com,2005:Question/3610462017-10-12T18:33:29Z2017-10-16T22:44:31ZHow would I make this code work? i am trying to threshold an image. <pre class="language-matlab">im = imread('image.bmp');
</pre><pre class="language-matlab">x = []; %creating empty matrix for x
y = [];%creating empty matrix for y
</pre><pre class="language-matlab">for i = [1: size(im,1)]
for j = [1:size(im,2)]
if 120 < im(i,j) < 200 {
x = [x,i]; y = [y,j];
i = 1; j = 1;
end
}
end
end
</pre>Juan Jhttps://uk.mathworks.com/matlabcentral/profile/authors/11228307-juan-jtag:uk.mathworks.com,2005:Question/3595602017-10-03T23:58:01Z2017-10-16T22:44:16ZResize images in ImageDataStore on GPU<p>I have trained a neural net (based on AlexNet) and want to classify new images by means of this neural net. First I read the images into an ImageDataStore but for AlexNet the dimension of the images have to be 227 x 227. Can I resize all images in the ImageDataStore on GPU? I currently use below code for the resizing but am wondering if this is the "fastest" way.</p><p>newSample.ReadFcn = @(newSample)imresize(imread(newSample),[227 227])</p><p>Thanks for your help,</p><p>Raf</p>RPhttps://uk.mathworks.com/matlabcentral/profile/authors/10469168-rptag:uk.mathworks.com,2005:Question/3616282017-10-16T21:07:47Z2017-10-16T22:43:13ZHow to display DICOM loop from file?<p>I have a problem with displaying DICOM data in Matlab. I have 1 serie of 115 frames echo data. I'm making a GUI for analysing data</p>Jaroslava Orenicovahttps://uk.mathworks.com/matlabcentral/profile/authors/7976186-jaroslava-orenicovatag:uk.mathworks.com,2005:Question/3616392017-10-16T22:40:32Z2017-10-16T22:40:32ZA code for a vector that doubles the elements that are positive and are divisible by 2 or 5, and raise to the power 4 the elements that are negative but greater than -3.<p>A vector is given by: V=[5, 17, -3, 8, 0, -1, 12, 15, 20, -6, 6, 4, -7, 16]. Write a program that doubles the elements that are positive and are divisible by 2 or 5, and raise to the power 4 the elements that are negative but greater than -3.</p>Mahir Öztürkhttps://uk.mathworks.com/matlabcentral/profile/authors/11251311-mahir-ozturk