https://fr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-03-26T20:49:45Ztag:fr.mathworks.com,2005:Question/3320302017-03-26T20:09:40Z2017-03-26T20:49:45ZExtracting frames from webcam !! <p>Hi everyone,
I want to extract the frame from my running webcam every 3 second I want to extract the frame and save it into variable to process it later so how I can do it please ?? I did this but not taking picture as running video ..</p><pre class="language-matlab">vid = videoinput('winvideo',2);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb');
for i=1:10
data = getsnapshot(vid);
figure(i);
imshow(data);
end
</pre>Khaled Al-Falehhttps://fr.mathworks.com/matlabcentral/profile/authors/9921472-khaled-al-falehtag:fr.mathworks.com,2005:Question/3320262017-03-26T19:39:47Z2017-03-26T20:47:34Zhi ı am a master student and I have a home work<pre> I have A BİNARY PİCTURE AND I WANT TO CALCULATE İT'S MAXİMUM width and length.can you help me , its a urgent situation =(</pre>hasan güneshttps://fr.mathworks.com/matlabcentral/profile/authors/9989524-hasan-gunestag:fr.mathworks.com,2005:Question/3320312017-03-26T20:45:01Z2017-03-26T20:45:01ZHow can I import data from an excel file and use it for calculations in GUI?<p>Hello everybody,</p><p>I have a little problem with the import of an excel file...
I want that the user can coose which file is imported with a button. I have a code, but I allways ger an error code, though I'm following suggestions from thee community. In my excel file I got rawdata of meassurements with 4 FSR sensors. Whenever I'm importing the data i can not make calculations within the button callback code. For testing I wanted to show the mean value of each sensor in a text box. Here is my code so far:
dataexcel=uigetfile;
data=dataexcel;
sensor1=data(:,3);
sensor2=data(:,4);
sensor3=data(:,1);
sensor4=data(:,2);
mean1=mean(sensor1);
set(handles.text2,'string',mean1);
mean2=mean(sensor2);
set(handles.text3,'string',mean2);
mean3=mean(sensor3);
set(handles.text4,'string',mean1);
mean4=mean(sensor4);
set(handles.text5,'string',mean1);</p><p>The thing is, that the values should be between 1 and 0.005, but the values seem to be random (102 for example). Can anybody help me? I can not import the data from excel into my workspace... So I can't calculate later on... Is it beacause I do something wrong with the import of the excel file? I am not able to save the parts of the file to variables... Please help me with my problem :)</p>Felifahttps://fr.mathworks.com/matlabcentral/profile/authors/9920438-felifatag:fr.mathworks.com,2005:Question/3320052017-03-26T16:36:23Z2017-03-26T20:44:36ZHOG feature extraction for 112x92<p>person = 5;
[hogFeature, visualization]= ...
extractHOGFeatures(read(training(person),1));
figure
This is the code for face detection. The code extracts the first image of a person. the image size is 112x92. In the workspace the hog feature shows 1x4680, for different dimension of image the hog feature value changes. I am unable to understand the changes of HOG feature. Can anyone help me please</p>Tousif Ahmedhttps://fr.mathworks.com/matlabcentral/profile/authors/9853263-tousif-ahmedtag:fr.mathworks.com,2005:Question/3320292017-03-26T20:03:00Z2017-03-26T20:44:36Zmodeling a forest fire<p>We are tasked with the question seen attached below, simulating a forest fire.</p><p>I have the following code, but was looking for some ideas or help on finishing off this problem.</p><p>Thanks</p><pre class="language-matlab">function outcomes = fire(numRows, numCols, startRow, startCol, trials)
% Simulate the spread of a fire.
start = (startRow, startCol)
if nargin == 5
trials = trials; % #trials = number of trials user inputs
</pre><pre class="language-matlab">elseif nargin == 4
trials = 1; %if not specified, trials = 1
%if only one trials performed, display the fire simulation
end
</pre><pre> while (startRow > 0 && startCol > 0 && numRows > 0 && numCols > 0) %runs the function while in the boundaries specified (ie. doesnt reach bottom end of grid)
currLoc = start + 1 %current location = starting location + 1</pre><pre> for i = 1 : trials %duration of simulation
[a b] = fire(outcomes, trials);
if a == 1
outcomes = outcomes + 1;
end</pre><pre> end
end</pre><pre> if currLoc == 0 %fire went out
success = 0;
else %fire continues
success = 1;
end</pre><pre class="language-matlab">colormap([.035 .200 .153; 1.00 .367 .063; .561 .510 .592]) % rgb values for green, orange, gray
map = [ 1 1 1 1; 3 3 3 1; 2 3 3 1 ];
image(outcomes);
</pre><pre class="language-matlab">end
</pre>John Jamisonhttps://fr.mathworks.com/matlabcentral/profile/authors/9544970-john-jamisontag:fr.mathworks.com,2005:Question/3319182017-03-25T21:02:18Z2017-03-26T20:40:08ZConvert .txt/.mat to .wav format<p>I have a .txt and a .mat file, both containing the same data. I would like to convert either one(whichever is easier) to a .wav file so that I can play the sound and carry out audio processing. I understand 'wavwrite' is one way of doing this but so far I have been unsuccessful.
I have tried:</p><pre class="language-matlab">>> load('data.mat')
>> hfile='data.wav';
>> wavwrite(y, Fs, hfile)
</pre><p>But when I run the code, it displays:</p><pre class="language-matlab">Undefined function or variable 'y'.
</pre><p>Does anyone know the solution to this problem or even an alternative method to convert a .txt/.mat file to .wav? Thanks</p>bilal malikhttps://fr.mathworks.com/matlabcentral/profile/authors/4821130-bilal-maliktag:fr.mathworks.com,2005:Question/3320112017-03-26T17:19:02Z2017-03-26T20:38:52ZI want to find out SVD of a 7X7 matrix(small block of an frame) for frames in temporal direction.<p>I want to find out SVD of a block, of a frame in temporal direction but I am getting error"Undefined function 'svd' for input arguments of type 'uint32'"</p><pre class="language-matlab">for num=1:NumberOfimages
km{:,:,num}= rgb2gray(uint32(imread(sprintf('path of frames',num))));
im=km{:,:,num};
for i=24
for j=24
submatrix = im(24:30, 24:30);
S=svd(submatrix);
SCELL{:,:,num}=S;%stores all the eigen values
</pre><pre> end
end</pre><pre> end</pre>Bibhu Prasad Dashttps://fr.mathworks.com/matlabcentral/profile/authors/9088446-bibhu-prasad-dastag:fr.mathworks.com,2005:Question/3320142017-03-26T17:32:53Z2017-03-26T20:38:27ZNo solution for my script/seemingly infinite calculation time<p>I need to calculate and graph solutions for a grain on a sifting plate, and I have this script, and it works for most of my values, but for some reason when i use these values it just keeps on calculating, and matlab starts using more of my RAM</p><pre class="language-matlab">close all
</pre><pre class="language-matlab">clear all
</pre><pre class="language-matlab">clc
</pre><pre class="language-matlab">R=0.025; % [m]
</pre><pre class="language-matlab">Omega=4; % [rad/s]
</pre><pre class="language-matlab">Mu=0.5; % [dimensionless]
</pre><pre class="language-matlab">g=9.81; % [m/s^2]
</pre><pre class="language-matlab">tspan=[0 100]; % time interval
</pre><pre class="language-matlab">ystart=[0 0.0000001 0 0]; % beginning conditions
</pre><pre class="language-matlab">eq=@(t,y) [y(2) ; - (Mu*g*y(2))/(sqrt( (y(2)^2) + (y(4)^2) )) + R*(Omega^2)*(cos(Omega*t)) ; y(4) ; - (Mu*g*y(4))/(sqrt( (y(2)^2) + (y(4)^2) )) + R*(Omega^2)*(sin(Omega*t)) ];
</pre><pre class="language-matlab">[t,y]=ode45(eq,tspan,ystart);
</pre><pre class="language-matlab">figure(1)
plot(y(:,1), y(:,3), 'g'); % this plots the position
</pre><pre class="language-matlab">xlabel('positie along the x-axis');
</pre><pre class="language-matlab">ylabel('positie along the y-axis');
</pre><pre class="language-matlab">title('movement of grain combination 2');
</pre><pre class="language-matlab">axis equal;
</pre>Dries Van Hemelenhttps://fr.mathworks.com/matlabcentral/profile/authors/6188722-dries-van-hemelentag:fr.mathworks.com,2005:Question/1655342014-12-05T09:11:56Z2017-03-26T20:36:17ZSet workspace data to sub GUI by push button on main GUI<p>Hello there,</p><p>I am currently working on a simulation program, which consists of two GUI's. I am having difficulties setting an edit text box with a value in the sub GUI by using a push button on the main GUI.</p><p>The main GUI has an "OPEN" button, which opens a .mat-file consisting a list of variables and sets these variables to the workspace. Some variables have to be set to the main GUI and some variables should be set to the sub GUI. I can open the sub GUI with a button "SUBGUI" on the main GUI.</p><p><b>Example</b></p><p>I can open the sub GUI with a button "SUBGUI" on the main GUI, and the main GUI has an "OPEN" button, which opens a .mat-file consisting variables "a" and "b".The two variables "a" and "b" are opened from the .mat-file and added to the workspace. "a" should be set to an edit text box in the main GUI and "b" should be set to an edit texg box in the sub GUI. Currently I am using this code.</p><p>a = 2
b = 3</p><pre class="language-matlab">function Open_Callback(hObject, eventdata, handles)
%Open .mat-file with values a and b
[FileName,PathName]=uigetfile('*.mat','Select .mat file to open');
if isequal (FileName,0)
msgbox('Cancelled')
else
evalin('base',['load ' FileName]);
end
%setting handles edit text box a to main GUI
set(handles.a, 'String', evalin('base','a'));
</pre><pre class="language-matlab">%setting handles edit text box b to sub GUI
b=evalin('base','b');
set(handles.b,'String',b);
</pre><p>This works for the main GUI, but not for the sub GUI. There are two problems:</p><p>1) When the variables are set to the workspace and I open the Sub GUI an error is generated. However, the string of the edit text box b is set to 3.</p><pre class="language-matlab">Reference to non-existent field 'b'.
</pre><pre class="language-matlab">Error in VibrationModel>Open_Callback (line 338)
set(handles.b,'String',b);
</pre><pre class="language-matlab">Error in gui_mainfcn (line 95)
feval(varargin{:});
</pre><pre class="language-matlab">Error in VibrationModel (line 42)
gui_mainfcn(gui_State, varargin{:});
</pre><pre class="language-matlab">Error in @(hObject,eventdata)VibrationModel('Open_Callback',hObject,eventdata,guidata(hObject))
</pre><pre class="language-matlab">Error while evaluating uicontrol Callback
</pre><p>2) If I haven't opened a .mat-file and the workspace is empty, the Sub GUI cannot be opened. Matlab generates an error for not having a variable b in the workspace.</p><pre class="language-matlab">Error using evalin
Undefined function or variable 'b'.
</pre><pre class="language-matlab">Error in SUBGUI>SUBGUI_OpeningFcn (line 58)
set(handles.b,'String',evalin('base','b'));
</pre><pre class="language-matlab">Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
</pre><pre class="language-matlab">Error in SUBGUI (line 42)
gui_mainfcn(gui_State, varargin{:});
</pre><pre class="language-matlab">Error in VibrationModel>SUBGUI_Callback (line 83)
SUBGUI;
</pre><pre class="language-matlab">Error in gui_mainfcn (line 95)
feval(varargin{:});
</pre><pre class="language-matlab">Error in VibrationModel (line 42)
gui_mainfcn(gui_State, varargin{:});
</pre><pre class="language-matlab">Error in @(hObject,eventdata)VibrationModel('SUBGUI_Callback',hObject,eventdata,guidata(hObject))
</pre><pre class="language-matlab">Error while evaluating uicontrol Callback
</pre><p>I hope anyone can help me solving these problems.</p>Maartenhttps://fr.mathworks.com/matlabcentral/profile/authors/5632278-maartentag:fr.mathworks.com,2005:Question/3320022017-03-26T16:27:42Z2017-03-26T20:34:25ZHow to convert 400 images to Gray scale<p>I have 400 images stored in a folder which are color photos, i need to convert them to gray scale and I need to resize them to 112x92 and should store the converted and resized images in a file. Please help me with the code.</p>Tousif Ahmedhttps://fr.mathworks.com/matlabcentral/profile/authors/9853263-tousif-ahmedtag:fr.mathworks.com,2005:Question/3319752017-03-26T12:52:01Z2017-03-26T20:34:13ZHow to read image data sets from a folder at once ?<p>Hello. I have 40 datasets in a folder in C drive. I need to convert those files from RGB to grayscale and should resize it but i am unable to read the file and cant convert all the files from RGB to gray at once and cant resize all the images at once and should save the converted and resized images. Can anyone help me with the coding of that please</p>Tousif Ahmedhttps://fr.mathworks.com/matlabcentral/profile/authors/9853263-tousif-ahmedtag:fr.mathworks.com,2005:Question/3315552017-03-23T16:31:13Z2017-03-26T20:32:35ZCan I use some other values rather then using the values of t2(target) to calculate the ya in neural network?<p>yn = B2 + LW2 * logsig( B1 + LW1 * xn );</p><p>ya=(yn+1)*(t2max-t2min)/2+t2min</p><p>t2=target, t2max=maximum of t2, t2min=minimum of t2;</p>Jasraj Purohithttps://fr.mathworks.com/matlabcentral/profile/authors/7705541-jasraj-purohittag:fr.mathworks.com,2005:Question/3320252017-03-26T19:27:04Z2017-03-26T20:19:11ZHow do I find the x values at the point of intercept between two quadratic functions numerically?<p>I have two quadratic equations, and need to find the points of intercept x1 and x2. Any tips would be great</p>V -https://fr.mathworks.com/matlabcentral/profile/authors/10024478-vtag:fr.mathworks.com,2005:Question/3132862016-11-21T05:00:00Z2017-03-26T20:14:19ZWhy do I see a "java.util.zip.ZipException" error in my installer log file when I try to install the MinGW support package?<p>When installing the MinGW Support Package, I see the following error:</p><p>There was a problem installing the third-party software. To resolve this issue, contact Technical Support</p><p>I also see the following inside of my MATLAB installer log file:</p><p>java.util.zip.ZipException</p><p>How can I proceed with installing this Support Package?</p><p> </p>MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:fr.mathworks.com,2005:Question/3317252017-03-24T12:03:31Z2017-03-26T20:11:17ZIs it possible to give the axes in a 3d plot a name/variables ?<p>I want to make a 2d plot in 3d. I´ve got an emg-signal of different muscles. Now i want to add on the z-axe my specific muscles like pecotralis, triceps etc. and on the x-axe the percent and on the y-axe the height of the emg-signal in µV. Is there any option to add on the z-axe the muscles and not only numbers.I tried to make a simple picture with paint.</p><img src = "/matlabcentral/answers/uploaded_files/73278/EMg-signal-test.jpg">Jakob Whttps://fr.mathworks.com/matlabcentral/profile/authors/9878719-jakob-wtag:fr.mathworks.com,2005:Question/3320282017-03-26T20:00:57Z2017-03-26T20:00:57Zhow to plot cdfplot with different line style?<p>Hi all,</p><p>I am trying to compare observed streamflow versus simulated (coming from two models) data for the calibration and validation period. I need to assign a different line style and color to each set of data but should be consistent in both subplots.</p><p>I have written down this code but can't get the line style out of it (here is some random data)</p><pre> Xobc=randn(1000,1);X1=randn(1000,1)+10; X2=randn(1000,1)*5;
Xobv=randn(500,1)*5; X3=randn(500,1)+2; X4=randn(500,1)*3;
figure
subplot(2,1,1);
hold on
cdfplot(Xobc); %Observed
cdfplot(X1); % Model-1
cdfplot(X2); % Model-2
set(gca, 'ylim', [0, 1.1])
title('Calibration')</pre><pre> subplot(2,1,2);
hold on
cdfplot(Xobv); %Observed
cdfplot(X3); % Model-1
cdfplot(X4); % Model-2
set(gca, 'ylim', [0, 1.1])
title('Validation')
xlabel('Streamflow (m^3/Sec)');
legend('Observed Streamflow','Model-1','Model-2');</pre><img src = "/matlabcentral/answers/uploaded_files/73449/cdfplot.jpg"><p>I attached, my original data set plot as well. What would one get from the CDFplot at first place?? Is this a good comparison aside from the daily hydrographs? Any thoughts would be appreciated.</p>Hydrohttps://fr.mathworks.com/matlabcentral/profile/authors/5628601-hydrotag:fr.mathworks.com,2005:Question/3320072017-03-26T16:47:32Z2017-03-26T19:54:43ZHow to transform this 2D animation into 3D?<p>I made this 2D animation of a projectile motion using the method of ode45:</p><pre class="language-matlab">clc
clear all
v0=input('Set the value of the initial speed: ');
A=input('Set the value of the angle: ');
rad=A*pi/180;
Vy=v0*sin(rad);
</pre><pre class="language-matlab">syms l
g = 9.80665;
Y=(Vy*l)-(g/2*(l^2));
T=solve(Y,l);
</pre><pre class="language-matlab">options=odeset('Maxstep',1e-9,'RelTol',1e-6);
edo=@(t,w)equationOfState(t,w,v0,A);
[t,w] = ode45(edo,[0:1e-2:double(T(2))], [0 Vy 0],'options');
</pre><pre class="language-matlab">xlabel('X'), ylabel('Y'), title('Projectile motion')
comet(w(:,3),w(:,1))
</pre><p>And this function:</p><pre class="language-matlab">function f= equationOfState(t,w,v0,A)
G=9.80665;
f= [w(2);
-G;
v0*cos(A)];
end
</pre><p>I need to transform the animation of this projectile motion into a 3D animation. What's the best way to do it? Thanks for your help.</p>Grishttps://fr.mathworks.com/matlabcentral/profile/authors/8563674-gristag:fr.mathworks.com,2005:Question/3317802017-03-24T17:21:19Z2017-03-26T19:50:10ZIs it possible to call a live script matlab file from another one?<p>Is it possible to call a live script matlab file from another one? Thank you.</p>Vahidoohttps://fr.mathworks.com/matlabcentral/profile/authors/9329193-vahidootag:fr.mathworks.com,2005:Question/3320272017-03-26T19:49:00Z2017-03-26T19:49:00Zarxml importer error due to data reference type(pointer type)<p>Hi everyone,
It is about import arxml file with data reference type with matlab 2015b and AUTOSAR 4.03.
I want to using data reference method to create a pointer type named ptrPuffer,pointing to uint8.
There are 2 options using data reference method in Davinci Developer to create pointer.
Option 1: if the pointer is referencing to unit8 type, then during importing the arxml in matlab, following error occurs: "use unsupported category DATA REFERENCE"
Option 2: if the pointer is referencing to void type, then matlab shows "invalid data type specification ".</p><p>Has someone the experience to import pointer type from Davinci Developer to matlab?
Regards,
Kelvin</p>Kehttps://fr.mathworks.com/matlabcentral/profile/authors/2879046-ketag:fr.mathworks.com,2005:Question/3319832017-03-26T14:10:49Z2017-03-26T19:36:41ZHow to get diagonal elements of non-square matrix?<p>Hi, guys!</p><p>I am working with rectangular matrixes and I want to extract the values that go from the upper left corner to lower right (diagonal). I have tried to write some codes, but they don't give me good results (it actually gets worst as the matrix gets "more rectangular"). Does anyone have an ideia?</p><p>Thank you,</p><p>Carolina Magalhães</p>turningpointhttps://fr.mathworks.com/matlabcentral/profile/authors/6642945-turningpointtag:fr.mathworks.com,2005:Question/2969992016-07-25T03:03:21Z2017-03-26T19:25:41ZlibGL error unable to load driver in Ubuntu 16.04 while running Matlab R2013b<p>I was trying to run a m-file on R2013b in Ubuntu 16.04. But i got the error and Matlab just hung:</p><pre class="language-matlab">libGL error: unable to load driver: r600_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: r600
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
</pre><p>The m-file tries to draw 3D plots of point clouds after reading ply files and processing them. My Matlab IDE completely froze and i had to use xkill to close it as nothing else worked.</p><p>The same code works normally in Windows without any extra configuration. By adding breakpoints and running one by one line, i found that the Matlab's plot3() function is giving trouble. I have previously done 2D plots using plot() function and it worked seamlessly in Ubuntu matlab. Both the files r600_dri.so and swrast_dri.so are in /usr/lib/x86_64-linux-gnu/dri.</p><p>What is the purpose of these shared object files? Why plot() does not give error and plot3() does? What does libGL error mean? And how to resolve it?</p><p>There are other places that try to address similar problems but they are in different context and difficult for me to extrapolate for my purposes. I would like an answer specific to my problem.</p><p>Most unexpectedly, i have also noted that this problem does not happen in R2016a because MATLAB selects its own graphics rendering engine as software opengl and sets it up automatically for its purpose.</p>ingstalamhttps://fr.mathworks.com/matlabcentral/profile/authors/5813143-ingstalamtag:fr.mathworks.com,2005:Question/3320242017-03-26T19:18:30Z2017-03-26T19:18:30Zconflict with Turbotax downloads for Mac using the .mdlp extension<p>Turbotax downloads for Mac use the .mdlp extension. When I try and open/install the Turbotax download it of course instead opens MATLAB. How can I get around this? Also tell Turbotax to use an approved extension, not yours. I see on www.file-extensions.org that mdlp is registered to MATLAB, not Turbotax. Turbotax support is mostly clueless.</p>Louis Derryhttps://fr.mathworks.com/matlabcentral/profile/authors/926408-louis-derrytag:fr.mathworks.com,2005:Question/3319962017-03-26T15:14:28Z2017-03-26T19:15:08ZHow to create a graph without knowing the data points?<p>Hi</p><p>I am trying to create the following graph (exponential when service level goes to 100%) in Matlab (see attached) but can't seem to make it work as I have no data points (function) given.</p><p>Note: 'safety stock requirements' is the label of the y-axis.</p><p>How can I do this?</p><p>Thanks a lot in advance! I really appreciate it!</p>Pieter Cecathttps://fr.mathworks.com/matlabcentral/profile/authors/9982698-pieter-cecattag:fr.mathworks.com,2005:Question/3233112017-02-04T03:58:35Z2017-03-26T19:10:50ZHow to make a connection between a key word and a binary digit?<p>I have a text 'mail.txt' and I chose a key word 'good'which is repeated 10 times in the text,I have
generated a random binary number consists of 10 digits 0100111011 ,the first occurrence of the word 'good'
meets the first digit'0' the second occurrence meets digit'1' and so on,How to achieve this and also to say if the
the digit is '1' replace 'good'with 'bad' ,else no changes,can I have your help please.</p>jojototohttps://fr.mathworks.com/matlabcentral/profile/authors/7097192-jojotototag:fr.mathworks.com,2005:Question/3320232017-03-26T19:10:25Z2017-03-26T19:10:25ZAnyone know how to add 2 simscape source blocks together? I am trying to add a fluid source with and air source to introduce air into a fluid line.<p>I am trying to model a fluid systems with air introduced into the systems. I then want to measure the air in the system but need to know how to add air from a reservoir to fluid from a separate reservoir.</p>Gary Herringtonhttps://fr.mathworks.com/matlabcentral/profile/authors/7753210-gary-herringtontag:fr.mathworks.com,2005:Question/3320222017-03-26T18:57:49Z2017-03-26T18:57:49ZHow to find peak coordinates of a signal within a specific range?<p>The code below is of two signals. I am trying to take the peak/max value of "signal_1", then create a range: <b>(max_value_x_component - 0.1e+9)</b> to <b>(max_value_x_component + 0.1e+9)</b>.</p><p>Then for signal_5 I want to find the x and y coordinates of the peak/max value between the rang: <b>(max_value_x_component - 0.1e+9)</b> to <b>(max_value_x_component + 0.1e+9)</b>.</p><p>I am looking to run this in a loop, so I need to actually find the peak values within the range through coding and not just by looking at a graph.</p><p>The code below will produce two figures with two graphs on each figure as seen in image 1 below. The graph that I am interested in analyzing is the second two graphs labeled "Graph of signal Fourier Transform". When looking at the graph you only see two large peaks/spikes one on the left near the origin and one on the far right. You need zoom into the left peak to see the waveform being analyzed as seen in image 2 below.</p><pre> h = 1.00E-12;
t = 0:h:40E-9;
A = 1;
A2 = 1.1111111;
A3 = 2.2222222;
A4 = 10;
A5 = 20;
f=3E9;
nfft = 2^(nextpow2(length(t))+5);</pre><pre> %Graphed signal_1
signal = cos(2*pi*f*t).*(A.*(heaviside(t)-heaviside(t-39E-9)));
snrdB = 0;
noise = 10^(-snrdB/20)*randn(size(signal));
sn = noise+signal;
y1 = fft(sn,nfft);
m1 = abs(y1);
er1 = (0:length(y1)-1)*(1/h)/length(y1);
figure (1)
subplot(2,1,1)
plot(t,sn)
title('Graph of signal_1')
xlabel('Time') % x-axis label
ylabel('Amplitude') % y-axis label
subplot(2,1,2)
plot(er1,m1)
grid on
title('Graph of signal_1 Fourier Transform')
xlabel('Frequency') % x-axis label
ylabel('Amplitude') % y-axis label</pre><pre> %Graphed signal_5
signal_5 = [cos(2*pi*f*t).*(A5.*(heaviside(t)-heaviside(t-1E-9)))]+[cos(2*pi*f*t).*(A5.*(heaviside(t-4E-9)-heaviside(t-5E-9)))];
snrdB = 0;
noise = 10^(-snrdB/20)*randn(size(signal_5));
s5n = noise+signal_5;
y5 = fft(s5n,nfft);
m5 = abs(y5);
er5 = (0:length(y5)-1)*(1/h)/length(y5);
indexmax = find(max(m5) == m5)
xmax = er5(indexmax)
ymax = m5(indexmax)
figure (5)
subplot(2,1,1)
plot(t,s5n)
title('Graph of signal_5')
xlabel('Time') % x-axis label
ylabel('Amplitude') % y-axis label
subplot(2,1,2)
plot(er5,m5)
grid on
title('Graph of signal_5 Fourier Transform')
xlabel('Frequency') % x-axis label
ylabel('Amplitude') % y-axis label</pre><img src = "/matlabcentral/answers/uploaded_files/73440/Capture.JPG"><p>Image 1. This is the figure that will be produced.</p><img src = "/matlabcentral/answers/uploaded_files/73441/Capture.JPG"><p>Image 2. This is the zoomed in waveform for the Four Transform graph of signal 3.</p>Anonymous45https://fr.mathworks.com/matlabcentral/profile/authors/9945585-anonymous45tag:fr.mathworks.com,2005:Question/3319742017-03-26T12:47:49Z2017-03-26T18:50:50ZPlease help me to find the equations of the following data.<pre class="language-matlab">x=[0 10 20 30 40 50 60];
y1=[.30 .50 1.40 1.60 2.60 2.90 3.35];
y2=[.68 .94 1.53 1.9 2.78 3.0 3.5];
y3=[1.029 1.34 2.36 2.81 3.7 3.9 4.7];
</pre><p>3 different equations required.</p>Sajal Khandelwalhttps://fr.mathworks.com/matlabcentral/profile/authors/10022337-sajal-khandelwaltag:fr.mathworks.com,2005:Question/3320212017-03-26T18:49:25Z2017-03-26T18:49:25ZMatrix gradient with non-rectangular surface data<p>Hi all,
I'm Brazilian and my English is not the best, but I'll try to explain my problem.</p><p>I have an irregular matrix because of the shape of the discrete function being in "T", and wanted to construct an algorithm that would determine the gradient of my discrete function through the finite differences in x and y.</p><p>I know there is a file already created with the name "gradient" that approximates the first derivative for rectangular arrays of discrete values. What if the array is of the type that is attached? Is it possible through matlab?</p><p>Thank you in advance</p>Joy Cravehttps://fr.mathworks.com/matlabcentral/profile/authors/10024059-joy-cravetag:fr.mathworks.com,2005:Question/3320162017-03-26T17:45:57Z2017-03-26T18:46:56Zerror ode arguments (line 92) <p>Hello, so I was practicing the shooting method using this script:</p><pre class="language-matlab">function Shooting_Con
option=odeset('RelTol',1e-3)
s=-200:20:200
s0=[]
ncase=length(s)
b=zeros(1,ncase)
for i=1:ncase
[z,c]=ode23s(@mandela,[0 0.001],[0.2 s(i)],option)
%zrange= 0 to 0.001
[m,n]=size(c)
b(1,i)=c(m,2)
end
y0=interp1(b,s,0)
global k Dab
k=.001
Dab=(1.2e-9)
L=.001
x=L*sqrt(k/Dab)
</pre><pre class="language-matlab">[z c]=ode45(@mandela,[0 0.001],[0.2 y0],option)
C=0.2*(cosh(x*(1-z/L))/cosh(x))
plot(z,C,'r',z,c(:,1),'ko')
legend('Exact','Differential')
xlabel('z')
ylabel('Concentration')
grid on
function dCadz=mandela(z,c)
global k Dab
dCadz=[c(2);((k/Dab)*c(1))]
</pre><p>but when I run it, it returns these errors:
Error using odearguments (line 92)
MANDELA returns a vector of length 1, but the length of initial conditions vector is 2. The
vector returned by MANDELA and the initial conditions vector must have the same number of
elements.</p><p>Error in ode23s (line 121)
= odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);</p><p>Error in class_0323 (line 8)
[z,c]=ode23s(@mandela,[0 0.001],[0.2 s(i)],option)
but I have two things in my dCadz function so I don't understand why I am only getting back 1 value when there are two things. :/
I need some serious help.</p>Marlon Brutushttps://fr.mathworks.com/matlabcentral/profile/authors/6855423-marlon-brutustag:fr.mathworks.com,2005:Question/3320202017-03-26T18:44:22Z2017-03-26T19:51:07Zhow do i rectify the error that i have got while performing the kmeans clustering <p>color based segmentation using kmeans clustering
how do i use 'start' key word in kmeans..i have tried a code but it gives an error it must have k rows how to solve it
the code i tried is here</p><pre class="language-matlab">[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates', 4, 'start',seeds);
</pre><pre class="language-matlab">rng(123); %// Set seed for reproducibility
numReplicates = 4;
ind = randperm(size(ab,1),numReplicates*nColors);
% ind=ind(1:numReplicates*nColors);
seeds = permute(reshape(ab(ind,:).', [2 nColors numReplicates]), [2 1 3]);
</pre><pre class="language-matlab">%// Now call kmeans
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates', numReplicates, 'start', seeds);
</pre>sudarshan rhttps://fr.mathworks.com/matlabcentral/profile/authors/9594552-sudarshan-rtag:fr.mathworks.com,2005:Question/3319862017-03-26T14:24:08Z2017-03-26T18:42:03ZAligning or justifying multiple text on same title line<p>Hi all,</p><p>I'm looking for a little help on a seemingly simple problem. I have a multiline title similar to this on a plot:</p><pre class="language-matlab">t = title({['\fontsize{14}','First Line Title']; ...
['\fontsize{12}','Second Line Title 1', ...
'Second Line Title 2','Second Line Title 3']}, ...
'FontWeight','Normal')
</pre><p>On the second line I have three pieces of text (Second Line Title 1-3). I'm exporting multiple plots, but the text changes for each plot I make. I'm wanting the alignment (justification) of each piece of text on the second line to remain constant regardless of number of characters so that there isn't a big swing in the justification of each piece of text. Hopefully this makes sense.</p><p>Does anyone have any suggestions on how to do this in MATLAB? Any thoughts or advice would be greatly appreciated!</p>John Crucehttps://fr.mathworks.com/matlabcentral/profile/authors/10022766-john-crucetag:fr.mathworks.com,2005:Question/3320192017-03-26T18:38:48Z2017-03-26T18:38:48ZHow to solve equations with possible values for variables?<p>I'm working in a simulation project, and there is a step that I'd like to solve using MATLAB. I'll explain a very simplified system, but still similar to the one in the project. It goes as following:
I have a set of 3 variables, and 4 conditions:</p><p>a1*4 + a2*3 + a3*1 = 6</p><p>a1 can be only 1 or 0</p><p>a2 can be only 1 or 0</p><p>a3 can be only 1 or 0</p><p>So, based on those restrictions, the only possible solution would be a1 = 1, a2 = 0, a3 = 1.
How can I write this in matlab, and get this answer?</p><p>Thanks!</p>Guilherme Magalhaeshttps://fr.mathworks.com/matlabcentral/profile/authors/9893900-guilherme-magalhaestag:fr.mathworks.com,2005:Question/3320172017-03-26T18:24:24Z2017-03-26T18:34:01Zwilcoxon test for two sample<p>hi everybody
Is it possible to do a signed rank wilcoxon test for two sample with different sizes ?</p><pre class="language-matlab">x=[331 308 300 414 253 323 452 396 104];
y=[248 393 260 355 279 184 386 450 432 196 197];
</pre><pre class="language-matlab">[p,h,stats] = signrank(x,y,'tail','right')
</pre><p>and error is : SIGNRANK requires the data vectors to have the same number of elements.
sorry if the answer is obvious!</p>farfarhttps://fr.mathworks.com/matlabcentral/profile/authors/7391310-farfartag:fr.mathworks.com,2005:Question/3319292017-03-26T01:41:44Z2017-03-26T18:32:11ZProblems with chosing the best optimization function<p>Hello there,</p><p>I'm trying MATLAB to help me with math optimization problems.
I know MATLAB has a lot of optimization fuctions to help me.
However, my first problem is to know wich one could help me better and easily.</p><p>Basically, I have this equation:</p><pre class="language-matlab">y=(k*x1*x2^0.75)/(2.8579*log((x1*1000)/(pi*dm));*
</pre><p>where k, pi and dm are predefined constants;
and x1 and x2 are my variables.</p><p>I need to find the maximum values for x1 and x2, so that y is as close as possible to 100.</p><p>Could someone help me with this problem?</p><p>Thanks in advance.</p><p>-Vinicius</p>Vinicius Almeidahttps://fr.mathworks.com/matlabcentral/profile/authors/10019848-vinicius-almeidatag:fr.mathworks.com,2005:Question/3320182017-03-26T18:31:39Z2017-03-26T18:31:39ZCounting the amount of steps taken by the sorting algorithm<p>Hi, I have a code that sorts the elements by their values as an Assignment, but I also need to specify the number of steps that were taken by the code.I searched everywhere and couldn't find any answers Could somebody help me? Here is the code:</p><pre class="language-matlab">if true
% code
end
X = [9 2 5 7 3 8 1 4 6 0 -2 -7];
n = length(X);
for i=1:n-1
A=X(i);
for j=i+1:n;
if X(j)>A;
A=X(j);
X(j)=X(i);
X(i)=A;
end
end
end
X
</pre><p>Thank you in advance:)</p>arfnhtylzhttps://fr.mathworks.com/matlabcentral/profile/authors/10024187-arfnhtylztag:fr.mathworks.com,2005:Question/3319452017-03-26T05:35:56Z2017-03-26T18:28:31ZUTF-8 strings in MEX-files<p>This question has been asked here before, but not with any satisfying answers. Since all those answers, a new documented function <a href = "https://www.mathworks.com/help/matlab/apiref/mxarraytoutf8string.html">mxArrayToUTF8String</a> has appeared. I'm hoping to find the function that does the reverse: make an mxArray from a UTF-8 encoded C or C++ string. I'm OK with an undocumented function, or using a bit of code from someone else. I'm not OK with linking some huge Unicode library, which I have no use for. All I need is convert UTF-8 to UTF-16 (which seems to be what MATLAB uses in their mxChar arrays).</p><p>Does anybody have any experience with UTF-8 encoded strings in MATLAB?</p><p>What does The MathWorks suggest we do if we want to work with UTF-8 encoded strings?</p>Cris Luengohttps://fr.mathworks.com/matlabcentral/profile/authors/210779-cris-luengotag:fr.mathworks.com,2005:Question/1849212015-03-24T15:52:38Z2017-03-26T18:23:25ZHow to Create Libraries in Matlab?<p>OK, I switch gears often between C, Matlab, and Python-so I am really a beginner in the Matlab world. Is there any way, in pure Matlab to create the equivalent of a library? I have several closely related functions that control a piece of hardware. The individual functions are relatively simple, so it seems asinine to have to put each one in a separate m-file. Is there a way I can group them all together? I guess this would be the equivalent of creating a toolbox, but what reading I've done seems to recommend against this approach. In the separate file sceneraio--does Matlab cache the functions in any way, or does the file have to be read from disk every time I call the function? It would seem this would introduce lots of latency.</p>Jimhttps://fr.mathworks.com/matlabcentral/profile/authors/5482502-jimtag:fr.mathworks.com,2005:Question/3320102017-03-26T17:17:08Z2017-03-26T18:13:44Zsolving non-linear equation <p>Hi</p><p>I am solving for x in this equation.</p><img src = "/matlabcentral/answers/uploaded_files/73432/zz.PNG"><p>where J1 is Bessel function of first kind order one. Below s my code, however i am notsure if this is the right way to solve an equation in matlab. can anyone please help me to check my code.</p><p>Thanks</p><pre class="language-matlab">clear all
syms x
</pre><pre class="language-matlab">b=371.05*10^-6;
</pre><pre class="language-matlab">num=sqrt(-8*b*abs(x));
den=sqrt(-2*b*abs(x));
</pre><pre class="language-matlab">eqn = 1.4*sqrt((besselj(1,num))/(den))==x;
</pre><pre class="language-matlab">solvx = solve(eqn,x);
vpa(solvx)
</pre>friethttps://fr.mathworks.com/matlabcentral/profile/authors/5876107-friettag:fr.mathworks.com,2005:Question/3315252017-03-23T14:10:38Z2017-03-26T18:09:41ZI got error : Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields.<p>I have used the following files and the error is :</p><p>Error using vertcat
Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have
the same set of fields.</p><p>Error in linearsyntax (line 16)
test=[test0;test1];</p>sam CPhttps://fr.mathworks.com/matlabcentral/profile/authors/8044262-sam-cptag:fr.mathworks.com,2005:Question/3314812017-03-23T10:02:24Z2017-03-26T18:09:09ZKnn code to compare two excel sheet<p>we are working on a power system on which we have to determine whether the failure of the power system is a fault or not a fault.
We have created a dataset with all possibilities of faults and not faults of the system called training set.
we have created another excel sheet called the training set in which we have taken some values of faults and not faults from the dataset.
We want to use knn algorithm and euclidean distance to compare/classify whether the readings in the training set are the values of faults or not faults when compared with the original dataset.
As we are putting four five values in the training set, how do we make matlab read and classify all the values one after the other without manually entering the values</p><p>P.S- 1 represents 'fault' and 2 represents 'not a fault' (in the AE column of the excel sheet)in the dataset excel sheet. After running knn algorithm we want 1 or 2 displayed on command line and written on training set.</p>Nana Fernandeshttps://fr.mathworks.com/matlabcentral/profile/authors/10002966-nana-fernandestag:fr.mathworks.com,2005:Question/3319922017-03-26T14:57:44Z2017-03-26T18:04:42ZHow can I install and run latest MATLAB setup on Ubuntu 16.04 with 3 GB RAM 1.9 GHz Clk speed<p>Request you to clear the cause of installing and running Latest MATLAB set up on 32 bit Ubuntu 16.04 OS with 32 GB RAM and 1.9 GHz Clk speed. Thanx and Regards</p>Rohit Kanshttps://fr.mathworks.com/matlabcentral/profile/authors/10022941-rohit-kanstag:fr.mathworks.com,2005:Question/3319942017-03-26T15:07:34Z2017-03-26T18:01:55ZOutput of isdst incorrect on for 26 March 2017<p>Hello,
The function isdst seems to say that 26 March 2017 London time does not occur during daylight saving time. The output is incorrect, 26 March 2017 (London time) occurs during Daylight Saving Time. The output for 27 March 2017 is correct.
Below is an example which illustrates the problem.</p><p>>> t = datetime(2017, 3, 26, 'TimeZone', 'Europe/London')</p><p>dt =</p><pre class="language-matlab">datetime
</pre><pre> 26-Mar-2017</pre><p>>> isdst(dt)</p><p>ans =</p><pre class="language-matlab">logical
</pre><pre> 0</pre>Florian Theilhttps://fr.mathworks.com/matlabcentral/profile/authors/1264106-florian-theiltag:fr.mathworks.com,2005:Question/3319972017-03-26T15:54:31Z2017-03-26T18:00:06ZCreate a main script (matlab) that asks the user which expression to show and then draws the appropriate face by calling functions for most of the data. The switch structure can be used as part of this (it can be found in your textbook). Hint: You w<p>Can anyone just solve this problem ? Help will be highly appreciated.</p>Bijaya Nepalhttps://fr.mathworks.com/matlabcentral/profile/authors/9573571-bijaya-nepaltag:fr.mathworks.com,2005:Question/3319952017-03-26T15:08:22Z2017-03-26T17:53:06Zi need to extend the polyfit line until intersect x-axis <p>this is my code ineed to make fitting line intersect x-axis how?</p><pre class="language-matlab">p=[2080 1885 1620 1205 888 645];
z=[0.759 0.767 0.787 0.828 0.866 0.900];
cum=[0 6.873 14.002 23.687 31.009 36.207];
r=p./z;
figure('color','b')
plot(cum,r,'k-.')
set(gca,'Color','y')
xlabel('cummulative production(MMM SCF)')
ylabel('P/Z(psig)')
title('Relation between compersibilty ratio and cumm production')
hold on
f=polyfit(cum,r,1);
k=polyval(f,cum);
plot(cum,k,'b')
</pre>ahmed ragaiehttps://fr.mathworks.com/matlabcentral/profile/authors/10022689-ahmed-ragaietag:fr.mathworks.com,2005:Question/3319732017-03-26T12:43:30Z2017-03-26T17:49:59ZMacOS: R2017a keeps asking "Allow incoming connections"<p>Running MacOS 10.12.3
On each invocation of Matlab R2017a, MacOS asks "Allow incoming connections, Allow / Deny". The answer doesn't get remembered for the next time I open Matlab. I have Matlab 2016a and 2017a installed side-by-side. The issue doesn't occur on MATLAB_R2016a, only on MATLAB_R2017a. I have worked around this by adding manually the file "/Applications/MATLAB_R2017a.app/Contents/MacOS/MATLAB" to the Firewall allowed list. I had to do this manually, as it wouldn't remember the setting from the prompt.</p>Noah Kanovskyhttps://fr.mathworks.com/matlabcentral/profile/authors/5501448-noah-kanovskytag:fr.mathworks.com,2005:Question/3320002017-03-26T16:05:37Z2017-03-26T17:45:52ZHow Can i write values in excel row by row??<p>can anyone tell me how am i supposed to write values to excel but in row by row manner i have 8 images and i have calculated the energy,entropy,dissimilarity,auto-corelation,contrast now i have stored them in a,b,c,d,e respectively
and then in x=[a b c d e] so i want to write these values row by row in cell.And they are different since i am processing 8 images from a folder.The code i have written writes only the last value 8 times row by row in the excel sheet. please i need urgent help..thanks in advance.</p><p>Code:</p><pre class="language-matlab">srcFiles = dir('C:\Users\sagar\Desktop\Abnormal\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\sagar\Desktop\Abnormal\',srcFiles(i).name);
I = imread(filename);
% figure, imshow(I);
</pre><pre class="language-matlab">t = rgb2gray(I);
w = adapthisteq(t);
GLCM2 = graycomatrix(w);
v = GLCM_Features1(GLCM2,0);
</pre><pre class="language-matlab">a = v.autoc
b = v.contr
c = v.dissi
d = v.energ
e = v.entro
</pre><pre class="language-matlab">x = [a b c d e]
</pre><pre class="language-matlab">offset = 1;
for a_iter = 1:8
</pre><pre class="language-matlab">xlswrite('newdata6.xls',x,1,sprintf('A%d',offset));
offset = offset + 1;
end
</pre><pre class="language-matlab">end
</pre>Sagar Sawanthttps://fr.mathworks.com/matlabcentral/profile/authors/9392638-sagar-sawanttag:fr.mathworks.com,2005:Question/3320152017-03-26T17:44:37Z2017-03-26T17:44:37ZMean Luminance - Units?<p>When finding the average luminance of an image (mean(rgb2gray(image))), in what units is the luminance value?</p>Gina D'Andrea-Pennahttps://fr.mathworks.com/matlabcentral/profile/authors/8564672-gina-d-andrea-pennatag:fr.mathworks.com,2005:Question/2467902015-10-05T04:28:31Z2017-03-26T17:40:23ZHow to classify brain tumor.<p>Hi, i am working on a project Brian tumor Segmentation and classification, i tried but didn't find a training Dataset for malignant and benign, please help me how to classify and which classifier is best for tumor classification, also if possible please provide me the link to download the Dataset for malignant and benign tumor.
Thanks</p>Muhammad Shoaibhttps://fr.mathworks.com/matlabcentral/profile/authors/6619683-muhammad-shoaibtag:fr.mathworks.com,2005:Question/3320132017-03-26T17:32:13Z2017-03-26T17:35:52Zfind doesn't work with tables<p>hello</p><p>I'm trying to find the index vector of where appears a value in a one column of a table (not an array nor a cell).</p><p>However, "find" gives me the error shown on the snapshot.</p><img src = "/matlabcentral/answers/uploaded_files/73436/error.png"><p>Any ideas</p>Abdelmoumen Bacettihttps://fr.mathworks.com/matlabcentral/profile/authors/2067162-abdelmoumen-bacettitag:fr.mathworks.com,2005:Question/3320122017-03-26T17:29:41Z2017-03-26T17:29:41ZHow can I change the slope of a polynomial, with a constraint between 2 points?<p>Hi,</p><p>I have a 3rd degree polynomial, shown as the blue curve below.</p><img src = "/matlabcentral/answers/uploaded_files/73433/untitled.jpg"><p>If 2 points are selected on this curve (with known x-axis coordinates), can I change the slope of the entire polynomial, so as to obtain a new desired slope (red dashed line) between the 2 points?</p><p>I have the polynomial equation, the x- and y- coordinates of the two red dots, and also have the slope of the dashed line. I can differentiate the polynomial but I'm not sure how to incorporate the slope of the dashed line.</p><p>I've been searching for possible ways to solve this and the closest example I found is the following code:</p><pre class="language-matlab">% Making some random data
Q1 = 0:0.01:1;
T = cos(2.1*pi*Q1)+0.2*randn(size(Q1));
figure
plot(Q1,T,'k.');
% Polyfit without constraints
order = 4;
C1 = polyfit(Q1,T,order);
%
hold on;
plot(Q1,polyval(C1,Q1))
V = bsxfun(@power,Q1(:),order:-1:0); % Make Vandermonde Matrix
% Make Constraints on the derivatives
Aleft = [(order:-1:1).*Q1(1).^(order-1:-1:0) 0];
Aright = [(order:-1:1).*Q1(end).^(order-1:-1:0) 0];
Aeq = [Aleft; Aright];
beq = [0;0]; %Value of the derivative is set to zero
% Call LSQLIN with options to prevent warnings
opts = optimset('lsqlin');
opts.LargeScale = 'off';
C2 = lsqlin(V,T,[],[],Aeq,beq,[],[],[],opts);
plot(Q1,polyval(C2,Q1),'r')
hold off;
legend({'Data' 'Polyfit' 'Constrained Polyfit'},'location','best');
</pre><p>The code changes the slope of the polynomial at particular points, but instead, I'd like to change the relative slope between the 2 points.</p><p>Please help...many thanks!</p>Mikehttps://fr.mathworks.com/matlabcentral/profile/authors/3295680-mike