https://uk.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions20190826T04:53:09Ztag:uk.mathworks.com,2005:Question/47751820190825T17:44:00Z20190826T04:53:09Zhow 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 SEhttps://uk.mathworks.com/matlabcentral/profile/authors/6648456lolasetag:uk.mathworks.com,2005:Question/29760620160729T02:04:02Z20190826T04:49:33ZUndefined 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 Algeboryhttps://uk.mathworks.com/matlabcentral/profile/authors/8477975bahaaalgeborytag:uk.mathworks.com,2005:Question/47754220190826T03:45:45Z20190826T04:48:27ZUsing GPU on multiple nested loopsThe 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+(znmaxznmin)*double(iz1)/double(nzs1);
ekzz=ekz^z;
for iy=1:nys
y=ynmin+(ynmaxynmin)*double(iy1)/double(nys1);
ekyy=eky^y;
for ix=1:nxs
x=xnmin+(xnmaxxnmin)*double(ix1)/double(nxs1);
ekxx=ekx^x;
wfrtmp(ix,iy,iz)=wfrtmp(ix,iy,iz)+coefft*ekxx*ekyy*ekzz;
end
end
end
end
wfr(ispin,:,:,:)=wfrtmp/sqrt(Vcell);
tocJhinhwan Leehttps://uk.mathworks.com/matlabcentral/profile/authors/2498849jhinhwanleetag:uk.mathworks.com,2005:Question/3663620120426T12:24:39Z20190826T04:45:17Zdecompressing 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')Pathttps://uk.mathworks.com/matlabcentral/profile/authors/3009067pattag:uk.mathworks.com,2005:Question/47754420190826T04:42:34Z20190826T04:42:34Zhow to connect simscape to sim electronicsi designed a solar inverter but output of solar is not conected to input terminal of inverterchilukamari pavankalyanhttps://uk.mathworks.com/matlabcentral/profile/authors/15380852chilukamaripavankalyantag:uk.mathworks.com,2005:Question/47754320190826T04:34:24Z20190826T04:38:27ZA problem with multiple columns in legendHi 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)Creatleehttps://uk.mathworks.com/matlabcentral/profile/authors/9994906creatleetag:uk.mathworks.com,2005:Question/47753920190826T03:17:12Z20190826T04:34:39ZPlotting a graphical converge inside a While  Newton Raphson numerical methodHi, 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(((pp0)/p)*100);
p0 = p;
i = i+1;
end
fprintf('\n Valor= %8.3f ',p0)
plot (p)
fplot (0)
hold offLuis Francisco Sanchezhttps://uk.mathworks.com/matlabcentral/profile/authors/13269652luisfranciscosancheztag:uk.mathworks.com,2005:Question/47752820190825T22:55:21Z20190826T04:26:49ZHow can Ido the same operations with multiples files using forloopI 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 forloop seems to be the best function, but I don't know how the (nested) forloop 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 forloop 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_HWTi_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_RTTi_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_fTi_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 Terolhttps://uk.mathworks.com/matlabcentral/profile/authors/10100100joseregoteroltag:uk.mathworks.com,2005:Question/47639020190816T11:39:13Z20190826T04:21:58ZHow to close the boundary of a surface already generated by filling the holesfrom 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(row1, colm) == 3
mOut(row, colm+1) = 3;
end
if m(row1, colm) == 3  m(row1,colm+2) == 3
mOut(row, colm+1) = 3;
end
if m(row1, colm + 1) == 3
mOut(row, colm+1) = 3;
end
end
end
% end
disp(mOut)
thanks for all cooperation in advance. M.S. Khanhttps://uk.mathworks.com/matlabcentral/profile/authors/13647580mskhantag:uk.mathworks.com,2005:Question/47745520190824T20:46:28Z20190826T04:21:15ZReplacing strings with varying length and numbersI 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?
thanksDaniel Schmidthttps://uk.mathworks.com/matlabcentral/profile/authors/15157770danielschmidttag:uk.mathworks.com,2005:Question/47754120190826T03:45:26Z20190826T04:18:47ZGUIDE: 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 Sunaryantohttps://uk.mathworks.com/matlabcentral/profile/authors/9096811hanssunaryantotag:uk.mathworks.com,2005:Question/8975720131010T04:58:51Z20190826T04:15:53ZHow 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? Malarvizhihttps://uk.mathworks.com/matlabcentral/profile/authors/4654273malarvizhitag:uk.mathworks.com,2005:Question/47753120190826T00:01:28Z20190826T04:15:09ZMatlab rounding my values without me wanting itHello, 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
 BestMartinhttps://uk.mathworks.com/matlabcentral/profile/authors/4265483martintag:uk.mathworks.com,2005:Question/47739220190824T02:55:03Z20190826T03:50:11ZDo 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 Liuhttps://uk.mathworks.com/matlabcentral/profile/authors/15107939xuliutag:uk.mathworks.com,2005:Question/47740620190824T08:21:40Z20190826T03:49:22ZLSQCURVEFIT for transfer function frequency response magnitude and phase curve fittingHi 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 Ghttps://uk.mathworks.com/matlabcentral/profile/authors/3967053prakashgtag:uk.mathworks.com,2005:Question/47754020190826T03:30:43Z20190826T03:30:43ZLive Editor is always loading in macOS Beta 10.15My 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 btwRuoxun Zhaihttps://uk.mathworks.com/matlabcentral/profile/authors/15938314ruoxunzhaitag:uk.mathworks.com,2005:Question/47753820190826T03:02:25Z20190826T03:13:04Zhow to loop in dynamic dimension matrix?How could i loop in dynamic dimension array?
