https://cn.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-09-23T18:08:06Ztag:cn.mathworks.com,2005:Question/3580392017-09-23T13:59:18Z2017-09-23T18:08:06ZERROR: MATLAB R2017a cannot run RTI Connext Shapes Demo<pre class="language-matlab">DDS.import('ShapeType.idl','matlab', 'f')
Warning: DDS.Utilities.getRtiPaths: Unable to obtain mex compiler info. rtiddsgen preprocessor is being disabled. To correct, run mex -setup
> In DDS.Utilities.getRtiPaths
In DDS.Utilities.convertIDLtoXML
In DDS.import
INFO com.rti.ndds.nddsgen.Main Running rtiddsgen version 2.5.0, please wait ...
INFO com.rti.ndds.nddsgen.Main Done
</pre><pre class="language-matlab">Error using DDS.Utilities.convertDDStoMathWorksType
DDSType: int32
</pre><pre class="language-matlab">Error in DDS.internal.readTypesXML.Member
</pre><pre class="language-matlab">Error in DDS.internal.readTypesXML.Struct
</pre><pre class="language-matlab">Error in DDS.internal.readTypesXML.readTypesXML/readType
</pre><pre class="language-matlab">Error in DDS.internal.readTypesXML.readTypesXML
</pre><pre class="language-matlab">Error in DDS.import
</pre>Humza Walihttps://cn.mathworks.com/matlabcentral/profile/authors/7869810-humza-walitag:cn.mathworks.com,2005:Question/3580492017-09-23T17:37:59Z2017-09-23T18:05:49ZHow do I do this switch statement?<p>How do I do this?</p><img src = "https://www.mathworks.com/matlabcentral/answers/uploaded_files/88812/image.png">Blair Hallhttps://cn.mathworks.com/matlabcentral/profile/authors/10774882-blair-halltag:cn.mathworks.com,2005:Question/3580502017-09-23T18:04:32Z2017-09-23T18:04:32Z"Function definitions are not permitted in this context." ? bisection<p>I am really new to MATLAB. I'm trying to write/test a bisection program that determines T as a function of C. I have initial guesses and will test some cases in the command window, but my code doesn't execute. I'm getting this error on the first line: "Function definitions are not permitted in this context." I'm not really sure if it's a file type error or a syntax error and how to fix it. Some help would be appreciated.</p><p>Thanks!</p><pre class="language-matlab">function [TofC] = TEval(osf)
</pre><pre> % temp absolute
U = 40+273.15;
L = 0+273.15;</pre><pre> % disp if no bracketing for a guess
if 0 < fTabs(L,osf)*fTabs(U,osf)
error('brackets')
end
end</pre><pre> r = L;</pre><pre> %iterate 1 to 10
for i=1:10
rInitial=r;
r = 0.5*(L+U);
% middle val
if r~=0, z = 100 * abs((r-rInitial)/r);
end
%check specifies test values from text
check=fTabs(r,osf)*fTabs(L,osf);
if check < 0
U = r;</pre><pre> elseif check > 0
r = L;</pre><pre> else
z = 0;
end
end</pre><pre> TofC = -273.15 + r; </pre><pre> function [k] = fTabs(Tabs,osf)
k = -139.3441 + ((1.5757e5)/Tabs) - ((6.64231e7)/Tabs^2);
k = k - ((8.62195e11)/Tabs^4) + ((1.2438e10)/Tabs^3);
k = k - log(osf);
end</pre>Amanda Padillahttps://cn.mathworks.com/matlabcentral/profile/authors/10721877-amanda-padillatag:cn.mathworks.com,2005:Question/3580302017-09-23T12:08:30Z2017-09-23T18:01:39Zhow to read grid data from text file ?<p>hi
I have a text file(attached). which contain ozone data. I am not able to read the data. since it is not in regular format. only latitude(-59.5S to 59.5N (1.00 degree steps)
) is given and on every latitude all ozone data is given so there are 288 longitudes(-179.375W to 179.375E (1.25 degree steps)) therefore 288 data points are there. but the problem is all data is in string format and we need to split data after every 3 digit. some random space is also given in the middle of the data so we have to remove that also otherwise data will not split in 3 correct digits .</p><p>later i will use inpolygon to grab out the data from specific region. that i will try later. but first i need to read this text file and took the data out.</p><p>hope you understand.</p>pruthhttps://cn.mathworks.com/matlabcentral/profile/authors/6973195-pruthtag:cn.mathworks.com,2005:Question/3580472017-09-23T17:04:10Z2017-09-23T17:57:41Zreshape a matrix from the text<p>I am trying to reshape a matrix from the text file to 45x50 , but when i do the reshape it shows that the number of the elements should not be changes. is there any problem with my coding?</p><pre> % fileid = fopen ('2016 Sept 7 - Vortex 1_0001')
x = textscan (fileid, '%n %n %n %n','headerlines',3,'delimiter',',')
cc = reshape (x, 44,45)</pre>yousef albahhttps://cn.mathworks.com/matlabcentral/profile/authors/10851784-yousef-albahtag:cn.mathworks.com,2005:Question/3579912017-09-22T22:58:07Z2017-09-23T17:28:33ZWhat is the best way to go about integrating a discrete and evenly spaced dataset?<p>I am calculating a gas diffusional profile in a solid sphere for which the first and second derivatives of the curve are both negative. This causes a systematic bias such that linear interpolation/trapz causes volume calculation errors to rise asymptotically under certain circumstances. I have been told that Romberg integration is a good antidote to the problem, however, it appears that a requirement of the Romberg method is to have a smooth, continuous function. Unfortunately, this curve can not be described by such a function.</p><p>I am wondering if someone more skilled than myself could help me come up with an interpolation scheme (piecewise?) that would give me the continuous function that could be fed into a Romberg script.</p><p>I have also tried using <a href = "https://www.mathworks.com/matlabcentral/fileexchange/28726-simpson-s-rule-integration?focused=5186784&tab=function">Simpson's rule integration</a>, but it seems my implementation is causing significant errors as well. I am probably doing something stupid wrong, but I have been staring at this stuff too long to really even tell. The approach here is to calculate and add the volume contributed by the concentration in each sphere between two spatial nodes, where v is the height of the concentration curve at radial position r, j is the index for spatial nodes and n is the number of spatial nodes:</p><pre> vol = simpsons([v(1) v(1)],0,r(1),[]) * (4/3 * pi * r(1)^3);
for j = 2:n
vol = vol + (4/3 * pi * r(j)^3 * simpsons(v(1:j),0,r(j),[]) - vol);
end</pre><p>I am probably making a stupid mistake here, and I'm not too familiar with interpolation schemes in MATLAB, so any advice or help on either front is greatly appreciated.</p><p>I have also attached an example of one of the curves I am trying to integrate over. v is on the y-axis and r (fractional) is on the x-axis.</p><img src = "/matlabcentral/answers/uploaded_files/88763/helpcurve.png">Adam Goldsmithhttps://cn.mathworks.com/matlabcentral/profile/authors/6114551-adam-goldsmithtag:cn.mathworks.com,2005:Question/3580232017-09-23T10:39:53Z2017-09-23T17:26:11ZFaster / more precise logarithm of complimentary error function?<p>If there is a way to calculate the logarithm of complimentary error function with better numerical precision (and preferably also faster) than doing it in the straightforward manner, e.g.</p><pre class="language-matlab">log(erfc(-5:5))
ans =
0.6931 0.6931 0.6931 0.6908 0.6112 0 -1.8496 -5.3649 -10.7204 -17.9878 -27.2009
</pre><p>As far as I know, many of numerical approximations involve product that includes exponential in some form <a href = "https://en.wikipedia.org/wiki/Error_function#Approximation_with_elementary_functions">e.g. see Wikipedia</a>, so it feels that some potential gain could be achieved through it.</p>Gleb Tikhonovhttps://cn.mathworks.com/matlabcentral/profile/authors/7808020-gleb-tikhonovtag:cn.mathworks.com,2005:Question/2551442015-11-16T16:24:33Z2017-09-23T17:16:37ZHow to generate a point cloud in 3D?<p>Hello dear community,</p><p>I would like to know if there is a fast way to create a cloud in 3D which consists of points. I would like to get something like this:</p><img src = "/matlabcentral/answers/uploaded_files/40299/image015.jpg"><p>The points should be written into a simple matrix. Each row should represent one point.
Thank you for your help!</p>Leo Müllerhttps://cn.mathworks.com/matlabcentral/profile/authors/7251449-leo-mullertag:cn.mathworks.com,2005:Question/3579982017-09-23T00:53:09Z2017-09-23T17:06:49Zif i have a matrix of x,y,u,v how can i use the gradient command<p>how to use the gradient</p>Ameed Azarhttps://cn.mathworks.com/matlabcentral/profile/authors/10846826-ameed-azartag:cn.mathworks.com,2005:Question/3580462017-09-23T16:41:02Z2017-09-23T17:05:25ZShould I indicate no input arguments to a function?<p>Suppose I have a function which requires no inputs. Should I indicate it with parentheses () or leave it naked? Both cases work, but is there a convention in the MATLAB community?</p><p>Example:</p><pre class="language-matlab">someFunction
% do sth
end
</pre><p>vs</p><pre class="language-matlab">someFunction()
% do sth
end
</pre>Zoltán Csátihttps://cn.mathworks.com/matlabcentral/profile/authors/2924415-zoltan-csatitag:cn.mathworks.com,2005:Question/832812013-07-26T19:57:22Z2017-09-23T17:04:48ZHow to change the color of a single point in a scatter plot?<p>I am plotting points:</p><p>x = [ 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5];</p><p>y = [ 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5];</p><p>plot(x,y,'*')</p><p>I would like to change the color of just an individual point, how do I go about it?</p>Irinahttps://cn.mathworks.com/matlabcentral/profile/authors/4406697-irinatag:cn.mathworks.com,2005:Question/3580432017-09-23T15:04:22Z2017-09-23T16:52:27ZResizing a 3D image without using imresize3<p>I do not have the image processing toolbox on my MatLab 2016b so I cannot use the imresize3() function. Is there other ways to resize an image of (x,y,z) to (a,b,c)?</p>Penemoniehttps://cn.mathworks.com/matlabcentral/profile/authors/7343218-penemonietag:cn.mathworks.com,2005:Question/3573002017-09-19T05:49:10Z2017-09-23T16:49:14ZWhat is problem?<img src = "/matlabcentral/answers/uploaded_files/88375/search1.PNG"><p>I want to apply this code on another image, but i am getting this problem, and the image can not be shown.</p><img src = "/matlabcentral/answers/uploaded_files/88376/mathlab.PNG"><p>Please any help</p>Haseeb Hassanhttps://cn.mathworks.com/matlabcentral/profile/authors/10023405-haseeb-hassantag:cn.mathworks.com,2005:Question/3580422017-09-23T14:55:04Z2017-09-23T16:40:52ZHow to randomly generate hierarchical graphs with specified levels <p>I wan't to create random hierarchical graphs using a matlab function.I should be able to specify the number of levels in the hierarchical graph.Is there an inbuilt function in matlab for this??
This is for the purpose of creating something analogous to a switched hierarchical architecture.</p>Deepal Tennakoonhttps://cn.mathworks.com/matlabcentral/profile/authors/11048424-deepal-tennakoontag:cn.mathworks.com,2005:Question/3580452017-09-23T16:08:18Z2017-09-23T16:08:18ZEqualizing Images for Background Subtraction<p>Hi;</p><p>I have a microscopic image of sperm and also the background of the image. I want to subtract them and then segment the sperms, but the two images are not equal in brightness and contrast, therefore some unwanted parts remain in the result. How can I equalize them? I used "histeq" and "adapthisteq" but the result was not good.</p><p>The images are attached.</p><p>Thank You :)</p><img src = "/matlabcentral/answers/uploaded_files/88810/matlab%20answers.jpg">Peyman Ghasemihttps://cn.mathworks.com/matlabcentral/profile/authors/4395296-peyman-ghasemitag:cn.mathworks.com,2005:Question/3580442017-09-23T15:08:05Z2017-09-23T16:03:19Zmatlab software free version ..... but why to pay it now ?<p>After opening matlab, I have found a message -"Matlab license will expire in 49 days. Please contact your system administrator or Mathworks to renew this license"... but I installed it's free version 3 years ago. then why I have to pay now to get it? Is this software does not run after 49 days or it shows any other meaning which I don't understand? please help me what I have to do to get it free .....</p>ARNAB CHATTARAJhttps://cn.mathworks.com/matlabcentral/profile/authors/6269440-arnab-chattarajtag:cn.mathworks.com,2005:Question/3574202017-09-19T18:15:33Z2017-09-23T14:56:48ZHow to convert a numeric string into a numeric range?<p>I am working with a GUI which allows users to select custom groups of numbers. The inputs are always stored as strings; however, I need to convert the string to a range of numbers.</p><p>For example, if the user inputs...</p><pre class="language-matlab">[1:3,5,7:9]
</pre><p>Then I would like to have a stored value of...</p><pre class="language-matlab">[1, 2, 3, 5, 7, 8, 9]
</pre><p>Is there a way to do this without using eval()?</p><pre class="language-matlab">eval('[1:3,5,7:9]')
</pre><p>I know the use of eval() is frowned upon, but I cannot think of a more efficient method. My only other idea has been to use regexp() which takes much more time because of all the conditional aspects of the search.</p><p><i>Note: I know this can be done in the Command Window, but I am attempting to only use GUI functions or other similar functions that create a pop-up, such as:</i></p><pre class="language-matlab">inputdlg()
</pre>Samuel Claryhttps://cn.mathworks.com/matlabcentral/profile/authors/3218295-samuel-clarytag:cn.mathworks.com,2005:Question/3578092017-09-21T21:35:44Z2017-09-23T14:56:38ZHow can i find number of pixel in irregular road from an image?<p>I have a binary image showing the irregular track and I have to find out the number of pixels to measure its width. Anyone have code to apply distance transform and skeleton for this problem? I have tried creating the bwdist and then skeleton and multiplying together Initially it cause error mtimes but after writing the equation as double(Dist) .* double(Skele); gives no error but results in Zero Matrix.</p>Harish Saklanihttps://cn.mathworks.com/matlabcentral/profile/authors/7774324-harish-saklanitag:cn.mathworks.com,2005:Question/3579962017-09-23T00:39:40Z2017-09-23T14:40:53ZWhy does legend('Position') overwrite strings?<p>When I try to reset the position of a legend with a legend('Position',...) command, the legend string changes to "Position". In contrast, legend('Location',...) works as I expect (but does not give the same level of control). Here is a minimal working example:</p><pre class="language-matlab">x=0:0.02:1;
y=x.^2;
z=x.^3;
f=figure;
hold on;
plot(x,y,'displayname','x^2');
plot(x,z,'displayname','x^3');
legend('show')
</pre><pre class="language-matlab">legend('Location','Best'); % This works as expected.
</pre><pre class="language-matlab">% But if I use the next line instead of setting Location,
% I just get the word 'Position' in the legend
% (and the legend seems to be located at 0,0).
% legend('Position',[0.5 0.5 0.2 0.2]);
</pre><p>It appears that a work-around is to use:</p><pre class="language-matlab">hl=legend('show');
legend(hl.String,'Position',[0.5 0.5 0.2 0.2]);
</pre><p>but I am curious why the simpler version fails. What am I doing wrong with legend('Position',...) ?</p><p>Thanks.</p>Jeff Millerhttps://cn.mathworks.com/matlabcentral/profile/authors/3203784-jeff-millertag:cn.mathworks.com,2005:Question/3579582017-09-22T17:12:52Z2017-09-23T14:34:11ZHow to add tolerance to my code ?<p>I have this code to flipud every other line along x-axis. The code works (only) when the increment on x-axis is an integer number(1,2,3...or 4 etc) as in data (a) attached, result shown in the first figure for 2 increment . but when the increment on x-axis is a fraction(1.123 or 1.234, ...or etc) as in data (b) attached, it only work for the first line as shown in the second Figure for 1.123 increment.</p><p>I think the reason is that I need to add a tolerance to the result of desired_line so Matlab can find it and add it to the desired_line_matrix. because of precision issue.</p><p>_ <b>But i don't know how to add the tolerance of search !!!!</b>_</p><p>Thank you so much</p><img src = "/matlabcentral/answers/uploaded_files/88740/a.PNG"><img src = "/matlabcentral/answers/uploaded_files/88741/B.PNG"><pre> %Find the desired lime:</pre><pre> desired_line_matrix=[];
TS=2;
s=a;
desired_line=[];
line_number=(max(s(:,1))-min(s(:,1)))/TS;
for j=0:TS:line_number*2
desired_line =s(1,1)+(j+min(s(:,1)));
desired_line_matrix=[desired_line_matrix,desired_line];
end</pre><pre class="language-matlab">%Flip the desired lime:
</pre><pre> for i=1:length(desired_line_matrix)
[r,c]=find(s(:,1)==desired_line_matrix(i));
d=r';
s(d,:)=flipud(a(d,:));
end
plot(s(:,1),s(:,2))
xlabel('X')
ylabel('Y')
hold on</pre>Faez Alkadihttps://cn.mathworks.com/matlabcentral/profile/authors/3644876-faez-alkaditag:cn.mathworks.com,2005:Question/3580402017-09-23T14:30:49Z2017-09-23T14:48:53ZCreating a 50x50 3D matrix composed of 2x1 vectors <p>I need to create a 50x50 image with each pixel composed of smaller 2x1 vectors using a 3D matrix. This then needs to be put into a nested for loop in order to have each value altered by a function, The 3D matrix will need to be altered back to 2D though before it can go into the function.</p><p>This is the code I have now but I know I am doing something wrong as I keep getting the error that my dimensions do not agree.</p><pre> y_image=zeros(50,50,14001); %creating empty vector for y image values
X_matrix=rand(50,50,2); %creating 50x50 3D image of X values between 0-1 </pre><pre> for row=1:50
for col=1:50
y_image(row,col,:)=R_final*X_matrix(row,col,:);
Y_squeeze=squeeze(y_image(row,col,:));
end
end</pre>C_J4995https://cn.mathworks.com/matlabcentral/profile/authors/10757043-c_j4995tag:cn.mathworks.com,2005:Question/3558552017-09-09T13:33:18Z2017-09-23T14:08:34ZHow to read text files from each subfolder<p>Hi,</p><p>I have a main folder which contains several sub folders, now I want to read text files from each subfolder, save the data into ".xlsx" of each subfolders data by its subfolder name. For example read data from subfolder1 and save the data as "subfolder1.xlsx", and subfolder2 data as "subfolder2.xlsx".</p><p>Read text files, and extract the data as mentioned below:</p><p>1. Above the first dotted (-----------) line, extract the information:
RainFallID, IINT, Rain Result, Start Time</p><p>2. Between two dotted lines(-------), the first column and 3rd column, in 3rd column if the data is mixed only keep the first part (for example 0.67 mm--> 0.67, 60.67+34e %-->60.67+34e, and if it is text like "False End"-->False End).</p><p>Please help some one kindly,</p>Mekala balajihttps://cn.mathworks.com/matlabcentral/profile/authors/5786945-mekala-balajitag:cn.mathworks.com,2005:Question/3580212017-09-23T10:29:51Z2017-09-23T13:54:17Z Matlab Gui. Retrieve the output of a function (external .m file) within a push button. Could anyone explain how to do it?<p>Hello I'm new about use the Matlab Gui. I'm struggling to retrieve the output of a function (external .m file) in a push button. Could anyone explain how to do it?</p><pre> %code</pre><pre> function Simulate_Callback(hObject, eventdata, handles)
% hObject handle to Simulate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global w DP
T=str2double(get(handles.inT,'string'));
P=str2double(get(handles.inP,'string'));
delta=str2double(get(handles.indelta,'string'));
Comp=str2double(get(handles.Comp,'data'));
Comp=Comp(:,1);
[w,DP]=external_Function(T,P,delta,Comp);</pre>Davide Dall'Acquahttps://cn.mathworks.com/matlabcentral/profile/authors/9041467-davide-dall-acquatag:cn.mathworks.com,2005:Question/3111562016-11-08T04:28:56Z2017-09-23T13:54:15Z R-CNN stop sign detector code<p>I am trying understand the code for stop sign detector using cnn but i do no identify the "Command" in below sentencie of the program:
"helperCIFAR10Data.download(url,cifar10Data);
I look for help but it shows an error msg</p>Euseb Martinezhttps://cn.mathworks.com/matlabcentral/profile/authors/8907615-euseb-martineztag:cn.mathworks.com,2005:Question/3580162017-09-23T09:18:37Z2017-09-23T13:50:26Z[Matlab] The product of three consecutive integers is 778596.Determine what these three integers are<p>The product of three consecutive integers is 778596.Determine what these three integers are.I have tried using for loop and while loop but i couldnt get the answer.Please help me.</p><p>Answer is 91,92,93</p>Ong Lee Wenhttps://cn.mathworks.com/matlabcentral/profile/authors/10639868-ong-lee-wentag:cn.mathworks.com,2005:Question/3580382017-09-23T13:49:01Z2017-09-23T13:49:01ZS-Function crashes due to serial port (Error Message: 'ext_serial_win32_comm': ExtTargetPktPending() call failed while checking for target pkt)<p>I created a S-function to read IMU raw data from BOOSTXL-SENSHUB & TM4C123GXL (Texas Instruments). While the function builds and runs, it crashes eventually with following error message:</p><p><b>Error occurred while executing External Mode MEX-file 'ext_serial_win32_comm':
ExtTargetPktPending() call failed while checking for target pkt</b></p><p>Currently I am trying to get 6 data -- three accelerometer and three gyroscope value with a sample time of 0.1. Instead of 6, if output is limited to 1 data, it runs a bit longer but eventually crashes with same error message.</p>Abdullah Rezahttps://cn.mathworks.com/matlabcentral/profile/authors/7690974-abdullah-rezatag:cn.mathworks.com,2005:Question/1516992014-08-20T18:26:43Z2017-09-23T13:45:20ZAm I computing cross entropy incorrectly?<p>I am working on a neural network and would like to use cross entropy as my error function. I noticed from <a href = "http://www.mathworks.com/matlabcentral/answers/104186-does-the-neural-network-toolbox-have-a-cross-entropy-error-function">a previous question</a> that MATLAB added this functionality starting with R2013b. I decided to test the <a href = "http://www.mathworks.com/help/nnet/ref/crossentropy.html">crossentropy</a> function by running the simple example provided in the documentation. The code is reprinted below for convenience:</p><pre class="language-matlab">[x,t] = iris_dataset;
net = patternnet(10);
net = train(net,x,t);
y = net(x);
perf = crossentropy(net,t,y)
</pre><p>When I run this code, I get perf = 0.0367. To verify this result, I ran the code:</p><pre class="language-matlab">ce = -mean(sum(t.*log(y)+(1-t).*log(1-y)))
</pre><p>which resulted in ce = 0.1100. Why are perf and ce unequal? Do I have an error in my calculation?</p>Matthew Eicholtzhttps://cn.mathworks.com/matlabcentral/profile/authors/3529521-matthew-eicholtztag:cn.mathworks.com,2005:Question/378272012-05-09T01:36:45Z2017-09-23T13:42:42ZGenerate 0 and 1<p>Hi,</p><p>How to generate 0 and 1 with equal probability?</p><p>I wanna generate sequence like 010101 or 011001 i.e probability of 0 and 1 should be 0.5.</p>Ronak Sakariahttps://cn.mathworks.com/matlabcentral/profile/authors/3477961-ronak-sakariatag:cn.mathworks.com,2005:Question/3580372017-09-23T13:32:54Z2017-09-23T13:32:54ZContourm lines overlay labels (using clabelm) <p>I use contourm in order to make a map and I want to have labels as well.
The label background color is set to none.
The lines are going through the labels and this is not looking nice. In some cases it is dificult to read the labels as well.</p><p>Does anybody know how to make a small gap in where the labels are placed?</p><p>This is a part of the code!</p><pre class="language-matlab">hold on
[c,h] =contourm(flipud(aody),flipud(aodx),flipud(rot90(aod)),5:5:60,'w','LineWidth',1);
t = clabelm(c,h);
set(t,'Fontsize',14)
</pre><pre class="language-matlab">set(t,'Color','w')
set(t,'BackgroundColor','none')
set(t,'FontWeight','bold')
</pre><img src = "/matlabcentral/answers/uploaded_files/88808/1Press.png">Platon Patlakashttps://cn.mathworks.com/matlabcentral/profile/authors/11046707-platon-patlakastag:cn.mathworks.com,2005:Question/555732012-12-03T21:27:16Z2017-09-23T13:22:58ZWhen using clabel to label contour lines, is there a way to manually adjust the gap in the contour line for the label?<p>The gaps in the contour lines over lap labeling after adjusting the format of the label to xe^x, font size to 16 and line width to 2.5. Is there a way to "update" the gap size after these adjustments have been made?</p><pre> h=figure(Number);
clf, grid on, hold on,
% disp('TP1'),
[C,H] = contour(X,Y,Z,V,'-k','Clipping','off','LineWidth',2.5);
set(gca,'FontSize',16),
% disp('TP2'),
text_handles=clabel(C,H,v,'LabelSpacing',500,'FontSize',16);
[j ~]=size(text_handles);
% disp('TP3'),
for i=1:j,
% i,disp('TP4'),
a=get(text_handles(i),'UserData');
y=char(num2str(a,'%5.0e'));
set(text_handles(i),'String', y);% ,'Interpreter','LaTex');
end</pre><p>I submitted a bug report on this and they forwarded to the enhancement team and confirmed that they were not able to find a work around for the issue.</p>Nathanhttps://cn.mathworks.com/matlabcentral/profile/authors/2531632-nathantag:cn.mathworks.com,2005:Question/3580362017-09-23T13:20:56Z2017-09-23T13:20:56ZHow to use correctly geoshow after worldmap?<p>I have set of dots with coordinates (lat and lon) I want to plot on a map. I have managed to use worldmap function for plotting the area I want. However, when I add after it geoshow, Matlab plots the dots on a blank background. How can it be fixed? it is part of an animation, that's why the hold functions.</p><pre class="language-matlab">lat_rng=[20 40];
lon_rng=[-80 -30];
ax = worldmap(lat_rng,lon_rng);
setm(ax, 'Origin', [0 180 0])
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow('landareas.shp', 'FaceColor', [0.5 0.7 0.5])
</pre><pre class="language-matlab">hold off
</pre><pre class="language-matlab">geoshow(latitude_N,longitude_E,'LineStyle','none')
hold on
title(sprintf('Lightning data on DATE:%g/%g/%g %g:00-%g:00 UTC. %g strokes selected.',start_time(3),start_time(2),start_time(1),i,i+1,length(latitude_N)))
xlabel('Longitude (E)')
ylabel('Latitude (N)')
hold off
</pre><pre class="language-matlab">drawnow
</pre>Aviad Shalomhttps://cn.mathworks.com/matlabcentral/profile/authors/9530212-aviad-shalomtag:cn.mathworks.com,2005:Question/1041612013-10-28T16:41:21Z2017-09-23T13:20:34ZWhen using contourf, is it possible to make a gap in contour lines so that the label is visible?<p>Hi,</p><p>My contour plots are largely illegible, as the contour labels insist on plotting over the middle of the lines! Is there a way to specify a break in the contour line for the label to fit into? Here's an example picture so you can tell what I mean;</p><img src = "/matlabcentral/answers/uploaded_files/3852/circstressoversigmaT_phi5_KI1.png"><p>and here's some example code;</p><pre class="language-matlab">clearvars
</pre><pre class="language-matlab">zeta=-90:10:90;
</pre><pre class="language-matlab">r_um=0:10:200;
xaxis=-90:10:90;
</pre><pre> angle_r_mat=rand(length(r_um),length(zeta));
ncont=3
prettycolours=ones(ncont,3);
prettycolours(ncont,:)=0.5;</pre><pre> [g,h]=contourf(zeta,r_um,angle_r_mat,ncont);set(gca,'FontSize',16)
set(h, 'linewidth', 1.5);
clabel(g,h,'fontsize',15)</pre><pre> set(gca,'Xtick',xaxis)
set(gca,'XtickLabel',xaxis)
colormap(prettycolours);</pre><pre> xlabel('\zeta(^o)','FontSize',16)
ylabel('r (\mu m)','FontSize',16)
title('partypartyparty')
grid on</pre><pre> xlim([-90, 90])
set(gca,'Layer','top')</pre><p>So I just want a gap in the contour line so that you can read the label. I've tried the help files and goggling, but haven't come up with anything. Anybody know how to do this?</p>Mikehttps://cn.mathworks.com/matlabcentral/profile/authors/3591135-miketag:cn.mathworks.com,2005:Question/3346462017-04-10T15:27:29Z2017-09-23T13:20:13ZPlease help me solve this error of derivative block not being finite at time = 0<p>Hi all, I am currently running a ball mill circuit using MATLAB however, I am given the following error when simulation is run:</p><pre class="language-matlab">An error occurred while running the simulation and the simulation was terminated
Caused by:
Derivative of state '1' in block 'Assign_CombinedMillandmix/Mix & Mill/Ball Mill/Oversize/Integrator3' at time 0.0 is not finite.
The simulation will be stopped. There may be a singularity in the solution.
If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances).
</pre><p>To try and solve personally, I changed the solver method to variable, testing ODE23tb, ODE23t & ODE15s;</p><p>however, this did not solve the problem.
Additionally attempted to change relative and absolute errors between the range 1e-4 to 1e-6.
I am running circuit for 5000s with a min step size of 0.4 and max step size of 0.7.</p><p>My initial integral conditions are 0, however, this was required.</p><p>Help would be much appreciated. Will send model should you require additional info. Please attach possible email address and how you would go about changing to make work.</p><p>Ciao.</p>The_Savage92https://cn.mathworks.com/matlabcentral/profile/authors/3435283-the_savage92tag:cn.mathworks.com,2005:Question/3580352017-09-23T13:18:39Z2017-09-23T13:18:39ZAlternatives to system identification<p>Salut,</p><p>I am currently attempting to model a plant using the sys iden. toolbox, however the models being formulated are very poor. It is monitoring temperature control using and on/off pump for a fermentation system.</p><p>If anybody has any useful books that would allow for the system to be modeled more accurately (i.e. by hand) or another program, please comment.</p><p>Maybe as an alternative, I am unsure as to whether changing the input from a pump on/off operation to something more tangible, maybe a heat transfer, however, still unsure how to perform that calculation with the system being 'uncertain'.</p><p>Help will be greatly appreciated.</p><p>Merci.</p>The_Savage92https://cn.mathworks.com/matlabcentral/profile/authors/3435283-the_savage92tag:cn.mathworks.com,2005:Question/3578912017-09-22T11:36:20Z2017-09-23T13:04:43ZCan I combine two markers together, and make them overlap?<p>I have a number of points represented by a circle marker. These markers overlap each other, but one is always layered "above it"\"in front of it" so that one circle is seen completely while the second is hidden behind it. Can it be possible to combine them, so that the overlap is constant between both markers?</p><p>Thank you in advance!</p>Marco Froelichhttps://cn.mathworks.com/matlabcentral/profile/authors/10550588-marco-froelichtag:cn.mathworks.com,2005:Question/3580342017-09-23T13:00:54Z2017-09-23T14:26:44Zreverberation rejection algorithm using auto regressive coefficients<p>Hi all</p><p>I am working on colored noise (reverberation) rejection algorithms. One approach present in literature is through prewhitening filter. In this approach as per my understanding, first we estimate reverberation spectrum through the data set in which no target is present i.e. we estimate ar coefficients (through auto regression) from this data set. In the next step, we use these ar coefficients in inverse filter to remove the reverberation from the next incoming data which can contain both reverberation as well as target.</p><p>I have done some MATLAB coding for this like:</p><p>a_=armcov(single_ping_data(1:10*pulse_samples),p);</p><p>here single_ping_data is the data set containing both reverberation and target. In the first ten" pulse_samples" chunks, there is only reverberation present so I estimate ar coefficients from this data set as a_.</p><p>In the next step, i formulate a combine signal as:</p><p>combine_signal=(single_ping_data(10*pulse_samples+1:10*pulse_samples+2*pulse_samples));</p><p>and finally i applied inverse filter on combine signal as:</p><p>y = filter(1,a_,combine_signal);</p><p>I repeated this process in a loop up to complete length of " single_ping_data".</p><p>The problem is that when i applied match filter on this filtered data, i could not get better results as compared to ones i got without applying this filter.</p><p>Can any one kindly help me in this regard?</p><p>Thanks</p>naumanhttps://cn.mathworks.com/matlabcentral/profile/authors/5528977-naumantag:cn.mathworks.com,2005:Question/3580332017-09-23T12:59:38Z2017-09-23T12:59:38ZWhat does this block stand for?<p>I am sorry for another possibly stupid question, but it is said that it is PI controller,</p><img src = "/matlabcentral/answers/uploaded_files/88806/8Kc_psHSYfk.jpg"><p>however in the simulink library I haven't found this one. What does this block stand for or in case it is custom block how can I design the same one?</p>Sabizhan Sumbekovhttps://cn.mathworks.com/matlabcentral/profile/authors/7988004-sabizhan-sumbekovtag:cn.mathworks.com,2005:Question/3580222017-09-23T10:32:50Z2017-09-23T12:58:36ZHow to remove artifacts from a signal<p>Hello,</p><p>I would like to remove artifacts from a signal, typically a lack of information in a thermocouple signal due to a shortcut.
In fact I don't want to calculate the moving average because it would alter the "good information" and extrapolate data that don't exist. But I want to detect wrong information (artifacts) based on this moving average, and replace it by NaN or 0.</p><img src = "/matlabcentral/answers/uploaded_files/88794/Capture.PNG"><p>I tried to code it, but it is not efficient at all (based on for loops), and I am sure I am not the first one to do this ;)</p><p>Thanks a lot for your help!</p><p>Max</p>maxroucoolhttps://cn.mathworks.com/matlabcentral/profile/authors/2077384-maxroucooltag:cn.mathworks.com,2005:Question/3580082017-09-23T06:32:18Z2017-09-23T12:58:34Zhow to connect signal builder outputs to the inputs through mscript.<p>Consider a 2 input AND gate and i am creating 2 signals in signal builder for these 2 inputs and instead of connecting manually i need to connect through mscript to the corresponding signal names.</p>mettupalli Sriharshahttps://cn.mathworks.com/matlabcentral/profile/authors/5374356-mettupalli-sriharshatag:cn.mathworks.com,2005:Question/3580262017-09-23T11:20:19Z2017-09-23T12:53:10ZLatex in plot title with variables<p>Hi, I'm running Matlab R2014b. Trying to make a nice plot with :</p><pre> title([' Slip regulation \lambda for K_{\sigma} = ',num2str(Ksigma),' K = ', num2str(K),' and \epsilon = ', num2str(theta)]); </pre><p>Tried even with</p><pre> title([' Slip regulation \lambda for K_{\sigma} = ',num2str(Ksigma),' K = ', num2str(K),' and \epsilon = ', num2str(theta), 'Interpreter','tex' ]); </pre><p>Still no luck. Would someone help me out ?
Thanks in advanced.</p>Maahttps://cn.mathworks.com/matlabcentral/profile/authors/2004384-maatag:cn.mathworks.com,2005:Question/3580322017-09-23T12:16:05Z2017-09-23T12:51:55ZHow to apply Median FIlter To a color image with out using 'rgb2gray' ? Program please.<p>How to add noise and eliminate it using filters (in this case salt and pepper and Median filters respectively) by using without the conversion to gray scale.?</p>SARATH JVhttps://cn.mathworks.com/matlabcentral/profile/authors/11046579-sarath-jvtag:cn.mathworks.com,2005:Question/3580272017-09-23T11:23:32Z2017-09-23T12:32:15ZAdding Arrays of cells<p>I have ten arrays of 15-dimensional A1, ..., A10 which consist of cells of different size. All arrays have same format i.e., same dimension of cells for all Ai, i=1,..10 respectively.</p><p>Ai = [2x1 double]
[1x2 double]
[2x2 double]
[2x1 double]
[2x2 double]
[2x2 double]
[2x2x2 double]
[2x1 double]
[2x2 double]
[2x2 double]
[2x2x2 double]
[2x2 double]
[2x2x2 double]
[2x2x2 double]
[4-D double]</p><p>I want A in same format where A is an array which have the mean of all components of cells of Ai, i =1,...,10. That is,
A = (A1+ ... +A10)/10.</p><p>Please help me. Thanks
:MSA</p>Sultanhttps://cn.mathworks.com/matlabcentral/profile/authors/5658850-sultantag:cn.mathworks.com,2005:Question/3580252017-09-23T11:11:49Z2017-09-23T12:32:00ZWhat kind of noise it is?<p>Hello everyone. I tried to get to know what type of noise I have in my data: if it's a white noise or clored. I used fft in orded to get a graph, but still I can't see clearly the type. I know the difference between the white and colored noises, but in the other examples the graphs seems to be beter. I use this code:</p><pre class="language-matlab">load data1.csv;
Fs=1000;
data1=data1-mean(data1);
Y = fft(data1);
L=numel(data1);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
</pre><p>And I get a graph:</p><img src = "/matlabcentral/answers/uploaded_files/88800/untitled.jpg"><p>Is it possible to say that it's colored noise or am I missing something?</p>Martynas Tirlikashttps://cn.mathworks.com/matlabcentral/profile/authors/10972291-martynas-tirlikastag:cn.mathworks.com,2005:Question/3580312017-09-23T12:15:18Z2017-09-23T12:27:13Zputting some matrix in a cell arrays<p>I have 3 matrices:</p><pre class="language-matlab">m1[5x4];
m2[5x4];
m3[5x3];
</pre><p>I want to put them in a cell W{i}</p><pre class="language-matlab">for i=1:3
</pre><p>in a way W{1}=m1; W{2}=m2 and W{3}=m3</p><p>How could I do it?
Thx</p>Ameni JOUILAhttps://cn.mathworks.com/matlabcentral/profile/authors/8092985-ameni-jouilatag:cn.mathworks.com,2005:Question/3572262017-09-18T18:06:55Z2017-09-23T12:12:42Zhow to read nc file ?<p>hi
i have nc file which contain world ocean salinity data at various depth.
i can collect lat(180) lon(360) data since it is vectors.
but salinity data is in 3d format with depth. i.e. 360*180*102 double, means data 360*180 points at one level and there are 102 levels.
i am not able see that file because it is crossing the display limit. i want to collect salinity data at only one level. so i can plot it in 2D. i wish i could get the data at specific level.</p><p>i have downloaded the file from :</p><p><a href = "https://data.nodc.noaa.gov/thredds/catalog/woa/WOA13/DATAv2/salinity/netcdf/A5B2/0.25/catalog.html?dataset=woa/WOA13/DATAv2/salinity/netcdf/A5B2/0.25/woa13_A5B2_s01_04v2.nc">https://data.nodc.noaa.gov/thredds/catalog/woa/WOA13/DATAv2/salinity/netcdf/A5B2/0.25/catalog.html?dataset=woa/WOA13/DATAv2/salinity/netcdf/A5B2/0.25/woa13_A5B2_s01_04v2.nc</a></p>pruthhttps://cn.mathworks.com/matlabcentral/profile/authors/6973195-pruthtag:cn.mathworks.com,2005:Question/331042012-03-22T13:31:44Z2017-09-23T12:12:17ZNeed code for Median Filtering on Color images<p>Need Code for Median Filtering on Color images</p><p>Cheers</p><p>Jagadeesh</p>Jagadeesh phttps://cn.mathworks.com/matlabcentral/profile/authors/3322145-jagadeesh-ptag:cn.mathworks.com,2005:Question/3580292017-09-23T12:06:58Z2017-09-23T12:06:58Zrotate a 3D plot and keep it the same size<p>I'm creating a GIF from a series of 3D plots, each one rotated from the previous by changing the viewpoint. Here is a snippet that does the frame generation:</p><pre class="language-matlab">for az=0:5:355
view([az,el]);
drawnow;
frame = getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename,'WriteMode','append','DelayTime',dt);
end
</pre><p>The problem I'm having is that each frame is magnified to fill the figure window, causing the plot to change size as it rotates. <a href = "https://drive.google.com/open?id=0B3t_p2l1mv5LXzhPbnFJT2VDWHM">Here</a> is a link to the GIF.</p><p>What view settings must I change to keep the 3D surface the same apparent size as I rotate it?</p>Scotthttps://cn.mathworks.com/matlabcentral/profile/authors/2670814-scotttag:cn.mathworks.com,2005:Question/3580282017-09-23T11:35:56Z2017-09-23T11:55:43ZHow to plot this function ?<p>Hello all, I'm quite new to matlab , so I want to figure out how to plot that heaviside function ?</p><img src = "/matlabcentral/answers/uploaded_files/88801/f.PNG"><p>I want to get that graphic below the function.</p>Tomas Tyvhttps://cn.mathworks.com/matlabcentral/profile/authors/11046426-tomas-tyvtag:cn.mathworks.com,2005:Question/3579802017-09-22T20:27:57Z2017-09-23T11:49:53ZAny guidance how to solve this, really need this and will be grateful for any help.<pre class="language-matlab">clc
clear all
syms y
a = 0:0.5:10;
U = 1;
x= 0;
sym y
for m = 0:1:10
j = 1;
eqn = U*y -(m/(2*pi)*atan((2*a*y)/(x.^2 + y.^2 - a.^2)))== 0;
soly = solve(eqn,y);
Y(j,1) = double(soly);
j = j + 1;
end
</pre><p>I need to get values for y or solve the eqn for y</p>Shifohttps://cn.mathworks.com/matlabcentral/profile/authors/10835987-shifotag:cn.mathworks.com,2005:Question/3580122017-09-23T08:06:05Z2017-09-23T11:48:51Zwhile loop with user defined function won't cycle through all conditions of the function.<p>I am utilising a while loop to determine the height of water in a dam and the discharge rate that is dependant on that height. The function that determines the discharge rate has a condition of if the water height is less than 20% then the discharge is 0. The issue is that when the height goes above this threshold the discharge rate determined by the function doesn't reflect that and will populate the rest of the array with 0's.</p><p>User defined function</p><pre class="language-matlab">function [Q] = O_R_A(H)
%Operating rule A for varying dam heights
% Determining the usage rates for the dam for different dam heights
H_max = 30.9; %dam height in m (scaled 1:300)
Q_out = 11923.2; %normal output rate
Q = 0;
if H >= 1*H_max;
Q = NaN();
elseif H >= 0.9*H_max;
Q = 1.5 * Q_out;
elseif H < 0.9*H_max & H >= 0.2*H_max;
Q = Q_out;
else H < 0.2*H_max;
Q = 0;
end
end
</pre><p>and the while loop that utilises the function is</p><pre class="language-matlab">m = 1;
H_A = 16.2; %initial water height
while m < length(Q_in)
m = m+1;
Q_A(m) = O_R_A(H_A);
delta_a(m) = (((Q_in(m-1) - Q_A(m))/f)*30.9); %change in water level
H_A(m) = H_A(m-1) + delta_a(m); %new water level
end
</pre><p>when the water level rises back above the 20% threshold I would like for the discharge rates to be calculated as per the conditions in the function.</p>Rhys Webbhttps://cn.mathworks.com/matlabcentral/profile/authors/11006704-rhys-webb