https://ch.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-07-19T19:24:44Ztag:ch.mathworks.com,2005:Question/4111282018-07-19T12:36:43Z2018-07-19T19:24:44Zremove duplicate rows from text file<p>I'd be glad to have some advise on the fastest way to read a text file which contains duplicate rows, remove all the duplicates and write it back.</p><p>Matlab version R14 SP3</p>michaelhttps://ch.mathworks.com/matlabcentral/profile/authors/313829-michaeltag:ch.mathworks.com,2005:Question/4111802018-07-19T16:55:55Z2018-07-19T19:24:25ZChart regions of pixels onto new image<p>I would like to take box or circle portions of an image and create a new image based on them. These regions would be in the same place spatially and any other area not covered by a circle or box would be black (ie pixelValue = [0,0,0]).</p><p>Is there any tool or function that can do that on Matlab? I had limited success with imcrop (the pixels weren't preserved spatially), and when I predefined the new image as image = zeros(256,256) the pixels were transcribed correctly spatially but they weren't the correct values (The image integrity wasn't preserved, ie the pixel values weren't correctly transcribed).</p><p>The boxes selected would be the regions that aren't white in this example image:</p><img src = "/matlabcentral/answers/uploaded_files/125802/image13.png"><p>This is the end image</p><img src = "/matlabcentral/answers/uploaded_files/125803/image13.png"><p>This was the starting image:</p><p>Of course, these aren't squares like the ones I'm going for (I wouldn't change their sizes, and they would be squares/circles not rectangles) but I drew this up with paint to try to illustrate what I'm trying to do.</p>Ariel Avshalumovhttps://ch.mathworks.com/matlabcentral/profile/authors/11798489-ariel-avshalumovtag:ch.mathworks.com,2005:Question/4112082018-07-19T19:24:16Z2018-07-19T19:24:16ZBreaker/switch does not open once closed<p>I have tried both the breaker and the ideal switch for a DC circuit. In their examples, if I change the switching and simulation times to be longer, the breaker and switch don't open and close like they should. They tend to get stuck in the closed state. Are these blocks not built to be simulated for more than 0.2s? And does anyone know how to solve this?</p>Ishita Rayhttps://ch.mathworks.com/matlabcentral/profile/authors/7248066-ishita-raytag:ch.mathworks.com,2005:Question/4066572018-06-20T20:41:07Z2018-07-19T19:23:23ZSolving a System of ODEs<p>My Input:</p><pre class="language-matlab">syms x(t) y(t) z(t)
%Units of kg and seconds
q = 1.60217662*(10^-19);
B = 2;
m_e = 1.60217662*(10*-31);
a = (q*B)/m_e;
</pre><pre class="language-matlab">%DiffiQ to solve
ode1 = diff(x,2) == a*diff(y);
ode2 = diff(y,2) == -a*diff(x);
ode3 = diff(z,2) == 0;
odes = [ode1; ode2; ode3];
</pre><pre class="language-matlab">%Solutions
S = dsolve(odes);
xSol(t) = S.x;
ySol(t) = S.y;
zSol(t) = S.z;
</pre><pre class="language-matlab">[xSol(t), ySol(t), zSol(t)] = dsolve(odes);
</pre><pre class="language-matlab">%Initial Conditions
condx1 = x(0) == 1;
condy1 = y(0) == 1;
condz1 = z(0) == 0;
</pre><pre class="language-matlab">%{
condvx1 = diff(x) == 1;
condvy1 = diff(y) == 2;
condvz1 = diff(z) == 2;
%}
</pre><pre class="language-matlab">%Plot Trajectory
</pre><pre class="language-matlab">t = 0:pi/50:8*pi;
plot3(ode1,ode2,ode3,'r','LineWidth',3)
</pre><p>My Output: Nothing. The program runs but nothing happens. I have to force close MatLab so that the script stops. I left it running for an hour to see but I am starting to think that there is another issue. Any advice is appreciated!</p><p>PS - Using Matlab R2018a and yes I purposefully commented out a section of initial conditions.</p>Tom Keatonhttps://ch.mathworks.com/matlabcentral/profile/authors/7591080-tom-keatontag:ch.mathworks.com,2005:Question/4112072018-07-19T19:21:23Z2018-07-19T19:21:23ZHybrid Optimizer: GA and PSO<p>Is there code available that utilizes the algorithm that is highlighted within this paper (pg.116)? https://link.springer.com/content/pdf/10.1007%2Fs40825-018-0085-7.pdf</p>Cpanhttps://ch.mathworks.com/matlabcentral/profile/authors/11080199-cpantag:ch.mathworks.com,2005:Question/4111922018-07-19T18:14:33Z2018-07-19T19:19:10ZMultibandread error: The file is too small to contain the specified data. <p>Hello everyone,</p><p>I am following this tutorial: <a href = "https://www.mathworks.com/videos/image-processing-made-easy-81718.html?s_cid=learn_vid">Image Processing Made Easy</a> however, I've got a problem right at the beginning.
In the video, the author uses:</p><pre> truecolor= multibandread('paris.lan', [512, 512, 7], 'uint8=>uint8',...
128, 'bil', 'ieee-le', {'Band','Direct',[3 2 1]});
imshow(truecolor)
xlabel('Image courtesy of Space Imaging, LLC')</pre><p>I found the same thing here: <a href = "https://blogs.mathworks.com/steve/2009/02/06/consider-multibandread-for-reading-your-data/">https://blogs.mathworks.com/steve/2009/02/06/consider-multibandread-for-reading-your-data/</a></p><p>First of all, I find it very annoying that in the tutorial page the materials (script and images) used for the lesson are not provided. I have tried downloading the picture from the link that I provided above.
I uploaded the picture with:</p><pre class="language-matlab">I = imread('desk2.jpg');
</pre><p>This works and the variable that I get is Value: 332x329x3 uint8. Class, again, uint8</p><p>I ran the script with truecolor (see above) and it gives me this error:</p><pre class="language-matlab">Error using multibandread (line 118)
The file is too small to contain the specified data. Check the size, offset, and precision arguments
</pre><p>I saw that someone had my same problem: <a href = "https://www.mathworks.com/matlabcentral/answers/46547-i-have-a-jpg-image-i-want-to-find-vegetative-area-and-count-trees-in-that-image-im-able-to-count-tre">https://www.mathworks.com/matlabcentral/answers/46547-i-have-a-jpg-image-i-want-to-find-vegetative-area-and-count-trees-in-that-image-im-able-to-count-tre</a></p><p>As suggested in that link I tried:</p><pre class="language-matlab">figure
truecolor = multibandread('desk2.jpg', [332, 329, 3], 'uint8=>uint8',...
128, 'bil', 'ieee-le', {'Band','Direct',[1 1 3]});
</pre><p>It gives me the same error. By the way, I read the doc page for multibandread. However, I find it quite annoying that the function is not really explained in the video. Anyways...</p><p>I also tried to invert the values, as suggested in that link. This way:</p><p>[329, 332, 3]</p><p>Still the same error. Does anybody know what to do? Also, can I use "multibandread" on any image? Or does the image need to be of a particular type?</p><p>Thank you for your time.</p>Gianluca Finottihttps://ch.mathworks.com/matlabcentral/profile/authors/12131790-gianluca-finottitag:ch.mathworks.com,2005:Question/4111962018-07-19T18:28:47Z2018-07-19T19:16:39ZCurve fitting of data points<p>I have a series of repeated data points that i am trying to fit with a skewed curve.
In the graph I am showing one set of the data points which are in blue. The black hand drawn
line is the kind of fit i want for my data. I want my fit to be a curve like the one drawn,
not a combination of two linear functions or a sawtooth. I have included the data points in text files.
Thank you.</p><img src = "/matlabcentral/answers/uploaded_files/125817/test1.jpg">Angelahttps://ch.mathworks.com/matlabcentral/profile/authors/5624596-angelatag:ch.mathworks.com,2005:Question/4111852018-07-19T17:13:10Z2018-07-19T19:14:57ZModifying the Tolerance (TolX) inside the Matlab function file (fzero.m).<p>I wrote the code as:</p><pre class="language-matlab">f = @(x) sin(x);
a = -0.01;
b = 0.05;
x = [a b];
options = optimset;
optnew = optimset(options,'TolX',1e-12);
[b,fval,exitflag,output]=fzero(f,x,options);
</pre><p>But, the program keeps using the default TolX !!
How can I modify the default Tolerance (TolX) to 1e-12 or to any other value?</p>Ahmad Alalyanihttps://ch.mathworks.com/matlabcentral/profile/authors/5131690-ahmad-alalyanitag:ch.mathworks.com,2005:Question/4112062018-07-19T19:13:38Z2018-07-19T19:13:38ZWhat time constant stands for in generic engine block ? <p>Hello there, I am trying to tune the generic engine block and I want to know what the engine time constant stands for. Does it represent the time delay that occurs during ignition or the time delay between the throttle variation and the output torque build up? Or it has to do with the engine dynamics (inertia)?</p>Andreas Christodoulouhttps://ch.mathworks.com/matlabcentral/profile/authors/11339197-andreas-christodouloutag:ch.mathworks.com,2005:Question/4111552018-07-19T14:37:44Z2018-07-19T19:12:51ZAdding functions in a for loop<p>I am trying to add a function in a for loop but I keep getting an error (Undefined function 'plus' for input arguments of type 'function_handle'). I would like to keep summing y(x) and plot the final result. Below is my script. Thanks ahead of time!</p><p>syms x</p><p>y = @(x) 1</p><p>for c = 1:5;</p><p>y = y(x) + @(x) 3*c.*((0 <= x) & (x <= 5))</p><p>x = linspace(0.2, 4, 500);</p><p>end</p><p>plot(x,y(x)</p>Jeffhttps://ch.mathworks.com/matlabcentral/profile/authors/13174713-jefftag:ch.mathworks.com,2005:Question/541642012-11-19T18:43:43Z2018-07-19T19:12:18ZHow can I plot an intersection volume?<p>Hey,</p><p>I am trying to plot a sphere V that is intersecting with a cylinder Z.</p><p>Z = (x;y;z) x^2+y^2=1 ; 0<z<5</p><p>V = (x;y;z) x^2+y^2+z^2=4</p><p>I just want to plot the volume of intersection.</p><p>How do I do that?</p><p>Thanks for your help</p>Johanneshttps://ch.mathworks.com/matlabcentral/profile/authors/3820097-johannestag:ch.mathworks.com,2005:Question/4112052018-07-19T19:11:10Z2018-07-19T19:11:10Zhow to resolve the error "matlab function block doesn't support matrix types on its input port for HDL code conversion (intention is to find inverse of matrix)<img src = "/matlabcentral/answers/uploaded_files/125819/IMG-20180719-WA0043.jpg"><p><a href = "</matlabcentral/answers/uploaded_files/125822/_20180720_002847.jpg"></matlabcentral/answers/uploaded_files/125822/_20180720_002847.jpg</a>>
I have attached the simulink model as well as the diagnostic viewer. When I run model in simulink it will run and give the answer. but while hdl code generation it gives error like this. My matlab code , .m file has array as input . is it
because of that? Can someone help me to fix the error?</p>Shrilakshmi bhathttps://ch.mathworks.com/matlabcentral/profile/authors/13117647-shrilakshmi-bhattag:ch.mathworks.com,2005:Question/4112042018-07-19T19:09:08Z2018-07-19T19:09:08ZAdding a singleton dimension to a 2D vector<p>I have a 22872x1 vector that needs to be a three dimensional matrix. Is there any way to add an additional singleton dimension to my vector in order to do such, i.e. go from 22872x1 to 22872x1x1? I need this vector to be three dimensional in order to run its values through a function, as the function requires a 3 dimensional matrix input.</p>Sarah Hutchinsonhttps://ch.mathworks.com/matlabcentral/profile/authors/8420547-sarah-hutchinsontag:ch.mathworks.com,2005:Question/4101172018-07-12T19:23:13Z2018-07-19T19:08:34ZHow can I remove quotes from a table?<p>Hi,</p><p>I have a large csv file which I import to MATLAB by an user-prompt and store the information in a table. After storing the information in the table, I see that each value in the table gets appended inside a single quotation mark. How to remove this quotation mark from each element or more specifically, how can I avoid storing the information from the csv file without appending a quotation mark with every element? Screenshot & code attached.</p><pre class="language-matlab">BaseDir = 'C:\Users\mhaque7\Documents\MATLAB'; % Set as you need
[FileName, FilePath] = uigetfile('*.csv', ...
'Please choose an Excel file', BaseDir);
if isequal(FileName, 0)
disp('User aborted file choosing.');
return; % Assuming this is a function
end
File = fullfile(FilePath, FileName);
data_src=readtable(File) %importing data from the csv file into a table
</pre>Mohammad Haquehttps://ch.mathworks.com/matlabcentral/profile/authors/13145584-mohammad-haquetag:ch.mathworks.com,2005:Question/4112032018-07-19T18:59:37Z2018-07-19T19:07:57ZFind number of terms in taylor expansion upto when error is 10^(-6)<p>Find number of terms in taylor expansion upto when error is 10^(-6)</p>khadija razahttps://ch.mathworks.com/matlabcentral/profile/authors/13175716-khadija-razatag:ch.mathworks.com,2005:Question/4111952018-07-19T18:27:04Z2018-07-19T19:05:37ZImplement ode15s function in a discrete model<p><b>How to implement the ode15s function in a discretized model?</b></p><p>In the continuous model it was quieter, as I found several examples. Now in the discretized model I can not find anything to help me. I emphasize that I am learning to program, so all help and the way that is explained to a lay person will be appreciated.</p><p>I can implement and compile by placing the template and specifying the step size. But I would like to apply this numerical solution to the model, just as it was done in the continuum. Any idea how to comoralize this process?</p><p>It follows two codes of the discretized model, both get the same results, except that the code_discret_1 is in state space format and the other is in systems format.</p>Fernanda Paula Rochahttps://ch.mathworks.com/matlabcentral/profile/authors/12365119-fernanda-paula-rochatag:ch.mathworks.com,2005:Question/4110252018-07-18T20:40:18Z2018-07-19T19:03:12ZHow to set cell color using a for loop for a range of cells with MATLAB?<p>WB.Worksheets.Item(1).Range('A1:N1').Interior.ColorIndex = 3;</p><p>Tried this. But, the problem with this is that I cannot use this line in a for loop.
Gives me an error that says -
Error using Interface.000208D8_0000_0000_C000_000000000046/Range
Error: Object returned error code: 0x800A03EC</p><p>Error in lenderinfotestdatascript (line 76)
WB.Worksheets.Item(1).Range('Ci').Interior.ColorIndex = 3;</p>Ankush Bhandehttps://ch.mathworks.com/matlabcentral/profile/authors/12877366-ankush-bhandetag:ch.mathworks.com,2005:Question/4112022018-07-19T18:57:29Z2018-07-19T18:59:23ZHow can I verify that this Optical flow is working properly?<p>Hello,</p><p>I am working on an optical flow problem, and the values aren't coming as expected. I have a video which has each frame written as .jpg images. Two frames that are close to each other (ie. frames 2 and 3) show the optical flow in the correct direction. However, when I use a larger difference (ie. frame 2 to 30), the optical flow arrows point left instead of right, which is the direction that the object moves in my video. Can someone please help me figure out what I am doing wrong? I have attached my code in this, so I hope you can help. Any help is appreciated!</p><p>Thanks</p><pre class="language-matlab">sc = 2;
im1c = imresize(im1, 1/sc);
C1 = detectHarrisFeatures(im1c);
C1 = C1.Location
C1 = C1*sc;
</pre><pre class="language-matlab">% Discard corners near the margin of the image
k = 1;
for i = 1:size(C1,1)
x_i = C1(i, 1);
y_i = C1(i, 2);
if x_i-w>=1 && y_i-w>=1 && x_i+w<=size(im1,1)-1 && y_i+w<=size(im1,2)-1
C(k,:) = C1(i,:); % creates coordinates for each corner
k = k+1;
end
end
</pre><pre class="language-matlab">% Plot corners on the image
figure();
imshow(fr1);
hold on
plot(C1(:,1), C1(:,2), 'r*');
hold off
x = length(C1(:,2));
</pre><pre class="language-matlab">%Conv2 = convolutions used to differentiate the image wrt to each dimension
Ix_m = conv2(im1,[-1 1; -1 1], 'valid'); % partial on x [-1 1; -1 1]
Iy_m = conv2(im1, [-1 -1; 1 1], 'valid'); % partial on y [-1 -1; 1 1]
It_m = conv2(im1, ones( 2), 'valid') + conv2(im2, -ones(2), 'valid'); % partial on t
u = zeros(length(C1),1);
v = zeros(length(C1),1);
</pre><pre class="language-matlab">% within window ww * ww
% Least squares solutions
for k = 1:length(C(:,2)) % Calculates optical flow from each corner
i = C(k,2);
j = C(k,1);
Ix = Ix_m(i-w:i+w, j-w:j+w);
Iy = Iy_m(i-w:i+w, j-w:j+w);
It = It_m(i-w:i+w, j-w:j+w);
</pre><pre> Ix = Ix(:);
Iy = Iy(:);
b = -It(:); % get b here</pre><pre> A = [Ix Iy]; % get A here
nu = pinv(A)*b; %Perform pseudo-inverse in order to calculate velocity profile</pre><pre> u(k)=nu(1);
v(k)=nu(2);
end</pre><pre class="language-matlab">figure();
imshow(fr1);
hold on;
quiver(C(:,1), C(:,2), u,v, 1,'r')
</pre>jasendevahttps://ch.mathworks.com/matlabcentral/profile/authors/13175688-jasendevatag:ch.mathworks.com,2005:Question/4112012018-07-19T18:49:31Z2018-07-19T18:58:54ZHow to get a pointer to 2D array when writing a C source Mex file?<p>Hi,
I'm trying to write a highly simple C source .mex file (function) that takes a 1 x n vector and n x n matrix, and yields their matrix product, again a 1 x n vector (all the arrays are of binary and I'm doing computations for binary case). My concern is how to get a pointer to 2D array,(e.g the line <b>arr = mxGetDoubles(prhs[1]);</b>) I tried mxGetDoubles as it works for 1xn arrays, but I came across with the warning <i>": assignment from incompatible pointer type [-Wincompatible-pointer-types]"</i>. I then tried mxGetData; it did not give any warnings yet when I called the function from the command window, MATLAB crashed and was forced to close.</p><p>I would be highly appreciated if anyone can help me out. Thanks and here is the whole .c code:</p><pre class="language-matlab">/*==========================================================
* arrayMultiplier.c
*
* Multiplies a 1xN matrix with a N X N matrix
* and outputs a 1xN matrix
*
* The calling syntax is:
* outMatrix = arrayProduct(vector, array)
*========================================================*/
</pre><pre> #include "mex.h"</pre><pre> /* The computational routine */
void arrayMultiplier( double *vec, double **arr, mwSize n ,double *z){
for (mwSize i=0; i<n; i++) {
for(mwSize j=0; j<n; j++) {
z[i] += vec[j]*arr[j][i];
}
z[i] = (double)((int)z[i] % 2);
}
}</pre><pre> /* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) {
double *vec;
double **arr;
mwSize nr;
double *outMatrix; </pre><pre> nr = mxGetN(prhs[0]); /*The "n" parameter of the 1 x n output matrix*/</pre><pre> vec = mxGetDoubles(prhs[0]);</pre><pre> arr = mxGetData(prhs[1]); /* This is where the warning appears */</pre><pre> /* creating the output matrix */
plhs[0] = mxCreateDoubleMatrix(1,nr,mxREAL);</pre><pre> /* get a pointer to the real data in the output matrix */
outMatrix = mxGetDoubles(plhs[0]);</pre><pre> /* call the computational routine */
arrayMultiplier(vec,arr,nr,outMatrix);
}</pre>Mustafa Aydinhttps://ch.mathworks.com/matlabcentral/profile/authors/10384761-mustafa-aydintag:ch.mathworks.com,2005:Question/4111742018-07-19T16:09:10Z2018-07-19T18:55:32Zhow can I use a*exp(bx)+ cx+d to fit the curve instead of two term exponential <p>Hi there I'm trying to fit the data with one term exponential and second term linear instead of using two term exponential. Although the curve fitting tool does allow me to do this, just not convinced that this is possible without transforming the data. Please can anyone help to clarify this query?</p>Emsal Llapashticahttps://ch.mathworks.com/matlabcentral/profile/authors/6623186-emsal-llapashticatag:ch.mathworks.com,2005:Question/4103002018-07-13T20:01:18Z2018-07-19T18:49:11ZHello! I need help with a problem. I want to do FFT of a complex number like 0.00030519-9.1558e-05i . Can anyone please guide me to the right direction of doing so?<p>IQ representation of signal
0.00030519-9.1558e-05i
I want to tranform this with FFT.</p>Faisal Kabirhttps://ch.mathworks.com/matlabcentral/profile/authors/13150087-faisal-kabirtag:ch.mathworks.com,2005:Question/4111972018-07-19T18:29:45Z2018-07-19T18:48:50ZGUIDE: how to share variables of a local function on its .m file to another callback button?<p>Hello fellows. This questions is about using GUIDE.</p><p>Here's the problem: I have a function @callbackslider nested with another function (showDicom), which the input is a DICOM file to see along the slices. The function showDicom is called in a callback button.</p><p>These functions are in the showDicom.m file.</p><p>I'd like to use the slice number (from @callbackslider) information to use in another function (also with its own .m file) which is called within another callback button.</p><p>showDicom.m</p><pre class="language-matlab">function showDicom(x, handles)
acquisition = squeeze(x);
[row, col, z] = size(acquisition);
figure (1)
imagesc(acquisition(:,:,1));
colormap jet;
title('Transverse');
sld = uicontrol('Style', 'Slider', 'SliderStep', [1/94 1], 'Value',1,...
'Min', 1, 'Max', 95, 'Callback', @callbackslider01);
</pre><pre> function callbackslider01(hObject, eventdata)
val = hObject.Value;
figure (1);
imagesc(acquisition(:,:,val));
title(num2str(val));
colormap jet;</pre><pre> end
end</pre><p>Now, as I said, I want to use the <b>val</b> variable in another callback button, which calls the function Uniformity.m:</p><pre> function test_Callback(hObject, eventdata, handles)
% hObject handle to Uniformity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)</pre><pre> f = msgbox('Look for the best slice, then press OK','test');
drawnow
waitfor(f);
Uniformity(dicom(:,:,val)); %function to run the test</pre><p>I've extensively tried to use handles and guidata, but it didn't work.
Thanks in advance.</p>drummerhttps://ch.mathworks.com/matlabcentral/profile/authors/6645378-drummertag:ch.mathworks.com,2005:Question/4111992018-07-19T18:34:59Z2018-07-19T18:42:19ZTimeout warnings with arduino and xbees<p>Hello everyone,</p><p>I'm currently putting together a wireless thermistor system using an Arduino Uno and two Xbees S1. While I have the Xbees communicating over a wireless serial connection successfully, I always end up with timeout warnings. ('Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.') This is frustrating as I would like to take hours of data, but it times out anywhere from a minute in to 10 minutes in.</p><p>The code I have uploaded to my Arduino via the Arduino IDE is as follows:</p><pre> //Setup constants (analog pins to be read)
const int analogPinA0 = A0;
const int analogPinA1 = A1;
const int analogPinA2 = A2;
const int analogPinA3 = A3;
const int analogPinA4 = A4;
const int analogPinA5 = A5;</pre><pre class="language-matlab">//variables
int mode = -1;
unsigned int sensorValue = 0;
</pre><pre class="language-matlab">void setup() {
// put your setup code here, to run once:
//BAUD
Serial.begin(9600);
</pre><pre class="language-matlab">}
</pre><pre class="language-matlab">void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0) //check if any data has been sent by PC
{
mode = Serial.read(); //check if there is a request for values
if(mode=='R') //used to set different modes for various operations
{
//read analog values of pins and send to PC
sensorValue = analogRead(analogPinA0);
Serial.println(sensorValue);
sensorValue = analogRead(analogPinA1);
Serial.println(sensorValue);
sensorValue = analogRead(analogPinA2);
Serial.println(sensorValue);
sensorValue = analogRead(analogPinA3);
Serial.println(sensorValue);
sensorValue = analogRead(analogPinA4);
Serial.println(sensorValue);
sensorValue = analogRead(analogPinA5);
Serial.println(sensorValue);
}
delay(30); //ms
}
}
</pre><p>On the Matlab side, I have the function setting up the serial connection and a function that translates the data read from the Arduino into temperature:</p><pre class="language-matlab">function [out] = setupSerial(comPort)
%Initialize the serial port communication between Arduino
%and Matlab. We ensure that the arduino is also communicating
%with Matlab at this time. A predefined code on the arduino
%acknowledges this. If setup is complete, then the value of
%setup is returned as 1, else 0
</pre><pre class="language-matlab">%Default boolean to true
flag = 1;
%Define the port
s = serial(comPort);
set(s,'DataBits',8);
set(s,'StopBits',1);
set(s,'BaudRate',9600);
set(s,'Parity','none');
set(s,'Timeout',10);
</pre><pre> fopen(s)
mbox = msgbox('Serial Communication setup.');
uiwait(mbox);
out.s = s;
out.flag = flag;
end</pre><pre class="language-matlab">function [Temp,Volt,Res] = xbeeV2T(R_fixed,V_tot,thermistor_slots_cell,out)
%xbeeV2T does the same as V2Temp_UDF.m but with the xbee
% Over serial instead of purely arduino
% out is a structure containing the serial structure s
load Steinhart_Coefs.mat
Volt = [];
Res = [];
Temp = [];
pause(2)
fwrite(out.s,'R','uchar');
for i=1:length(thermistor_slots_cell)
Volt(i) = str2num(fgetl(out.s))*0.0049; %Analog read directly to arduino is not voltage
end
Res = Res3950_UDF(Volt,R_fixed,V_tot);
Temp = Temp3950_UDF(Res,A,B,C);
end
</pre><p>Finally, my code which calls the latter function is in a while loop:</p><pre class="language-matlab">timer_tot = tic;
while (toc(timer_tot)< exptime)
timer_loop = tic;
[Temp(i,:), V_A(i,:), R(i,:)] = ...
xbeeV2T(R_fixed,V_total,A_in,wireless);
%Set the i-th row to all six thermistor readings (data taking)
time(i) = toc(timer_tot); %takes continuous time data
</pre><pre> %LIVE PLOT
for j = 1:length(A_in)
plot(time(i),Temp(i,j),'+','Color',clr{j},...
'linewidth',1.1)
grid on
hold on
end</pre><pre> %PAUSE TIME
looptime = toc(timer_loop);
pause(wait-looptime)
end </pre><p>I have tried subbing in and out fprintf for fwrite, as well as fread, fscanf, and fgets for fgetl. I have tried placing the pause both before and after the fwrite command as well as in the for loop. Regardless of my troubleshooting, I always get a timeout error. Ideally, I could erase the pause to take data every second (the value of wait), but at this point, I just want to avoid the timeout error.</p>Taylor Lonnerhttps://ch.mathworks.com/matlabcentral/profile/authors/11111114-taylor-lonnertag:ch.mathworks.com,2005:Question/4112002018-07-19T18:38:07Z2018-07-19T18:38:07ZHow to find all of the shared rows between several cells in a cell array and keep track of the number of times they are shared<p>I have a 1 x N cell array in Matlab. Each cell is of different size M(i) x 4, where i=1:length(cellarray). The first 3 columns hold x, y, and z coordinates, and the last column holds some data in my field at that location (for instance velocity).</p><p>Let's say cell1=cellarray{1} and cell2=cellarray{2} are now the individual cells, and pos1=cell1(:,1:3) and pos2=cell2(:,1:3) are the position data. I know that between pos1 and pos2, that I can find the indices of the shared rows using in=ismember(pos2,pos1,'rows'). The order here is deliberate because sometimes length(pos2)>length(pos1).</p><p>Here is my attempt at doing this with a for loop.</p><pre class="language-matlab">l=1;
for i=1:length(cellarray)
cell1 = cellarray{i};
pos1 = cell1(:,1:3);
for j=1:length(cellarray)
if i~=j
cell2 = TimeAvg_All{j};
pos2 = cellarray(:,1:3);
</pre><pre> in=ismember(pos2,pos1,'rows');
share{l} = pos2(in);
noshare{l} = pos2(~in);
l=l+1;
end
end
end</pre><p>Once this is done, I would have to repeat the process comparing the cells in share and noshare to each other as I did above with pos1 and pos2, differentiating between the rows that are shared. Keeping track of the individual share's and noshare's is cumbersome, and I was hoping that there might be an easier way to do this. It's quite easy if there is only two cells in the original cellarray but I have anywhere between 25 and 30.</p><p>My final goal is to have a count of how many times a specific position value (first three columns of any row in one of the cells) is repeated in the entire cellarray. Values that are not shared should have a count=0, values that are shared once should have a count=1 etc. I would also need to know all of the indices corresponding to the positions shared or not.</p><p>Thank you very much.</p>Nathaniel Wernerhttps://ch.mathworks.com/matlabcentral/profile/authors/3668968-nathaniel-wernertag:ch.mathworks.com,2005:Question/4111982018-07-19T18:30:51Z2018-07-19T18:36:53ZError using Interface.000208DA_0000_0000_C000_000000000046/SaveAs<p>I am trying to create an excel file and save it but for the first file I try to run this I get the following error on running the following line of code</p><pre class="language-matlab">>> ExcelWorkbook.SaveAs(output_xls);
</pre><pre class="language-matlab">Error using Interface.000208DA_0000_0000_C000_000000000046/SaveAs
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Cannot access 'Engagement_summary.xlsx'.
Help File:xlmain11.chm
Help Context ID: 0
</pre><p>Sometime before that I get a warning that occurs when i try to run delete(output_xls) but when I comment out this line the same error ends up occurring.</p><pre class="language-matlab">Warning: File not found or permission denied
</pre><p>If I run the code on 10 different files, it only does this for the first one, and then messes up that first one, but the rest it runs through just fine.</p><p>Any idea what could be going on? Sorry I can't submit my code, but I thought I'd ask anyways.</p><p>Thank you!</p>Matthew Suttonhttps://ch.mathworks.com/matlabcentral/profile/authors/11143657-matthew-suttontag:ch.mathworks.com,2005:Question/4111702018-07-19T15:52:54Z2018-07-19T18:35:59ZUicontextmenu doesn't work properly when using menu editor in GUI<p>I have a GUI with multiple axes, and I want a context menu in one of the axes. I used menu editor to get it to work, but for some reason I can only see the right click options if I don't have an image on the axis. The moment I use imshow on that axis for example, I can no longer see the context menu. I've tried looking around for a solution, but most people seem to be hard coding uicontextmenu, and I want to know how to make it work properly through the menu editor. Thanks for any help.</p>Matt Markowitzhttps://ch.mathworks.com/matlabcentral/profile/authors/12186718-matt-markowitztag:ch.mathworks.com,2005:Question/4106882018-07-17T09:28:59Z2018-07-19T18:35:23ZWrite Enumerator/ENUM type data to PostgreSQL database with sqlwrite (Database Toolbox)<p>Hi everyone,
I created an ENUM type in my PostgreSQL database:</p><pre class="language-matlab">CREATE TYPE public.producttype AS ENUM
('FCR', 'aFRR', 'mFRR');
</pre><p>And then I created an object in Matlab:</p><pre class="language-matlab">testdata = table();
testdata.producttype = {'FCR'};
testdata.value = 20;
</pre><p>If I upload my table to my PostgreSQL database with sqlwrite I get an error:</p><pre class="language-matlab">sqlwrite(conn, 'de_regelleistung', testdata)
</pre><p>Error message:</p><pre class="language-matlab">Error using database.jdbc.connection/sqlwrite (line 172)
JDBC JDBC/ODBC Error: Batch entry 0 INSERT INTO de_regelleistung ( producttype, value ) VALUES ( 'FCR', 20 ) was aborted: ERROR: column
"producttype" is of type producttype but expression is of type character varying
Hinweis: You will need to rewrite or cast the expression.
Position: 163 Call getNextException to see other errors in the batch..
</pre>Markus Kreuzerhttps://ch.mathworks.com/matlabcentral/profile/authors/12725989-markus-kreuzertag:ch.mathworks.com,2005:Question/4111932018-07-19T18:22:49Z2018-07-19T18:31:58ZFinding L and R marks in a X-Ray image<p>I want to find L (left) and R (marks) in X-Ray Images (.jpg). Afterwards I want to give an output whether it's right or left (foot for example). Do you have an idea? Best regards</p>Felix Seilerhttps://ch.mathworks.com/matlabcentral/profile/authors/12349213-felix-seilertag:ch.mathworks.com,2005:Question/4109712018-07-18T16:00:15Z2018-07-19T18:30:48ZHow can I apply multiple in mintutes for loops to 365 days<p>I am new in MATLAB and I need a help to calculate resistance growth for a battery for one year and then estimation how many years does need to reach 200% of its initial value. If I have an equation for it in for loop for different uses a day, how can apply those uses in minutes to 365 days?</p><p>For example,</p><pre class="language-matlab">for i=1:365 %one year
</pre><pre> for j=1:720 % using the battery for the half of day (in minutes)</pre><pre> time_1= ??? % here is the place to link i and j ????</pre><pre> R_1= x*time_1;%resistance growth for the first use</pre><pre> end</pre><pre> for k=721:1440 % using the battery for the half of day (in minutes)</pre><pre> time_2= ???? %here is the place to link i and k</pre><pre> R_2= x*time_2;%resistance growth for the second use</pre><pre> end
end </pre><p>Any idea which helps will be appreciated. Thank you in advance!</p>Muapper Alhadrihttps://ch.mathworks.com/matlabcentral/profile/authors/3641891-muapper-alhadritag:ch.mathworks.com,2005:Question/4111942018-07-19T18:24:32Z2018-07-19T18:24:32ZHow to produce Documentation for my appdesigner app?<p>I made a MATLAB app using appdesigner for a school project and I am now trying to produce documentation for it</p><p>I tryed to look at <a href = "https://it.mathworks.com/help/matlab/matlab_prog/create-help-for-classes.html#btleu9g-1">create-help-for-classes</a> but it seems that it doesn't read the comment line under the function name and i just get a plain default text when i look for my function with the doc comand</p><p>do you have any suggestion for me?</p>Fabrizio Zavanonehttps://ch.mathworks.com/matlabcentral/profile/authors/9914887-fabrizio-zavanonetag:ch.mathworks.com,2005:Question/4111862018-07-19T17:29:26Z2018-07-19T18:23:10ZFinding distribution from few moments<p>I have first 4 moments of an unknown distribution and I want to approximate that unknown distribution. Is there any method in MATLAB by which I can do this?</p>Luqman Saleemhttps://ch.mathworks.com/matlabcentral/profile/authors/9731121-luqman-saleemtag:ch.mathworks.com,2005:Question/4109682018-07-18T15:49:47Z2018-07-19T18:22:36ZEverytime I run my code I keep getting an infinite recursion error. My code is posted below. Can you please help me figure out why it keeps giving me this error?<p>It flags me at the y(:, i) = x.^(i)./factorial(i); line below.</p><pre class="language-matlab">function exp = expapprox(x,n)
n = 5;
x = 1:5;
% number of iterations for loop
for i = 1:n
y(:, i) = x.^(i)./factorial(i);
end
exp = 1+ sum(y);
actexp = exp(x);
plot(actexp, expapprox(x,5))
end
</pre>Alison Michellhttps://ch.mathworks.com/matlabcentral/profile/authors/12652638-alison-michelltag:ch.mathworks.com,2005:Question/2551032015-11-16T14:50:00Z2018-07-19T18:22:24ZImport too large csv data file with strings <p>My file is about 72 MB, almost 850000 rows and on average 7 columns, so some times the number of columns changes. Data is mostly comprised of strings so i used the:</p><p><a href = "http://www.mathworks.com/matlabcentral/fileexchange/23573-csvimport">http://www.mathworks.com/matlabcentral/fileexchange/23573-csvimport</a></p><p>as</p><pre class="language-matlab">name= 'etch.csv';
</pre><pre class="language-matlab">[C1, C2, C3, C4, C5, C6, C7] = csvimport(name, 'columns', [1:7], 'noHeader', true, 'delimiter', ';' );
</pre><p>(i am interested only in the 7 columns even there were cases with more data)
This works perfectly for small data sets. For my case it took me almost 30 minutes or even more. Any idea for something better? Thank you</p><p>PS My data type is:</p><p>1: Device Name,Category,Date,Time,Source,Message,Condition,Name,Act</p><p>2: string1,string2,mm/dd/yyyy,hh:mm:ss.sss,string,string,string,1 or 0</p><p>.....</p><p>850000: and it goes on as line 2</p><p>last column most of the times has no data but does not interest me</p>Christos Antonakopouloshttps://ch.mathworks.com/matlabcentral/profile/authors/7285075-christos-antonakopoulostag:ch.mathworks.com,2005:Question/4111782018-07-19T16:48:37Z2018-07-19T18:20:08ZHow can I change imge dimentions?<p>Hi, everyone!</p><p>I have a database of images (the number of images may vary) with different dimensions, need to change thier width/high (resize whole image but not crop it) to same one, then save the new images in a separate folder.</p><p>I have tried the im.resize function, but the image is cropped and information lost. It is necessary that the integrity of the image does not change, but only its parameters.</p><p>Thanks</p>victorhttps://ch.mathworks.com/matlabcentral/profile/authors/3197154-victortag:ch.mathworks.com,2005:Question/4107632018-07-17T15:56:08Z2018-07-19T18:19:46ZA function that will open a windows command prompt and check the network licenses available?<p>Piggy-backing off this question: <a href = "https://www.mathworks.com/matlabcentral/answers/102830-is-there-a-way-for-licenses-to-be-monitored-from-the-client-machine-instead-of-the-server">Is there a way for licenses to be monitored from the client machine instead of the server?</a></p><p>My goal is to have a MATLAB function I can call that will print the in-use network licenses to the command window, then return control to MATLAB without having to Ctrl+C. The $MATLAB, $ARCH, $LICENSE PATH have all been replaced with the appropriate folder locations in my code.</p><p><b>Current Code:</b></p><pre class="language-matlab">function checkLicense()
%checkLicense Checks to see if MATLAB licenses are available
!cmd.exe
sprintf('cd $MATLAB/etc/$ARCH')
sprintf('lmutil lmstat -a -c "$LICENSE PATH"')
end
</pre><p>This will give access to the cmd.exe through MATLAB's command window, but doesn't print out the actual commands (looking at it now, it's obvious that wouldn't work because I'm giving control to cmd.exe, not MATLAB).</p><p><b>What I've Tried:</b></p><p>Using the <i>dos( __</i>,'-echo')_ and <i>system( __</i>,'-echo')_ functions to cd and use 'lmutil', I get the error:</p><p><i>'lmutil' is not recognized as an internal or external command,
operable program or batch file.</i></p>Mike Crawfordhttps://ch.mathworks.com/matlabcentral/profile/authors/13024015-mike-crawfordtag:ch.mathworks.com,2005:Question/3984302018-05-01T04:00:00Z2018-07-19T18:18:09ZWhy does the Update Installer fail with no clear error message shown in the log file?<p>When trying to install the R2017b Updates the installation process terminates with the message:</p><pre class="language-matlab">Installation failed [1]
</pre><p>There is no other clear indicator of what may be causing the issue. How can I resolve the issue?</p>MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ch.mathworks.com,2005:Question/4111842018-07-19T17:12:16Z2018-07-19T18:16:58ZHelp with conidtional loops? <p>Everything in the code works like I want it to except I need the code to end if a guess is higher than 10. it will display 'dumb' but also needs to end the program. I can't get it to break the code.</p><pre class="language-matlab">%% Guess Number Game
</pre><pre class="language-matlab">R=floor ( rand()*10 );
count=0;
</pre><pre class="language-matlab">for i=0:5
while(i~=5)
</pre><pre> guess=input('Guess a number between 0 and 10')</pre><pre> if (R>guess)
disp('Your Guess Is Too Small')</pre><pre> elseif (R<guess)
disp('Your Guess Is Too Large')</pre><pre> elseif (R==guess)
disp('You are Correct! It is')
end</pre><pre> if (guess>10)
disp('DUMB')
break;
end</pre><pre> count=count+1
if count==3;
disp ('You Failed The Game, Try Again')
count=0;</pre><pre> break;</pre><pre> end
end
end</pre>Taylor Gateshttps://ch.mathworks.com/matlabcentral/profile/authors/12943866-taylor-gatestag:ch.mathworks.com,2005:Question/4111872018-07-19T17:42:00Z2018-07-19T18:14:11ZSetting Limits on a Random Number Generation<p>I am creating a matrix of numbers with a normal distribution; however, I need to truncate the data so that all random values are between 0 and 100. Below is the code I wrote to produce the random values so far. How would you set limits for the random number generator?</p><pre class="language-matlab">n = 1000;
RQD_mu = 71;
RQD_sigma = 10;
RQD = zeros(n,1);
for i = 1:n
RQD(i) = random('Normal', RQD_mu, RQD_sigma);
end
</pre>Ryan Ziebarthhttps://ch.mathworks.com/matlabcentral/profile/authors/13174680-ryan-ziebarthtag:ch.mathworks.com,2005:Question/4096422018-07-10T13:12:36Z2018-07-19T18:12:39ZIs there any way to reduce the error in the calculation of eigenvectors when using eig function? <p>In the equation AV = BVD (cond(A) = 10^4, cond(B) = 10^8), my A and B matrices are highly ill-conditioned. The eigenvectors I am getting have an error around 100, whereas the actual value of eigenvector is in the order of 10^-2. I tried [V, D] = eig(A, B, 'qz'), but this didn't make much difference. So is there any way I can specify the error tolerance while using [V, D] = eig(A, B) or is there any other way of computing eigenvectors with the required tolerance in MATLAB?</p><p>Thanks.</p>Yaswanth Saihttps://ch.mathworks.com/matlabcentral/profile/authors/8803177-yaswanth-saitag:ch.mathworks.com,2005:Question/4111912018-07-19T18:10:56Z2018-07-19T18:10:56ZDo threads continue to run in MEX files when executing has been passed back to MATLAB<p>I have a mex file that starts a thread that listens for messages from another program via windows sockets. I know that while execution is in the MEX file, that it can receive the messages and process them. Now, if I start the same thread and then exit the mex file back into the MATLAB environment, will the thread continue to run and process messages? I'd like to be able to check in every once in awhile and see how things are going without having to be stuck in the MEX file waiting for something to happen.</p>Justin Bodehttps://ch.mathworks.com/matlabcentral/profile/authors/2427027-justin-bodetag:ch.mathworks.com,2005:Question/4110132018-07-18T19:03:09Z2018-07-19T18:10:21ZFind all roots of non linear equation<p>Hi,</p><p>i want to find the all roots of an non linear equation without using the symbolic toolbox because of runtime issues. So i tried to use fzero and i found this helpful thread: <a href = "https://de.mathworks.com/matlabcentral/answers/160117-how-to-use-fzero-and-choose-correctly-initial-guess">https://de.mathworks.com/matlabcentral/answers/160117-how-to-use-fzero-and-choose-correctly-initial-guess</a></p><p>So i added my equation to it. The problem is that it doesn't fin initial guesses because of the step size. if i am using x = linspace(-1,1); it finds the root but not if i have a bigger intervall. And the problem is that normally i don't know the intervall that exactly.</p><p>1. Has sb an idea how i could improve the code to make it work for me ? Or has sb any idea how i could solve this problem with another method ? I cannot use roots() or sth else for polynoms because the equation is no polynom.</p><pre class="language-matlab">if true
b1=0
b2=0
v1=0
v2=0
s1=0
s2=0.175
j2=0.28
tau =300
x = linspace(-10,10); % Interval To Evaluate Over
f = @(x)-s2 + s1 + (v1 + (b1 - j2.*x).^2/(2.*j2) + (j2.*x.^2)/2 - (b1.*(b1 - j2.*x))/j2).*(tau - x - (2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(2.*j2) + (b1 - j2.*x)/j2 + (2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(2.*j2)) + (2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2)).^3/(48.*j2.^2) - (b1 - j2.*x).^3/(6.*j2.^2) + (j2.*x.^3)/3 + x.*(v1 + (b1 - j2.*x).^2/(2.*j2) - (b1.*(b1 - j2.*x))/j2) - (v1.*(b1 - j2.*x))/j2 + (2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(3/2))/(24.*j2.^2) + (b1.*(b1 - j2.*x).^2)/(2.*j2.^2) + ((2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2)).*(v1 - (j2.*v1 - j2.*v2 - b1.^2/2 + b2.^2/2 + j2.^2.*x.^2)/(2.*j2) + (b1 - j2.*x).^2/(2.*j2) + (j2.*x.^2)/2 - (b1.*(b1 - j2.*x))/j2))/(2.*j2) + (2.^(1/2).*(2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2)).^2.*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(16.*j2.^2) - (2.^(1/2).*(v1 + (b1 - j2.*x).^2/(2.*j2) + (j2.*x.^2)/2 - (b1.*(b1 - j2.*x))/j2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(2.*j2);
fplot(f)
fx = f(x); % Function Evaluated Over ‘x’
cs = fx.*circshift(fx,-1,2); % Product Negative At Zero-Crossings
xc = x(cs <= 0); % Values Of ‘x’ Near Zero Crossings
for k1 = 1:length(xc)
fz(k1) = fzero(f, xc(k1)); % Use ‘xc’ As Initial Zero Estimate
end
syms x
f = -s2 + s1 + (v1 + (b1 - j2.*x).^2/(2.*j2) + (j2.*x.^2)/2 - (b1.*(b1 - j2.*x))/j2).*(tau - x - (2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(2.*j2) + (b1 - j2.*x)/j2 + (2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(2.*j2)) + (2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2)).^3/(48.*j2.^2) - (b1 - j2.*x).^3/(6.*j2.^2) + (j2.*x.^3)/3 + x.*(v1 + (b1 - j2.*x).^2/(2.*j2) - (b1.*(b1 - j2.*x))/j2) - (v1.*(b1 - j2.*x))/j2 + (2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(3/2))/(24.*j2.^2) + (b1.*(b1 - j2.*x).^2)/(2.*j2.^2) + ((2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2)).*(v1 - (j2.*v1 - j2.*v2 - b1.^2/2 + b2.^2/2 + j2.^2.*x.^2)/(2.*j2) + (b1 - j2.*x).^2/(2.*j2) + (j2.*x.^2)/2 - (b1.*(b1 - j2.*x))/j2))/(2.*j2) + (2.^(1/2).*(2.*b2 - 2.^(1/2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2)).^2.*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(16.*j2.^2) - (2.^(1/2).*(v1 + (b1 - j2.*x).^2/(2.*j2) + (j2.*x.^2)/2 - (b1.*(b1 - j2.*x))/j2).*(2.*j2.*v1 - 2.*j2.*v2 - b1.^2 + b2.^2 + 2.*j2.^2.*x.^2).^(1/2))/(2.*j2);
vpa(solve(f,x))
end
</pre>IlPadrinohttps://ch.mathworks.com/matlabcentral/profile/authors/5234029-ilpadrinotag:ch.mathworks.com,2005:Question/4111882018-07-19T17:47:53Z2018-07-19T18:10:10ZHow to solve for a variable in an exponential equation <p>I want to solve this function for rs.. I used this code</p><p>syms ra rb rs Vr</p><p>Eq1 = Vr == exp((-pi*ra)/rs)+exp((-pi*rb)/rs);</p><p>t_sol = solve(Eq1, rs)</p><p>but I am getting an empty sym
can anyone help me
it's urgent</p>Alice Faisalhttps://ch.mathworks.com/matlabcentral/profile/authors/12004227-alice-faisaltag:ch.mathworks.com,2005:Question/4111812018-07-19T16:58:02Z2018-07-19T18:02:08ZTo find common area between two plots.<p>Hello everyone,
I want to find the common area between a circle whose diameter endpoints' coordinates are known and a curve formed by a set of 175 points. How to do that??</p>Sanjana Dhiranhttps://ch.mathworks.com/matlabcentral/profile/authors/10312282-sanjana-dhirantag:ch.mathworks.com,2005:Question/4111892018-07-19T17:49:06Z2018-07-19T18:01:07ZError trying to use Nested Functions: Not shared Variable<p>Hello,</p><p>I'm currently trying to write my script using Nested Functions in the aim to use less memory space with the inputs-variables calls.</p><p>And so, when I'm calling my parent function, it returns me:
"Error using cumsum
CUMSUM supports only numerical or logical inputs."</p><p>and in fact, I'm using cumsum(A) where A is normally the result of my Nested function, but it doesn't seem to operate because A doesn't appear in the workspace...
I've tried to create A=[] before calling the Nested function but it didn't change any thing.</p><p>Does someone know what could be the problem please ?</p><p>Thank you in advance and have a nice day,</p><p>Eric</p><p>Could someone tell me if the anterior way of writing it is a convenient structure please</p>Eric VALETTEhttps://ch.mathworks.com/matlabcentral/profile/authors/13044274-eric-valettetag:ch.mathworks.com,2005:Question/1190972014-02-25T19:54:13Z2018-07-19T17:55:02Zi want a matlab code on segmentation of cursive handwriting using fuzzy method<p>or any method except neural network
help me if possible</p>yashikahttps://ch.mathworks.com/matlabcentral/profile/authors/4879126-yashikatag:ch.mathworks.com,2005:Question/2592462015-12-07T16:36:25Z2018-07-19T17:53:55ZTI C2000 F28335 integrating with MATLAB Simulink<p>Hi everyone,</p><p>We have a TI C2000 F28335 Delfino Family Experimenter Kit. We have two version of MATLAB; R2010a and R2013a. Code Composer Studio V.6 is also loaded. Our purpose is to integrate MATLAB with our TI control board. What are the fundamental steps to configure Matlab with CSS? Our purpose is to make some tests with this board through using Simulink environment? Could anyone help about this issue?</p>Mirsadhttps://ch.mathworks.com/matlabcentral/profile/authors/5105612-mirsadtag:ch.mathworks.com,2005:Question/4111902018-07-19T17:51:37Z2018-07-19T17:51:37ZFeature Selection using PCA (Principal Component Analysis)<p>Hello all,</p><p>Currently have 16 features, that I want to select using PCA, in order to use later on in a classifier.
My data array is <i>significant_metric_values</i> and has a dimension of 61 (observations) x 16 (features).</p><p>Previous to PCA, I normalize each column by subtracting its mean and dividing with the standard deviation.</p><p>After this I apply PCA:</p><pre class="language-matlab">[coeff,score,~,~,explained] = pca(significant_metric_values);
</pre><p>When plotting the cumulative variance percentage (plot(cumsum(explained/sum(explained))*100)), I got a nice plot.</p><p><b>My question is the following: Assuming that I want to select features that select up to 90% of the variance, I have to plot, I have to choose 9 features. But which features should I choose?</b></p><p>I believed it was the first 9 features from the <i>significant_metric_values</i> array, but if I redo the analysis changing the <i>significant_metric_values</i> array, the plot is equal.</p><p>How do I know which features to use in my classifier?</p><p>Many thanks,</p><p>Diogo</p>Diogo Tecelãohttps://ch.mathworks.com/matlabcentral/profile/authors/6133591-diogo-tecelaotag:ch.mathworks.com,2005:Question/4111632018-07-19T15:27:29Z2018-07-19T17:50:59ZIs there a way to plot multiple files using a loop in matlab?<p>I want to use a for loop to plot data from a range of files whos names are string values. This is the code I am using:</p><pre> %Convert variable year from integer to string
yr=num2str(17);
dy=num2str(15);
mn=num2str(3);</pre><pre> yr2 = num2str(17);
dy2 = num2str(4);
mn2 = num2str(4);</pre><pre> %Create a MMDDYY string
date_str=[mn '-' dy '-' yr];
date_str2=[mn2 '-' dy2 '-' yr2];</pre><pre> for i = date_str:date_str2</pre><p>is there a way I can plot the data from 3-15-17 to 4-4-17, which are in excel files? I already have programs in which I can plot an individual day, I just want to be able to plot a range of days.</p>Brandon Bushhttps://ch.mathworks.com/matlabcentral/profile/authors/9649681-brandon-bushtag:ch.mathworks.com,2005:Question/4099602018-07-12T06:16:40Z2018-07-19T17:45:59ZHow do I interpolate a set of data and change the timestamp to specific points in time?<p>I have several sets of data coming from different sensors which register data at different time-intervals. I want to synchronize the time of all the data down to milliseconds, and I want to interpolate the values for the timestamps so they match the new timestamp.</p><p>Some sensors register a new value every hour, while others register for every 10th, 8th, 30th, etc, minutes.</p>Anders Teigmoenhttps://ch.mathworks.com/matlabcentral/profile/authors/11042554-anders-teigmoentag:ch.mathworks.com,2005:Question/4091592018-07-06T16:27:23Z2018-07-19T17:42:09ZHow can I clear specific Python classes/modules from memory without using "clear classes"<p>I have successfully developed a workflow that will allow me to call custom python code from Matlab, see the following two scripts:</p><p>MATLAB:</p><pre class="language-matlab">function out = reloadPy() % A Matlab function
clear classes
mod = py.importlib.import_module('mymod');
py.importlib.reload(mod);
v1 = 1:5;
v2 = 6:10;
out = double(py.mymod.add2Vectors(v1,v2));
</pre><p>Python:</p><pre class="language-matlab"># mymod.py - a python function
</pre><pre class="language-matlab">import numpy
import array
</pre><pre class="language-matlab">def add2Vectors(v1, v2):
myarray = numpy.array(v1) + numpy.array(v2)
return array.array('d', myarray)
</pre><p>If I call reloadPy from the command line I get the following output:</p><pre class="language-matlab">>> test = reloadPy
Warning: Objects of 'onCleanup' class exist. Cannot clear this class or any of its superclasses.
> In reloadPy (line 2)
Warning: Objects of 'table' class exist. Cannot clear this class or any of its superclasses.
> In reloadPy (line 2)
Warning: Objects of 'datetime' class exist. Cannot clear this class or any of its superclasses.
> In reloadPy (line 2)
</pre><pre class="language-matlab">test =
</pre><pre> 7 9 11 13 15</pre><pre class="language-matlab">>>
</pre><p>The warnings are stemming from the "clear classes" command. I am using that sequence of commands (lines 2-4) to reload the python module while debugging. Any changes I make to mymod.py are not captured unless I execute all 3 commands. The documentation for "clear" states:</p><pre class="language-matlab">Calling clear all, clear classes, and clear functions decreases code performance, and is usually unnecessary. ...
</pre><pre class="language-matlab">To clear a particular class, use clear myClass.
</pre><p><b>Is there a way to just clear just my python class or module?</b> I can't find the name. I tried</p><pre class="language-matlab">[M, X, C] = inmem
</pre><p>But none of the result seem to be related to python.</p>Emil Geigerhttps://ch.mathworks.com/matlabcentral/profile/authors/7902321-emil-geiger