Currently i'm using switchcase 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 14\n' );
end
mode_vec=reshape(mat,[],1);
endPengyuan Zhuhttps://uk.mathworks.com/matlabcentral/profile/authors/16026238pengyuanzhutag:uk.mathworks.com,2005:Question/47710420190822T00:15:12Z20190826T03:10:24ZHow 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 Clarkehttps://uk.mathworks.com/matlabcentral/profile/authors/15996771senaclarketag:uk.mathworks.com,2005:Question/30181520160903T10:37:51Z20190826T03:08:52ZHow 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 Ghttps://uk.mathworks.com/matlabcentral/profile/authors/8657183gopsabgtag:uk.mathworks.com,2005:Question/47747320190825T04:01:58Z20190826T02:58:25ZDetection of 3D blobs with flat surfacesI have a 3D grayscale 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 Milimonfaredhttps://uk.mathworks.com/matlabcentral/profile/authors/7377106roohollahmilimonfaredtag:uk.mathworks.com,2005:Question/47753320190826T00:59:02Z20190826T02:56:27ZMake one word in path name a variableCan I make one variable in a path name a variable?
'C:\Users\Jane....'
'C:\Users\George....'Nancy Hammondhttps://uk.mathworks.com/matlabcentral/profile/authors/1441668nancyhammondtag:uk.mathworks.com,2005:Question/47753620190826T02:47:32Z20190826T02:54:02ZSaving 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/73719uncollageacollageimage
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 zoophttps://uk.mathworks.com/matlabcentral/profile/authors/15501100nozooptag:uk.mathworks.com,2005:Question/47753720190826T02:48:07Z20190826T02:48:07ZCan someone write a program that removes stimulus artifact from my continuous trace?I record singleunit 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 hourlong 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 zoomedout 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 Sahaihttps://uk.mathworks.com/matlabcentral/profile/authors/13196171sidsahaitag:uk.mathworks.com,2005:Question/35988020171005T17:27:36Z20190826T02:39:02ZIs 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 WECSim: http://wecsim.github.io/WECSim/, and they have the same problem).
The problem is that: when you linearize the wavestructure 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 socalled "added mass" matrix which represents the mass of the fluid that moves.
The problem with the added mass matrix is that it has offdiagonal 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 WECSim) is to move some of the addedmass terms to the mass inertia values of a rigid body, but keep the offdiagonal 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 offdiagonal 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 McNatthttps://uk.mathworks.com/matlabcentral/profile/authors/8246849cameronmcnatttag:uk.mathworks.com,2005:Question/47752120190825T19:02:07Z20190826T02:33:22ZGetting 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 Tawfikhttps://uk.mathworks.com/matlabcentral/profile/authors/13520758alitawfiktag:uk.mathworks.com,2005:Question/30002220160818T13:00:11Z20190826T02:25:44ZI 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 Ahmedhttps://uk.mathworks.com/matlabcentral/profile/authors/5352980mohammadahmedtag:uk.mathworks.com,2005:Question/31571720161206T19:36:42Z20190826T02:25:08ZPoisson Point Process with fixed NI came across this in a network model:
*Distribute _N_ points according to a homogeneous Poisson point process in a twodimensional 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 Johanssonhttps://uk.mathworks.com/matlabcentral/profile/authors/4299594tobiasjohanssontag:uk.mathworks.com,2005:Question/47750020190825T14:21:15Z20190826T02:15:31ZHow 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 Liuhttps://uk.mathworks.com/matlabcentral/profile/authors/13613540xinliutag:uk.mathworks.com,2005:Question/47712420190822T04:43:00Z20190826T01:58:24Z2D MUSIC algorithm for rangeazimuth FMCW data processingHi, I want to draw a map of rangeazimuth. I can achieve 1D music, but there is some problem with 2D music for rangeazimuth.
%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*m2K)
W_ = Sort_EV(:,4:end);
for r = 1:length(VecR)
for theta = 1:length(VecA)
a_1 = [];
for mm1 = 0:m11
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*(m21)/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('rangeazimuth');
% figure,imagesc(abs(Smusic));Shirleyuue Jianghttps://uk.mathworks.com/matlabcentral/profile/authors/16000440shirleyuuejiangtag:uk.mathworks.com,2005:Question/47753420190826T01:02:08Z20190826T01:58:22ZQuiver different skip factor for rows and columnsHello,
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 Mohamadhttps://uk.mathworks.com/matlabcentral/profile/authors/10712567muhammadsofwanbinmohamadtag:uk.mathworks.com,2005:Question/28488320160519T00:10:37Z20190826T01:47:22ZHow 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*i18),':','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);
endJasnoor Singhhttps://uk.mathworks.com/matlabcentral/profile/authors/7777984jasnoorsinghtag:uk.mathworks.com,2005:Question/47359520190726T10:22:58Z20190826T01:47:06ZHow 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 kimhttps://uk.mathworks.com/matlabcentral/profile/authors/13030628jinsookimtag:uk.mathworks.com,2005:Question/47738620190824T00:30:41Z20190826T01:44:57ZI 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 Saafanhttps://uk.mathworks.com/matlabcentral/profile/authors/15262815muhammadsaafantag:uk.mathworks.com,2005:Question/47752920190825T23:16:26Z20190826T01:36:01Zcant scroll in editorMatlab freezes. Can't scroll through editor. Cursor wont moveNancy Hammondhttps://uk.mathworks.com/matlabcentral/profile/authors/1441668nancyhammondtag:uk.mathworks.com,2005:Question/47753220190826T00:27:32Z20190826T01:31:42ZAssigned colorbar heights in pcolor subplotsI am making a lot of figures with pcolor subplots. I want all the xaxes 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 Hirshhttps://uk.mathworks.com/matlabcentral/profile/authors/6143971heidihirshtag:uk.mathworks.com,2005:Question/47484820190805T05:59:39Z20190826T01:06:39ZTraining YOLO V2 with multiple (more than one) classesHi 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 Moayedhttps://uk.mathworks.com/matlabcentral/profile/authors/11782601zahramoayedtag:uk.mathworks.com,2005:Question/47750420190825T14:54:19Z20190826T00:47:54Zhow to choose different colors for nodest = [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 Mahinhttps://uk.mathworks.com/matlabcentral/profile/authors/13150227kashfiamahintag:uk.mathworks.com,2005:Question/47747920190825T05:38:41Z20190825T23:58:21ZIs 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 ravihttps://uk.mathworks.com/matlabcentral/profile/authors/12308260madhanravitag:uk.mathworks.com,2005:Question/47753020190825T23:41:19Z20190825T23:57:45ZUpdate 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=Pdtemp1;
temp3=0;
if(temp2>0)
temp3=10.0*temp2;
end
obj(k)=temp+temp3;
% fprintf('fuelcost=%7.3f $\n',obj(k));
end
Jeev rejihttps://uk.mathworks.com/matlabcentral/profile/authors/7663850jeevrejitag:uk.mathworks.com,2005:Question/47751320190825T16:59:16Z20190825T23:37:38ZPreprocessing tall array / datastore dataPlease pardon me if this has been asked before.
What is the most efficient way to preprocess a large wide table (about 10,000,000 rows by 500 columns) currently divided in many small tables in separate matfiles. 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
Michaelhttps://uk.mathworks.com/matlabcentral/profile/authors/2195244michaeltag:uk.mathworks.com,2005:Question/47752320190825T19:54:22Z20190825T23:32:36ZFit sinc square to FFT peakGood 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 Reicholdhttps://uk.mathworks.com/matlabcentral/profile/authors/6946493tobiasreicholdtag:uk.mathworks.com,2005:Question/47744620190824T18:53:43Z20190825T23:30:30Zinterp1 for matrixI 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 Hirshhttps://uk.mathworks.com/matlabcentral/profile/authors/6143971heidihirshtag:uk.mathworks.com,2005:Question/38259020180214T08:58:14Z20190825T23:28:48ZHow 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(t1)
for j=2:length(x1)
T(n+1,j)=s*T(n,j+1)+(12*s)*T(n,j)+s*T(n,j1);
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)+(12*s)*T(n,j)+s*T(n,j1);alaa akkoushhttps://uk.mathworks.com/matlabcentral/profile/authors/10119302alaaakkoushtag:uk.mathworks.com,2005:Question/47684320190820T11:38:57Z20190825T23:06:37ZConverting symbolic exponential function into linear formHi, 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)chemeng100https://uk.mathworks.com/matlabcentral/profile/authors/9376068chemeng100tag:uk.mathworks.com,2005:Question/47749220190825T11:41:13Z20190825T23:05:14ZHow 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?roykhttps://uk.mathworks.com/matlabcentral/profile/authors/11390442royktag:uk.mathworks.com,2005:Question/36646420171111T17:22:30Z20190825T22:59:50ZDocumentation of Editor APIThere 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/10577howtogetalistofallopenfilesinmatlabeditor>
* <https://www.mathworks.com/matlabcentral/answers/16389howcanisavealistofopenmfiles>
* <https://www.mathworks.com/matlabcentral/answers/119438howcanicreatealistofmfilescurrentlyopenintheeditor>
* ...
# 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/24615editormacroassignamacrotoakeyboardkeystrokeinthematlabeditorandcommandwindow?focused=5177605&tab=function FEX: EditorMacro> does not work as stable as I need it.Janhttps://uk.mathworks.com/matlabcentral/profile/authors/869888jantag:uk.mathworks.com,2005:Question/47746420190824T23:14:59Z20190825T22:48:06Zreplace 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 Somiahttps://uk.mathworks.com/matlabcentral/profile/authors/15852088lekhchinesomiatag:uk.mathworks.com,2005:Question/40932020180708T14:37:38Z20190825T22:46:54ZRectify the error in imreadWhenever 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 reddyhttps://uk.mathworks.com/matlabcentral/profile/authors/12273820varshareddytag:uk.mathworks.com,2005:Question/47751720190825T17:42:36Z20190825T22:44:29ZThe realvalued amplitude response Where amplitude response A(w) is continuous and realvalued.
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 linearphase FIR filter
% A : amplitude response at the frequencies w
w : [0:L1]*(2*pi/L);
h : impulse response
type = [1,2,3,4]
Johan Johanhttps://uk.mathworks.com/matlabcentral/profile/authors/12590840johanjohantag:uk.mathworks.com,2005:Question/47671920190819T15:52:51Z20190825T22:44:10ZLinear programming and cash flow matching I am trying to solve a simple large scale linear /nonlinear 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 Smithhttps://uk.mathworks.com/matlabcentral/profile/authors/15981591lsmith