https://uk.mathworks.com/matlabcentral/answers/questions MATLAB Answers — New Questions 2019-08-26T04:53:09Z tag:uk.mathworks.com,2005:Question/477518 2019-08-25T17:44:00Z 2019-08-26T04:53:09Z how to create timeline plot? Hi all, I want to create a timeline plot similer to the following: North | |||||||||||||||||||||||||||| ||||||||||||||||||||||||||||| | | Central | |||||||||||||||||||||||||||||||||| |_________________________________________ Jan Feb Mar Apr .....etc start date end date start date end date the time periods for the north are datenum([2019 01 30]) datenum([2019 04 12], and datenum(2019,07,03) datenum(2019,08,25) Time for the Central is datenum(2019,01,08) datenum(2019,03,03) Any help will be appreciated Thanks. Lola SE https://uk.mathworks.com/matlabcentral/profile/authors/6648456-lola-se tag:uk.mathworks.com,2005:Question/297606 2016-07-29T02:04:02Z 2019-08-26T04:49:33Z Undefined function 'plotSpec' for input arguments of type 'double' Hello, The following code should give the following graph, but there is an error appearing which is "Undefined function 'plotSpec' for input arguments of type 'double'." So, any one knows what is the problem? Thanks, f=10; time=2; Ts=1/1000; t=Ts:Ts:time; x=sign(cos(2*pi*f*t)); plotSpec(x,Ts) Bahaa Algebory https://uk.mathworks.com/matlabcentral/profile/authors/8477975-bahaa-algebory tag:uk.mathworks.com,2005:Question/477542 2019-08-26T03:45:45Z 2019-08-26T04:48:27Z Using GPU on multiple nested loops The following code is slow for large ncnt (typically >2000) and I want to use my GPU for the outermost (iplane) loop. Can you give me an hint? (I have an NVIDIA RTX 8000.) nxs=101; nys=101; nzs=101; ncnt=100; xnmin=-1.0; xnmax= 1.0; ynmin=-1.0; ynmax= 1.0; znmin=-1.0; znmax= 1.0; coefftmp=complex(rand(1,ncnt)); igalltmp=rand(3,ncnt); vktmp=rand(1,3); wfrtmp=complex(zeros(nxs,nys,nzs)); tic for iplane=1:ncnt % GPU loop ee=exp(2.*pi*complex(0.,1.)); vkg=vktmp+double(igalltmp(:,iplane)'); ekx=ee^vkg(1); eky=ee^vkg(2); ekz=ee^vkg(3); coefft=coefftmp(iplane); for iz=1:nzs z=znmin+(znmax-znmin)*double(iz-1)/double(nzs-1); ekzz=ekz^z; for iy=1:nys y=ynmin+(ynmax-ynmin)*double(iy-1)/double(nys-1); ekyy=eky^y; for ix=1:nxs x=xnmin+(xnmax-xnmin)*double(ix-1)/double(nxs-1); ekxx=ekx^x; wfrtmp(ix,iy,iz)=wfrtmp(ix,iy,iz)+coefft*ekxx*ekyy*ekzz; end end end end wfr(ispin,:,:,:)=wfrtmp/sqrt(Vcell); toc Jhinhwan Lee https://uk.mathworks.com/matlabcentral/profile/authors/2498849-jhinhwan-lee tag:uk.mathworks.com,2005:Question/36636 2012-04-26T12:24:39Z 2019-08-26T04:45:17Z decompressing an compressed image I have a code for compression please telll how to decompress an image from that compressd image y=imread('dock.jpg'); y=rgb2gray(y);y=double(y) threshold=0.125 y=imresize(y,[256 256 ]) low=min(min(y)); high=max(max(y)); % NEEDED LATER FOR DISPLAYING figure, imagesc(y), colormap(gray), axis off title('original image') w=wavmat; ty = w'*y*w; % THE WAVELET TRANSFORMATION tty=ty; % A TRICK TO ELIMNATE THE OVERALL tty(1,1)=0; % AVERAGE FROM CONSIDERATION WHEN dead=max(max(abs(tty)))*threshold/100; % DECIDING JUST HOW TO THRESHOLD clear tty; dy=ty; index=find(abs(dy)<=dead); dy(index)=zeros(size(index)); % SETTING LOTS OF ELEMENTS TO ZERO cy = full(w*sparse(dy)*w'); % THE INVERSE WAVELET TRANSFORMATION density = nnz(dy); % ENTRIES USED OUT OF 256^2 = 65536 disp(['Wavelet transformed and doctored matrix uses ']) disp([ num2str(density) ' entries out of 256^2 = 65536,']) disp(['thus is ' num2str(100*density/65536) '% dense, and we get a ']) disp(['compression ratio of ' num2str(65536/nnz(dy)) ' to 1']) % "COMPRESSION RATIO" = 65536/DENSITY figure, imagesc(cy,[low high]), colormap(gray), axis off title('compressed image') Pat https://uk.mathworks.com/matlabcentral/profile/authors/3009067-pat tag:uk.mathworks.com,2005:Question/477544 2019-08-26T04:42:34Z 2019-08-26T04:42:34Z how to connect simscape to sim electronics i designed a solar inverter but output of solar is not conected to input terminal of inverter chilukamari pavankalyan https://uk.mathworks.com/matlabcentral/profile/authors/15380852-chilukamari-pavankalyan tag:uk.mathworks.com,2005:Question/477543 2019-08-26T04:34:24Z 2019-08-26T04:38:27Z A problem with multiple columns in legend Hi all, I just made the following lines, simply I cannot make a multiple column legend. If anyone knows how to deal with this, i would be very thankful! Thanks in advance. figure bar(randn(4)) [xx,yy] = legend({'a','b','c','d'}, 'box','off','NumColumns', 4) Creatlee https://uk.mathworks.com/matlabcentral/profile/authors/9994906-creatlee tag:uk.mathworks.com,2005:Question/477539 2019-08-26T03:17:12Z 2019-08-26T04:34:39Z Plotting a graphical converge inside a While - Newton Raphson numerical method Hi, I'm trying to get a command inside a while so as the Newton Rapshon code shows a graphical converge. If the values of the aproximations are connected between a line, it shows something like a spider web. Can anyone help me out, please? Here is my code: clear clc syms x f = input('Introducir la función: '); %function p0 = input ('Introducir valor semilla: '); %first aproximation TOL = input ('Introducir la tolerancia de error: '); %error fplot (f) grid on hold on derivada = diff(f); derivada = inline (derivada); f = inline (f); eabs = 100; i =0; while eabs>TOL p = p0 - (f(p0))/(derivada(p0)); eabs = abs(((p-p0)/p)*100); p0 = p; i = i+1; end fprintf('\n Valor= %8.3f ',p0) plot (p) fplot (0) hold off Luis Francisco Sanchez https://uk.mathworks.com/matlabcentral/profile/authors/13269652-luis-francisco-sanchez tag:uk.mathworks.com,2005:Question/477528 2019-08-25T22:55:21Z 2019-08-26T04:26:49Z How can Ido the same operations with multiples files using for-loop I developed the a code for one specific file (spike1.mat). Now I want to run this code for n files (spike1.mat, spike2.mat, spike3.mat, so on). Nested for-loop seems to be the best function, but I don't know how the (nested) for-loop makes the operation for the first file, for the second file, and so on. In other words,I don't know how I can integrate my operations into the for-loop because I don't know how to name the files. This is my entire code: clear;clc; function = spike_analysis load 'spike1.mat'; %Plot the spike with a corrected baseline A=spike1(:,1); B=spike1(:,2); B1=B-(min(B)); %Baseline is 0 if the minimum value is different than 0. figure(1) plot(A,B1) ylabel('Intensity (pA)') xlabel('Time(s)') title('1st spike') format longG % The parameters for the entire spike % Charge of the entire spike %The inmediate integration of the vector Intensity during the time is the %charge (Q), i.e. the amount of molecules released per vesicle. Q_spike=trapz(A,B1)*10^3 % The Increment of time of the Half Width of the spike %Find the Time (second) when Intensity is maximum %[a b]=max(Fst_spike(:,2)); %Time_maxI=Fst_spike(b,1) % The Increment of time of Half Width. %Find the half max value. halfMax = max(B1) / 2; index1_HW = find(B1 >= halfMax, 1, 'first'); %Gives the number of the row where data first drops below half the max. index2_HW = find(B1 >= halfMax, 1, 'last'); %Gives the number of the row where data last rises above half the max. Ti_HW=A(index1_HW,1) Tf_HW=A(index2_HW,1) AT_HW=(Tf_HW-Ti_HW)*10^6 %The Rise Time (the time span between the 50% and the 90% of the %maxIntensty). % Find the 90% of the maxIntensity. RT_90 = max(B1) * 0.90; index1_RT = find(B1 >= halfMax, 1, 'first'); %Gives the number of the row where data first rises above half the max. index2_RT = find(B1 >= RT_90, 1, 'first'); %Gives the number of the row where data first drops below 90% of the max. Ti_RT=A(index1_RT,1) Tf_RT=A(index2_RT,1) AT_RT=(Tf_RT-Ti_RT)*10^6 % The paramenters of the foot signal load 'footsignal_spike1.mat' A_f=footsignal_spike1(:,1); B_f=footsignal_spike1(:,2); figure (2) plot(A_f,B_f) ylabel('Intensity (pA)') xlabel('Time(s)') title('1st foot signal') % Charge of the foot signal Q_footsignal=trapz(A_f,B_f)*10^3 % Max amplitude of the foot signal MaxI_f=max(B_f) % Foot signal duration Ti_f=min(A_f) Tf_f=max(A_f) AT_f=(Tf_f-Ti_f)*10^6 %Save the parameters and the entire spike figure Table_parameters_spike1=table(MaxI_f,Q_footsignal,Ti_f,Tf_f,AT_f,AT_HW,AT_RT,halfMax,index1_HW,index2_HW,index1_RT,index2_RT,Q_spike,RT_90) writetable (Table_parameters_spike1,'Parameters 1 spike.xlsx') savefig(figure(1),'1st spike.fig') savefig(figure(2),'1st footsignal.fig') I tried this code https://matlab.fandom.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F but I cannot make it to work. For example, how can I do the first step, the plot? How can I plot the first file? Thanks! Jose Rego Terol https://uk.mathworks.com/matlabcentral/profile/authors/10100100-jose-rego-terol tag:uk.mathworks.com,2005:Question/476390 2019-08-16T11:39:13Z 2019-08-26T04:21:58Z How to close the boundary of a surface already generated by filling the holes from give matrix (attached), i am using following code to close the surface and to make a boundary but i am getting errors that indexing is out of bound. m = zeros(28) m = load('Matrix_Boundary_fills_3s_only.txt'); [rows, colms] = size(m); mOut = m; for row = 2 : rows % for colm = 1:colms if m(row-1, colm) == 3 mOut(row, colm+1) = 3; end if m(row-1, colm) == 3 || m(row-1,colm+2) == 3 mOut(row, colm+1) = 3; end if m(row-1, colm + 1) == 3 mOut(row, colm+1) = 3; end end end % end disp(mOut) thanks for all cooperation in advance. M.S. Khan https://uk.mathworks.com/matlabcentral/profile/authors/13647580-m-s-khan tag:uk.mathworks.com,2005:Question/477455 2019-08-24T20:46:28Z 2019-08-26T04:21:15Z Replacing strings with varying length and numbers I want to replace strings in varying length an numeric values. I know that the regexprep function is very powerfull in modifying strings, but all its syntax is very complex for me. My strings are structured like this: 'Phase1_525kV_4km_100m_0.5ohm' Now I want to be able to replace each number and its subsequent unit up to the unterscore symbol. So I need something that replaces all numbers in front of for exmaple km, but the length of the numeric values in front of the units are not allways the same. This should also include values for not whole numbers like '0.5ohm' which should also be replaced completele. What is the right syntax to use for the regexprep function? thanks Daniel Schmidt https://uk.mathworks.com/matlabcentral/profile/authors/15157770-daniel-schmidt tag:uk.mathworks.com,2005:Question/477541 2019-08-26T03:45:26Z 2019-08-26T04:18:47Z GUIDE: findobj() results in handle to deleted Line Hi All, I'm trying to extract line information from two different plots in GUIDE. My approach is to plot the first -> save it into base workspace -> switch axes -> plot the second -> save it into base workspace Once this is done, I then tried to check if this works using the following function: a = findobj(handles.axes1, 'Type', 'Line') b = findobj(handles.axes2, 'Type', 'Line') b does give a result, however a would give the following error: 'handle to deleted Line' Any idea for any workaround? Thanks! Hans Sunaryanto https://uk.mathworks.com/matlabcentral/profile/authors/9096811-hans-sunaryanto tag:uk.mathworks.com,2005:Question/89757 2013-10-10T04:58:51Z 2019-08-26T04:15:53Z How to divide 256X256 matrix into sixteen 16X16 blocks? I am having pixel value of an image as 256X256 matrix. I want to divide it into sixteen 16X16 matrix (ie)an image into sub blocks. It is needed to compare each 16X16 with other. Can anyone help? Malarvizhi https://uk.mathworks.com/matlabcentral/profile/authors/4654273-malarvizhi tag:uk.mathworks.com,2005:Question/477531 2019-08-26T00:01:28Z 2019-08-26T04:15:09Z Matlab rounding my values without me wanting it Hello, this basically frustrates me a bit, - if I have: Price = 20074.5; And I present it in my table like this: disp(table(Price,'VariableNames',{'answer'})); answer _____ 20075 I dont get decimals? Anyone know a way around this? I hope there can be some kind of solution without format long/short because I don't want to touch other things - Best Martin https://uk.mathworks.com/matlabcentral/profile/authors/4265483-martin tag:uk.mathworks.com,2005:Question/477392 2019-08-24T02:55:03Z 2019-08-26T03:50:11Z Do I need to consider loading Flash into RAM to run when I do code generation of DSP28335? Hello, I am working on code generation of DSP28335. Do I need to consider loading Flash into RAM to run? For example, the following sentence Now I have a serious performance problem and need help. Thank you! Xu Liu https://uk.mathworks.com/matlabcentral/profile/authors/15107939-xu-liu tag:uk.mathworks.com,2005:Question/477406 2019-08-24T08:21:40Z 2019-08-26T03:49:22Z LSQCURVEFIT for transfer function frequency response magnitude and phase curve fitting Hi all, can somebody please help me to find out transfer function time constants from LSQCURVEFIT function for identifying the transfer function through curvefitting the data available. Avaiable data frequency points (xdata) Magnitude and phase data(ydata) tau1Omega to tau6Omega are time constants required to be find out. current code is attached below, i'm encountering error ---------------------------------------------------------------------------------------------- Error using lsqcurvefit (line 251) Function value and YDATA sizes are not equal. Error in Untitled (line 32) e = lsqcurvefit(ObjFun01,var01,xdata,ydata2,lb,ub); ------------------------------------------------------------------------------------------------- cnst11 = 0.002777; lb = [0 0 0 0 0 0 0 0]; ub = [10 10 10 10 10 10 10 10]; var01 = [0 0 0 0 0 0 0 0]; xdata = load('xdata.txt'); ydata = load('ydata_in_magnitude_phase_form.txt'); ydata1 = ydata(1:1:end,:); ydata1(:,1) = ydata(:,1) ; %Load frequency ydata1(:,2) = ydata(:,2) ; %Load magnitude ydata1(:,3) = ydata(:,3) ; %Load frequency ydata1(:,4) = ydata(:,4) ; %Load phase ydata1(:,5) = 1; % weights ydata2 = ydata1(:,2).*exp(1i.*ydata1(:,4)); %converting to complex number form tau1Omga = var01(1,1) ; tau2Omga = var01(1,2) ; tau3Omga = var01(1,3) ; tau4Omga = var01(1,4) ; tau5Omga = var01(1,5) ; tau6Omga = var01(1,6) ; tau7Omga = var01(1,7) ; tau8Omga = var01(1,8) ; ObjFun01 = @(x,xdata)cnst11*((1+ tau1Omga*1i*x).*(1+ tau2Omga*1i*x).*(1+ tau3Omga*1i*x))./ ( (1+ tau4Omga*1i*x).*(1+ tau5Omga*1i*x).*(1+ tau6Omga*1i*x) ); e = lsqcurvefit(ObjFun01,var01,xdata,ydata2,lb,ub); any help in this regard would be greatly appreciated. PRAKASH G https://uk.mathworks.com/matlabcentral/profile/authors/3967053-prakash-g tag:uk.mathworks.com,2005:Question/477540 2019-08-26T03:30:43Z 2019-08-26T03:30:43Z Live Editor is always loading in macOS Beta 10.15 My matlab version is R2019a, and macOS version is 10.15 beta 7. And after upgrading my macOS, matlab live editor can't load any more. As long as I open a .mlx file, the live editor will display 'Loading' forever! My system language is Chinese btw Ruoxun Zhai https://uk.mathworks.com/matlabcentral/profile/authors/15938314-ruoxun-zhai tag:uk.mathworks.com,2005:Question/477538 2019-08-26T03:02:25Z 2019-08-26T03:13:04Z how to loop in dynamic dimension matrix? How could i loop in dynamic dimension array? Currently i'm using switch-case statement, but the code looks redundant, and it can only support limited dimension. function mode_vec = gen_mode_vec(freq,signal_size) mat=zeros(signal_size); dimension=length(signal_size); switch dimension case 1 for m=1:signal_size(1) mode_vec(m)=exp(1i*dot(m,freq)); end case 2 for m=1:signal_size(1) for n=1:signal_size(2) mode_vec(m,n)=exp(1i*dot([m,n],freq)); end end case 3 for m=1:signal_size(1) for n=1:signal_size(2) for k=1:signal_size(3) mode_vec(m,n,k)=exp(1i*dot([m,n,k],freq)); end end end case 4 for m=1:signal_size(1) for n=1:signal_size(2) for k=1:signal_size(3) for p=1:signal_size(4) mode_vec(m,n,k,p)=exp(1i*dot([m,n,k,p],freq)); end end end end otherwise fprintf('only support dimension 1-4\n' ); end mode_vec=reshape(mat,[],1); end Pengyuan Zhu https://uk.mathworks.com/matlabcentral/profile/authors/16026238-pengyuan-zhu tag:uk.mathworks.com,2005:Question/477104 2019-08-22T00:15:12Z 2019-08-26T03:10:24Z How would you plot a graph which a ball then rolls down (say a y=x^2 graph) How would you plot a graph which a ball then rolls down (say a y=x^2 graph) Sena Clarke https://uk.mathworks.com/matlabcentral/profile/authors/15996771-sena-clarke tag:uk.mathworks.com,2005:Question/301815 2016-09-03T10:37:51Z 2019-08-26T03:08:52Z How does pdist2 work? I am really confused. I have a matrix A= 1 2 3 4 I want to calculate dissimilarity. So I came to know that i could use euclidean to find. pdist2(A,A) gives me 0 2.828 2.828 0 But If I calculate manually I am getting 0 1.414 1.414 0 Why the result is multiplied by 2? GopsAB G https://uk.mathworks.com/matlabcentral/profile/authors/8657183-gopsab-g tag:uk.mathworks.com,2005:Question/477473 2019-08-25T04:01:58Z 2019-08-26T02:58:25Z Detection of 3D blobs with flat surfaces I have a 3D gray-scale array that represents a bag with several objects inside. I need to find (segment) any object with flat surface/s in the bag. Knowing the approximate intensity range of these objects, I binarized the volume, and removed objects with volumes below a threshold. The result was getting some of those objects as individual blobs and some attached to nearby objects. Now, I would like to detect blobs with flat surfaces. Any suggestion? Roohollah Milimonfared https://uk.mathworks.com/matlabcentral/profile/authors/7377106-roohollah-milimonfared tag:uk.mathworks.com,2005:Question/477533 2019-08-26T00:59:02Z 2019-08-26T02:56:27Z Make one word in path name a variable Can I make one variable in a path name a variable? 'C:\Users\Jane....' 'C:\Users\George....' Nancy Hammond https://uk.mathworks.com/matlabcentral/profile/authors/1441668-nancy-hammond tag:uk.mathworks.com,2005:Question/477536 2019-08-26T02:47:32Z 2019-08-26T02:54:02Z Saving multiple cropped images to a different folder So I am new to matlab and having trouble using the imwrite() function. I uncollaged an image (137 seperate images) and want to save the individual images to a new folder. How do I use the imwrite() function to save all the cropped images? I was using this post ... https://www.mathworks.com/matlabcentral/answers/73719-uncollage-a-collage-image Code... message = sprintf('Would you like to crop out and save each individual images?'); reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes'); % Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No. if strcmpi(reply, 'Yes') figure; % Create a new figure window. % Maximize the figure window. set(gcf, 'Units','Normalized','OuterPosition',[0 0 1 1]); for k = 1 : numberOfBlobs % Loop through all blobs. % Find the bounding box of each blob. thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob. % Extract out this zoop into it's own image. subImage = imcrop(originalImage, thisBlobsBoundingBox); % Saving the cropped image **imwrite(subImage,'path to folder') ?? ** end end no zoop https://uk.mathworks.com/matlabcentral/profile/authors/15501100-no-zoop tag:uk.mathworks.com,2005:Question/477537 2019-08-26T02:48:07Z 2019-08-26T02:48:07Z Can someone write a program that removes stimulus artifact from my continuous trace? I record single-unit spiking neuronal frequency from rat brains. I also apply deep brain stimulation. However, the stimulus interferes with the recording, and I cannot see the single units underneath. The below picture shows baseline recording, before stim is applied. I hope the picture is visible enough. The spikes show neuronal firing, which I would like to preserve. The timing of those spikes are especially important, because I am trying to observe changes in spike frequency over time as a result of DBS. The trace shown below is a 4 second piece of an hour-long recording. Then I apply stimulation at 150 Hz. The stimulation completely masks single unit activity, as you can see below. The magnification is the same as from above. Below is a 70x zoomed-out version of the same trace. You can see the point at which I turn on stim. I am wondering if any one is willing to write a program to help me remove the stimulus artifact while preserving the single units. Probably the most accurate way to do this is to do independent component analysis where you determine what a stim artifact looks like, and then you "subtract out" the artifact, and what should be left is the trace. I don't know if something like this is possible. If anyone is willing to have a go at this, please let me know, and I can send you a .mat file of the trace. If anyone has any other suggestions, I'll gladly take them. Thanks! Sid Sahai https://uk.mathworks.com/matlabcentral/profile/authors/13196171-sid-sahai tag:uk.mathworks.com,2005:Question/359880 2017-10-05T17:27:36Z 2019-08-26T02:39:02Z Is there any way to create inertial forces in Simscape Multibody? I am using Simscape Multibody to model an ocean wave energy converter. (I am using the same method (and some of the code) as WEC-Sim: http://wec-sim.github.io/WEC-Sim/, and they have the same problem). The problem is that: when you linearize the wave-structure problem you get inertial terms due to the fact that the body is pushing around water. That is, the "mass" is not just the mass of the rigid body, but also the mass of the fluid is moves. You get a so-called "added mass" matrix which represents the mass of the fluid that moves. The problem with the added mass matrix is that it has off-diagonal inertial terms, potentially between any two DOF. e.g. when it moves in surge, the pressure due to the moving fluid can create a moment in pitch. The added mass matrix for a 6DOF body is 6x6. This means, that you can't put it in as the mass, inertia values of a rigid body. What I've done (and I got this from WEC-Sim) is to move some of the added-mass terms to the mass inertia values of a rigid body, but keep the off-diagonal terms and create a force proportional to acceleration. This creates an algebraic loop that can't be solved in general. The next solution is to introduce a time delay. This works for most situations, except when the off-diagonal terms are large, then it creates instabilities. The best solution for me would be able to specify the full 6x6 mass matrix in the Simscape Multibody rigid body, but this doesn't seem to be an option. Is there any other way to create this type of force? Cameron McNatt https://uk.mathworks.com/matlabcentral/profile/authors/8246849-cameron-mcnatt tag:uk.mathworks.com,2005:Question/477521 2019-08-25T19:02:07Z 2019-08-26T02:33:22Z Getting values from a for loop when specific condition met I am doing a loop, and want the iteration stops when condition of x = 5 however, the code terminates before x=5 ? So any help please clear all; clc; x=[1 2 3 4 5 6 7 8 9 10]; for n=1:10 if x(n)>= 5; break end disp('how many iteration done now'); final(n,:)=x(n) z(n,:)=x(n)+2 end Ali Tawfik https://uk.mathworks.com/matlabcentral/profile/authors/13520758-ali-tawfik tag:uk.mathworks.com,2005:Question/300022 2016-08-18T13:00:11Z 2019-08-26T02:25:44Z I want to spatially distribute 1000 mobile devices in a network according to Poisson Point Process. I have 1000 mobile devices or Users. I want to spatially distribute them in a Network(Area detail given in next line) according to Poisson Point Process where the density rate or Lambda is 100. Network is a circular Area of Radius 1000m. poissrnd function only gives me a random variable. What can I do with it to spatially distribute them?. Please inform regarding it. I would be obliged. Mohammad Ahmed https://uk.mathworks.com/matlabcentral/profile/authors/5352980-mohammad-ahmed tag:uk.mathworks.com,2005:Question/315717 2016-12-06T19:36:42Z 2019-08-26T02:25:08Z Poisson Point Process with fixed N I came across this in a network model: *Distribute _N_ points according to a homogeneous Poisson point process in a two-dimensional space of unit area.* No more info was given. Could somebody enlighten me on what this means? Usually I think of this as: 1) Generate the random variable _N_ = _n_ distributed as Poisson for a given lambda and area. 2) Generate _n_ uniform points in that area. But in the statement in bold text above _N_ is fixed from the beginning. What would be a procedure for that (in Matlab)? Tobias Johansson https://uk.mathworks.com/matlabcentral/profile/authors/4299594-tobias-johansson tag:uk.mathworks.com,2005:Question/477500 2019-08-25T14:21:15Z 2019-08-26T02:15:31Z How can I multiply two big matrices, avoiding out of memory? for example, I = A*B, in which size(A) = [1024^2, 3], size(B) = [3, 1001^2]. So, size(I) = [1024^2, 1001^2] which could cause out of memory. I have tried using tall arrays like the following code: AA = tall(A); II = AA*B; I = gather(II); but the command line still shows error: out of memory. Sincerely thanks! %% update %% Thanks for your answer very much! Originally, I want to calculate this equation: where so I write the following matrix equation: m and n are variable, for example,m = 1024, n=1001^2 whatever. It is worth noting that the two matrices in exp(...) are not too big, but the result of their multiplication is too large to be storaged in memory. I've tried to split the two matrices into several small patches, but it need to input the number of the patches manually rather than automatically, moreover, the for loop could not be avoided in this case. I have no good ideal currently. Best regards! Xin Liu https://uk.mathworks.com/matlabcentral/profile/authors/13613540-xin-liu tag:uk.mathworks.com,2005:Question/477124 2019-08-22T04:43:00Z 2019-08-26T01:58:24Z 2D MUSIC algorithm for range-azimuth FMCW data processing Hi, I want to draw a map of range-azimuth. I can achieve 1D music, but there is some problem with 2D music for range-azimuth. %X_ is the signal. J = fliplr(eye(m1*m2,m1*m2)); Cx_ = 1/(2*p1*p2)*(X_*X_' + J*(X_*X_')*J); [EV,D] = eig(Cx_); %D for eigenvalues and EV for eigenvector EVA_temp = diag(D)'; [EVA,I] = sort(EVA_temp); Sort_EV = fliplr(EV(:,I)); %eig % W_ = Sort_EV(:,K+1:end); %(m1*m2)*(m1*m2-K) W_ = Sort_EV(:,4:end); for r = 1:length(VecR) for theta = 1:length(VecA) a_1 = []; for mm1 = 0:m1-1 tao_i(mm1+1) = 2/c*( VecR(r) + mm1*d*sin(VecA(theta)) ); aa = exp(1i*2*pi*tao_i(mm1+1)*(linspace(fc,fc+alpha*(m2-1)/fs,m2) ) ); %0- a_1 = cat(2,a_1,aa); end a = a_1.'; Smusic(r,theta) = 1/(a'*W_*W_'*a); end end S_ = Smusic/(max(max(Smusic))); figure,imagesc(VecA*180/pi,VecR(1:50),log(abs(S_)));xlabel('Azimuth(deg)');ylabel('Range(m)');title('range-azimuth'); % figure,imagesc(abs(Smusic)); Shirleyuue Jiang https://uk.mathworks.com/matlabcentral/profile/authors/16000440-shirleyuue-jiang tag:uk.mathworks.com,2005:Question/477534 2019-08-26T01:02:08Z 2019-08-26T01:58:22Z Quiver different skip factor for rows and columns Hello, I'm trying to reduce the number of arrows in quiver and successfully did it using below code: V=[xmat' ymat' vx' vy']; skip=2; V_skip=V(1:skip:end,:); figure quiver(V_skip(:,1),V_skip(:,2),V_skip(:,3),V_skip(:,4)); Which equally plot every other element along x and y direction. However, I want to skip more arrow along y direction. For example skip 2 elements along x direction and skip 4 elements along y direction. Is it possible to do so? Thank you in advance. Muhammad Sofwan Bin Mohamad https://uk.mathworks.com/matlabcentral/profile/authors/10712567-muhammad-sofwan-bin-mohamad tag:uk.mathworks.com,2005:Question/284883 2016-05-19T00:10:37Z 2019-08-26T01:47:22Z How to smooth out or fit a surface? I have my data stored in a 44 by 44 matrix. When I plot this data, it has a lot of irregular peaks. I want a smooth surface instead. (I cannot use the cftool since I've got a long loop and cannot do it manually everytime.) Following is the code I'm using but I get an error saying that x and y should be a column matrix. If I remove the fit command line, the whole code runs perfectly fine. Can someone please point out my mistake or suggest changes to this code? x = 1:44; y = 1:44; for i = 1:35 a = xlsread('\\uoa.auckland.ac.nz\engdfs\Homeair.xlsx',strcat('CO',int2str(46*i-18),':','EF',int2str(46*i+25))); b = fit([x,y,],a,'lowess'); figure; surf(x,y,b); axis([0 44 0 44 -50 120]); fname = sprintf('A%d.png',i); saveas(gcf,fname); end Jasnoor Singh https://uk.mathworks.com/matlabcentral/profile/authors/7777984-jasnoor-singh tag:uk.mathworks.com,2005:Question/473595 2019-07-26T10:22:58Z 2019-08-26T01:47:06Z How to increase the resolution of Point cloud in 2D? Hello, I project a 3D PCD in two dimensions and calculate the distance value of each point cloud. This is a 2d PCD that uses gscatter to represent different colors depending on distance.ed this repository(https://github.com/balcilar/DenseDepthMap). It works weel on kitti dataset but it doens't work on my own dataset(point cloud). Is there any way I can express my pcd with higher resolution like the respository? jin soo kim https://uk.mathworks.com/matlabcentral/profile/authors/13030628-jin-soo-kim tag:uk.mathworks.com,2005:Question/477386 2019-08-24T00:30:41Z 2019-08-26T01:44:57Z I want to smooth the boarder of all white areas in this Binary Image (even the tiny ones). Consider it like smoothing with your hand. Muhammad Saafan https://uk.mathworks.com/matlabcentral/profile/authors/15262815-muhammad-saafan tag:uk.mathworks.com,2005:Question/477529 2019-08-25T23:16:26Z 2019-08-26T01:36:01Z cant scroll in editor Matlab freezes. Can't scroll through editor. Cursor wont move Nancy Hammond https://uk.mathworks.com/matlabcentral/profile/authors/1441668-nancy-hammond tag:uk.mathworks.com,2005:Question/477532 2019-08-26T00:27:32Z 2019-08-26T01:31:42Z Assigned colorbar heights in pcolor subplots I am making a lot of figures with pcolor subplots. I want all the x-axes to match so I am manually assigned the colorbar positions. Right now I am doing this by a trial and error approach to get the colorbars lined up. Is there a "cheat sheet" somewhere that would tell me where the default subplots line up for assigning heights of the colorbars. This is the line I am playing with c=colorbar; set(c, 'Position', [0.93 .11 .015 .2]) Does my question make sense? Heidi Hirsh https://uk.mathworks.com/matlabcentral/profile/authors/6143971-heidi-hirsh tag:uk.mathworks.com,2005:Question/474848 2019-08-05T05:59:39Z 2019-08-26T01:06:39Z Training YOLO V2 with multiple (more than one) classes Hi all, When I train YOLOV2 with single class (person) using trainYOLOv2ObjectDetector, I can get precision/recall of 0.92 but when I add another class (car) with same images and just few car labels, the accuracy is 0, meaning even the person cannot be detected in any of the images even my training images! I even use AnchorBox estimation and treid many times. All the matlab examples are tarined only on single objects but how about if we have more than one class to be trained? Does anyone have any success to help me please? Zahra Moayed https://uk.mathworks.com/matlabcentral/profile/authors/11782601-zahra-moayed tag:uk.mathworks.com,2005:Question/477504 2019-08-25T14:54:19Z 2019-08-26T00:47:54Z how to choose different colors for nodes t = [1 1 1 1]; h = [2 3 4 5]; g = graph(t,h); p = plot(g); g.Edges.value = [10; 20; 20; 100]; g.Nodes.value = [0.3; 0.564; 12; 1; 0.005]; g.Nodes.NodeColors = g.Nodes.value; g.Edges.EdgeColors = g.Edges.value; p.NodeCData = g.Nodes.NodeColors; p.EdgeCData = g.Edges.EdgeColors; q= plot(g,'NodeCData',g.Nodes.NodeColors); colorbar t is the source node as input and h is demand node as output. I want to two different colors for input and output. But I don't find correct way. Plz help me to solve it. Kashfia Mahin https://uk.mathworks.com/matlabcentral/profile/authors/13150227-kashfia-mahin tag:uk.mathworks.com,2005:Question/477479 2019-08-25T05:38:41Z 2019-08-25T23:58:21Z Is there a possibility to use varargin()? Is there any other way to perform such operation? c = {rand,rand(4)}; z = @(...) mean(...); z(c{:}) The same can be achieved using cellfun(), but is it possible only through anonymous function? madhan ravi https://uk.mathworks.com/matlabcentral/profile/authors/12308260-madhan-ravi tag:uk.mathworks.com,2005:Question/477530 2019-08-25T23:41:19Z 2019-08-25T23:57:45Z Update Array - I want to move the value at TEMP through to an array and display it all possible values of temp. %disp('the parent objective values are'); for k=1:pop_size temp=0; temp1=0; car=[] obj(k)=0; for i=1:n temp1=temp1+Pg(k,i); temp=temp+a(i)+b(i)*Pg(k,i)+c(i)*Pg(k,i)*Pg(k,i); car=temp end temp2=Pd-temp1; temp3=0; if(temp2>0) temp3=10.0*temp2; end obj(k)=temp+temp3; % fprintf('fuelcost=%7.3f \$\n',obj(k)); end Jeev reji https://uk.mathworks.com/matlabcentral/profile/authors/7663850-jeev-reji tag:uk.mathworks.com,2005:Question/477513 2019-08-25T16:59:16Z 2019-08-25T23:37:38Z Pre-processing tall array / datastore data Please pardon me if this has been asked before. What is the most efficient way to pre-process a large wide table (about 10,000,000 rows by 500 columns) currently divided in many small tables in separate mat-files. The data may be quite sparse in areas and is mostly numeric with a datetime column, some categorical, and some text fields. For example, should I: stack() the small tables tables but leave them in separate files combine them into a giant wide table combine them into a stacked very tall table delete many NaNs significantly reducing the height of the stacked table use sparse() on a wide table Those are just some thoughts. Please let me know the best way. Thank You, Michael Michael https://uk.mathworks.com/matlabcentral/profile/authors/2195244-michael tag:uk.mathworks.com,2005:Question/477523 2019-08-25T19:54:22Z 2019-08-25T23:32:36Z Fit sinc square to FFT peak Good evening, I have an FFT peak to which I need to fit a sinc square function to obtain an improved estimate for the peak location and peak width. However there doesn't seem to be a function to perform this properly. Has someone done this before/knows the correct function? Below is the figure in question. Any help would be much appreciated. Tobias Reichold https://uk.mathworks.com/matlabcentral/profile/authors/6946493-tobias-reichold tag:uk.mathworks.com,2005:Question/477446 2019-08-24T18:53:43Z 2019-08-25T23:30:30Z interp1 for matrix I have two velocity matrices that I want to interpolate onto a new time vector. The matrices are both 8011x60 doubles where the rows are different times and the columns are depths. Can I use interp 1 to interpolate each row onto the new time? This is how I have it set up now (how I would use interp1 if U and V were vectors): I took a screenshot of my workspace too if that helps. U_new = interp1(Date,U,M1time); V_new = interp1(Date,V,M1time); Temp_new = interp1(Date,Temp,M1time); Heidi Hirsh https://uk.mathworks.com/matlabcentral/profile/authors/6143971-heidi-hirsh tag:uk.mathworks.com,2005:Question/382590 2018-02-14T08:58:14Z 2019-08-25T23:28:48Z How to solve heat equation on matlab ? dt=0.1; dx=1; D=0.002;%thermal coefficient s=(D*0.1)/(1)^2; %s=D*dt/dx^2 T(1,1)=0.2;%initial condition t=0:0.1:1; x=0:1:10; for n=1:length(t-1) for j=2:length(x-1) T(n+1,j)=s*T(n,j+1)+(1-2*s)*T(n,j)+s*T(n,j-1); end end but the error I,m getting is in the matrix dimension : Index exceeds matrix dimensions. Error in untitled (line 13) T(n+1,j)=s*T(n,j+1)+(1-2*s)*T(n,j)+s*T(n,j-1); alaa akkoush https://uk.mathworks.com/matlabcentral/profile/authors/10119302-alaa-akkoush tag:uk.mathworks.com,2005:Question/476843 2019-08-20T11:38:57Z 2019-08-25T23:06:37Z Converting symbolic exponential function into linear form Hi, below I have a code to solve symbolically differential equation. My question is simple: How to present the solution in linear form instead of exponential form. So basically what is the code to logarithm symbolically function on both sides of the solved equation? syms A(t) k A0 R = -diff(A) == k*A; cond = A(0) == A0; A(t) = dsolve(R,cond) chemeng100 https://uk.mathworks.com/matlabcentral/profile/authors/9376068-chemeng100 tag:uk.mathworks.com,2005:Question/477492 2019-08-25T11:41:13Z 2019-08-25T23:05:14Z How to implement MyClass that overloads all methods of a certain naitive class ? I have a class MyClass that has a numerical property Val. I want the class to overload any/all numerical functions, such that fcn(Obj) returns fcn(Obj.Val). I can implement separately an overload of any given function (say: sin, cos, and so), but I want a generic way to essentially overload ANY numeric function. Is there a way to do it? royk https://uk.mathworks.com/matlabcentral/profile/authors/11390442-royk tag:uk.mathworks.com,2005:Question/366464 2017-11-11T17:22:30Z 2019-08-25T22:59:50Z Documentation of Editor API There is an API to interact with the files opened in the editor, see e.g. matlab.desktop.editor.getAll But how can I find the corresponding docs or further explanations? These trials are not successful in R2016b: docsearch editor docsearch editor api docsearch matlab.desktop.editor docsearch getAll doc matlab.desktop.editor.getAll % [EDITED: This DOES work!] doc matlab.desktop.editor % This also - See Michelle's answer Searching in the net does not find the official documentation also, e.g. asking Google for "matlab.desktop.editor.getAll" provides these links on top: * <https://www.mathworks.com/matlabcentral/answers/10577-how-to-get-a-list-of-all-open-files-in-matlab-editor> * <https://www.mathworks.com/matlabcentral/answers/16389-how-can-i-save-a-list-of-open-m-files> * <https://www.mathworks.com/matlabcentral/answers/119438-how-can-i-create-a-list-of-m-files-currently-open-in-the-editor> * ... # Is this API documented? # If so, where do I find an exhaustive documentation? # How could I find this by my own? PS. What a pity that the powerful feature of running macros in the editor has been removed after Matlab version 5.3! <https://www.mathworks.com/matlabcentral/fileexchange/24615-editormacro-assign-a-macro-to-a-keyboard-key-stroke-in-the-matlab-editor-and-command-window?focused=5177605&tab=function FEX: EditorMacro> does not work as stable as I need it. Jan https://uk.mathworks.com/matlabcentral/profile/authors/869888-jan tag:uk.mathworks.com,2005:Question/477464 2019-08-24T23:14:59Z 2019-08-25T22:48:06Z replace frame in video Hi I use matlab R2018b I insert text as watermark in specific frame from video ( using DCT ) but I have some problem 1- I want to replace the original frame by the watermarked frame 2- the text that I can insert just one character (8 binary) how can I insert more LEKHCHINE Somia https://uk.mathworks.com/matlabcentral/profile/authors/15852088-lekhchine-somia tag:uk.mathworks.com,2005:Question/409320 2018-07-08T14:37:38Z 2019-08-25T22:46:54Z Rectify the error in imread Whenever i try to execute this command: a=imread('itsarose.jpg'); It shows an error: Error using imread>get_full_filename (line 516) File "itsarose.jpg" does not exist. Error in imread (line 340) fullname = get_full_filename(filename); i just followed it with an imshow command , nothing much.I use MatlabR2018a. What can i do to rectify this? varsha reddy https://uk.mathworks.com/matlabcentral/profile/authors/12273820-varsha-reddy tag:uk.mathworks.com,2005:Question/477517 2019-08-25T17:42:36Z 2019-08-25T22:44:29Z The real-valued amplitude response Where amplitude response A(w) is continuous and real-valued. How i can write a Matlab function that uses the FFT to compute A(w) from the impulse response h(n) at the frequency points. Matlab header: function [A,w] = firamp(h,type,L) % Amplitude response of a linear-phase FIR filter % A : amplitude response at the frequencies w w : [0:L-1]*(2*pi/L); h : impulse response type = [1,2,3,4] Johan Johan https://uk.mathworks.com/matlabcentral/profile/authors/12590840-johan-johan tag:uk.mathworks.com,2005:Question/476719 2019-08-19T15:52:51Z 2019-08-25T22:44:10Z Linear programming and cash flow matching I am trying to solve a simple large scale linear /non-linear programming problem to match liability cash flows with asset cash flows. I am thinking between MATLAB and R to solve this problem. I have explained the problem below and I was wondering whether MATLAB can be used to solve this. Can anyone please let me know if and how MATLAB can be used to solve this problem? If any particular MATLAB optimization toolboxes will be needed then please let me know. A fixed set of liability cash flows are given, say for the next 20 years. We need to select appropriate bonds to match these liability cash flows, ignoring interest rate risk and other market risks. We are given market value of bonds and their cash flows based on which we need to decide which bonds to select. The objective function is to minimise value of liabilities, which is calculated by discounting liability cash flows at a flat discount rate, say 1% + a spread. This spread depends upon internal rate of return of the assets portfolio, e.g. spread = 50% of internal rate of return on the asset portfolio (the higher the spread, the lower the value of liabilities. Constraints are: weights of bonds can be either zero or 1 (i.e. either we invest in a bond or we don’t) and asset cash flows can be lower than liability cash flows in certain years but cumulatively say at every 3 years asset cash flows should exceed liability cash flows. L Smith https://uk.mathworks.com/matlabcentral/profile/authors/15981591-l-smith