http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-12-08T06:45:49Ztag:www.mathworks.com,2005:Question/3159022016-12-07T23:53:51Z2016-12-08T06:45:49ZWhat is the problem with my noise removal function?<p>I am just trying to make an example to go off of to clean up gaussian noise from a picture without using the built in functions. My function should be replacing all the numbers not on the edges of my 6x6 matrix but it is only replacing the the (2,2) number. What am I doing wrong?</p><pre> a = [1 2 3 4 5 6; 1 2 3 5 7 6; 3 4 5 6 7 8; 4 5 6 7 8 9; 1 2 3 1 2 3; 1 4 5 6 7 8];
kernel = (1/16).*[1 2 1;2 4 2;1 2 1];
[row,col]= size(a);
ii= 1; jj= 3; mm= 1; kk= 3; tt= 2; yy= 2;
for row = a(ii:jj)
for col = a(mm:kk)
result = a(ii:jj,mm:kk).* kernel;
b= mean2(result);
a(tt,yy)= b;
mm= mm+1; kk= kk+1; tt= tt+1;
if kk> col
break;
end
end
ii= ii+1; jj= jj+1; yy= yy+1;
if jj> row
break;
end
end</pre>Jake Konneskyhttp://www.mathworks.com/matlabcentral/profile/authors/8615307-jake-konneskytag:www.mathworks.com,2005:Question/3159292016-12-08T05:51:57Z2016-12-08T06:40:37ZHow to get the gray level co-occurrence matrix feature which is energy, entropy and contrast of the image using GUI? <p>I want to create the GUI that can extract the gray gray level co-occurrence matrix feature which is energy, entropy and contrast of the image(bitmap). How to get that feature?</p>Muhammad Harith Ramlihttp://www.mathworks.com/matlabcentral/profile/authors/8940052-muhammad-harith-ramlitag:www.mathworks.com,2005:Question/3159382016-12-08T06:39:45Z2016-12-08T06:39:45ZMATLAB Command for finding Expected Value<p>for finding the co-variance matrix of a matrix containing 12 columns suppose[x1x2,x3---x12], i need to find the individual co-variances, which i am finding by Expectation formula given bellow:</p><img src = "/matlabcentral/answers/uploaded_files/65005/cov%20expected.PNG"><p>is there any MATLAB command to find right hand side? any command for Expectation?</p>Waseem Ullahhttp://www.mathworks.com/matlabcentral/profile/authors/9336770-waseem-ullahtag:www.mathworks.com,2005:Question/3158592016-12-07T18:22:36Z2016-12-08T06:39:00Z I would like to know the algorithm to compress a txt <p>I need a program that can compress a .txt file with saved and another that can unzip the file being compressed</p>lina sevillahttp://www.mathworks.com/matlabcentral/profile/authors/9334121-lina-sevillatag:www.mathworks.com,2005:Question/3159322016-12-08T06:09:38Z2016-12-08T06:38:12Zi have b1=00000001 and b2=00001010 now i want this 8 digit binary code in matrix form b1= 0000 first raw & 0001 second raw 2*4 size matrix from binary digit number<p>8 digit binary to 4 digit group and make matrix from it
b1= 0 0 0 0(first raw)
0 0 0 1(second raw)
b2= 0 0 0 0
1 0 1 0
2*4 size matrix</p>Pratik Anandparahttp://www.mathworks.com/matlabcentral/profile/authors/9212467-pratik-anandparatag:www.mathworks.com,2005:Question/3159372016-12-08T06:36:56Z2016-12-08T06:36:56ZmxCreateStructArray and mxCreateStructMatrix field name memory management<p>I've been trying to find documentation on how the field names are managed with the structure creating functions in mex. Are the field name character arrays copied before being stored internally. Do the character array pointers need to point to the first character of Matlab managed memory (e.g. initialized via mxMalloc)? The only example I could find online was the phonebook.c, which took the string from another Matlab managed variable.</p>Jim Hokansonhttp://www.mathworks.com/matlabcentral/profile/authors/937359-jim-hokansontag:www.mathworks.com,2005:Question/3106082016-11-04T10:26:52Z2016-12-08T06:34:14ZFor solving Model equations and to implement control which one is better either Simulink or script file ?<p>Suppose to implement controllers like PID, MPC, Fuzzy Controllers.</p>PUJARI MURAGAhttp://www.mathworks.com/matlabcentral/profile/authors/7846398-pujari-muragatag:www.mathworks.com,2005:Question/3159362016-12-08T06:31:23Z2016-12-08T06:31:23ZProblem with the executables created with MATLAB compiler<p>Hi,</p><p>I have created an executable from the MATLAB compiler. But the results that I get from running directly from the MATLAB console and from the executables are not the same. The system goes into an infinite loop when I try the executables.</p>Thangamani Veeramanihttp://www.mathworks.com/matlabcentral/profile/authors/9336781-thangamani-veeramanitag:www.mathworks.com,2005:Question/3158722016-12-07T19:58:43Z2016-12-08T06:25:36ZHow can I use wcodemat to re-scale an intensity/gray-scale image?<p>I want to change my original intensity/gray-scale image into wcodemat for wavelet transform but problem is if i use</p><p>Y = wcodemat(X)</p><p>the image just turn into different shades of blue and this doesn't represent the original image(which is black and grey), I also cannot use</p><p>Y = wcodemat(X,NBCODES), because my image doesn't have map which is required for the NBCODES parameter.</p><p>How can I resolve this problem?</p>Subhahttp://www.mathworks.com/matlabcentral/profile/authors/7390034-subhatag:www.mathworks.com,2005:Question/3159332016-12-08T06:16:18Z2016-12-08T06:20:17ZI ran a set of codes that I recently found in a text book. It supposed to give me a graph but I'm getting an empty one instead. <p>I ran these codes in Matlab 2012. Since the code is made available to the public, they should be correct. But I'm getting an empty graph with an error message
"Error using ~= Matrix dimensions must agree.
Error in Dirty_or_TH_precoding (line 59)
N_ebits = N_ebits + sum(msg_bit~=demapped);"</p><p>These are the codes:-</p><p>clear all; clf
mode = 0; % Set to 0/1 for Dirty/TH precoding
N_frame=10; % Number of frames in a packet, 1 frame=4 symbols
N_packet=200; % Number of packets
b=2; % Number of bits per QPSK symbol
NT=4; N_user=10; N_act_user=4; I=eye(N_act_user,NT);
N_pbits =N_frame*NT*b; % Number of bits in a packet
N_tbits = N_pbits*N_packet; % Number of total bits
SNRdBs=[0:2:20]; sq2=sqrt(2);
for i_SNR=1:length(SNRdBs)
SNRdB = SNRdBs(i_SNR); N_ebits = 0;
%rand('seed',1); randn('seed',1);
sigma2 = NT*0.5*10^(-SNRdB/10); sigma = sqrt(sigma2);
%------------- Transmitter ----------------
for i_packet=1:N_packet
msg_bit = randi(1,N_pbits); % Bit generation
symbol = QPSK_mapper(msg_bit).';
x = reshape(symbol,NT,N_frame);
H = (randn(N_user,NT)+j*randn(N_user,NT))/sq2;
%----- user selection ----------
Combinations = nchoosek([1:N_user],N_act_user)';
for i=1:size(Combinations,2)
H_used = H(Combinations(:,i),:);
[Q_temp, R_temp] = qr(H_used);
%diagonal entries of R_temp are real
minimum_l(i) = min(diag(R_temp));
end
[max_min_l,Index] = max(minimum_l);
H_used = H(Combinations(:,Index),:);
[Q_temp,R_temp] = qr(H_used');
L=R_temp'; Q=Q_temp';
xp = x;
if mode==0 % Dirty precoding
for m=2:4
xp(m,:) = xp(m,:) - L(m,1:m-1)/L(m,m)*xp(1:m-1,:);
end
else % TH precoding
for m=2:4
xp(m,:) = modulo(xp(m,:)-L(m,1:m-1)/L(m,m)*xp(1:m-1,:),sq2);
end
end
Tx_signal = Q'*xp; % DPC/TH encoder
%------------ Channel and Noise ----------------
Rx_signal = H_used*Tx_signal + ...
sigma*(randn(N_act_user,N_frame)+1i*randn(N_act_user,N_frame));
%------------ Receiver ----------------
y = inv(diag(diag(L)))*Rx_signal;
symbol_hat = reshape(y,NT*N_frame,1);
if mode==1 % in the case of TH precoding
symbol_hat = modulo(symbol_hat,sq2);
end
symbol_sliced = QPSK_slicer(symbol_hat);
demapped = QPSK_demapper(symbol_sliced);
N_ebits = N_ebits + sum(msg_bit~=demapped);
end
BER(i_SNR) = N_ebits/N_tbits;
end
semilogy(SNRdBs,BER,'-x'), grid on</p>Vishnudaya Dayalamhttp://www.mathworks.com/matlabcentral/profile/authors/9333193-vishnudaya-dayalamtag:www.mathworks.com,2005:Question/3159352016-12-08T06:19:07Z2016-12-08T06:19:50ZHow can I make these separate for loops into a nested for loop together?<pre> clc, clear
A = [1:11; 2:12; 3:13; 4:14; 5:15; 6:16; 7:17 ]
[M N] = size(A);</pre><pre class="language-matlab">for i = 1:M
Ax = [A(i, N - 5 + 1:N) A(i, 1:N - 5)];
Ax(1,(1:5)) = 0;
k(i,:) = Ax;
end
</pre><pre class="language-matlab">for j = 1:N
Ay = [k(1+2:M,j);
k(1:2,j)];
Ay(end-1:end) = 0;
k(:,j) = Ay;
end
</pre><pre> k</pre>Muhamed Polovinahttp://www.mathworks.com/matlabcentral/profile/authors/7686304-muhamed-polovinatag:www.mathworks.com,2005:Question/3159342016-12-08T06:17:49Z2016-12-08T06:17:49ZUsing Interrupt pin on Arduino<p>Hi, I need to record number of revolutions using hall effect switches. I'm using Matlab to control the Arduino board. I've never used Simulink and don't want to start now since I've coded everything else for this project in Matlab.</p><p>Ideally I'd like to use the interrupt pins on the Arduino, but can't find the appropriate Matlab code online.</p><p>If there is another way I'm open to suggestions, as long as it isn't using Simulink.</p><p>Can someone please help me?</p><p>Thank you!!</p>Carl-Michaelhttp://www.mathworks.com/matlabcentral/profile/authors/8680645-carl-michaeltag:www.mathworks.com,2005:Question/1960882015-04-04T14:24:32Z2016-12-08T06:07:06ZNeural networks - How to use different datasets for training, validation and testing?<p>Best</p><p>I've a question about Neural networks in Matlab.</p><p>First of all, I've a small NN, 2 inputs, 1 hidden layer with 10 neurons and one output. And this works fine. But the question which I've is. Can I determine my training date, validation data and test data?</p><p>I know, if I use e.g. net = feedforwardnet(10); that I can divide my overall dataset into e.g.70/100 15/100 and 15/100. But I don't want to do this, because in this case I want to train my NN with a 1000 data-points, validate them with another 1000 data-points and use another independent data-set of 1000 data-points to test them. With other words, I want to control these 3 interdependent data-sets.</p><p>Thus, can someone help me?</p><p>Kind regards</p><p>Edit, I don't want to use a data-set with 3000 data-points and set the devideParams on 1/3 1/3 & 1/3.</p>Dieter Verbeemenhttp://www.mathworks.com/matlabcentral/profile/authors/6368797-dieter-verbeementag:www.mathworks.com,2005:Question/3159312016-12-08T06:04:56Z2016-12-08T06:04:56ZSimulation of common source circuit.<p>I want to simulate common source circuit in Simulink.
But I think the waveform shown in scope seems not enough accurate.
Could you tell me how to change the accuracy(simulation step?).</p><p>I attached model.mdl</p>Taishi Sawauchihttp://www.mathworks.com/matlabcentral/profile/authors/7985621-taishi-sawauchitag:www.mathworks.com,2005:Question/689382013-03-28T10:40:18Z2016-12-08T06:03:54ZHow can I save individual movie frames from a video?<p>I want to save individual frames of my video--how can I do this?</p><p>I tried the code below but it is not working...</p><pre class="language-matlab">clc
close all
clear all
</pre><pre class="language-matlab">source='Intellegent.avi';
</pre><pre class="language-matlab">vidobj=VideoReader(source);
</pre><pre class="language-matlab">frames=vidobj.Numberofframes;
</pre><pre class="language-matlab">for f=1:frames
thisframe=read(vidobj,f);
figure(1);imagesc(thisframe);
for K=1:size(thisframe,3)
itframe=thisframe(:,:,K);
thisfile = sprintf('frame_%04d.jpg', K);
imwrite( thisframe, thisfile );
end
end
</pre>Algorithms Analysthttp://www.mathworks.com/matlabcentral/profile/authors/3698936-algorithms-analysttag:www.mathworks.com,2005:Question/3159262016-12-08T05:31:32Z2016-12-08T06:02:29ZHow to plot cylindrical object boundary using MATLAB<p>Hello! Everyone,
I have Object placed inside a box and i used distance sensors to get the distance of the object from a reference point (0,0,0), now i want to plot the surface of this object using MATLAB, but i am confused, which plotting function to use.</p><p>Suppose the object placed is cylindrical object as shown below.</p><img src = "/matlabcentral/answers/uploaded_files/64989/Image.png"><p>These are the valid points which i get from the sensor from point (0,0,0) and all of these points are same across the z-axis</p><p>x = (89.26772163,89.2251516,89.17737906,89.05573047,
88.8611554,88.59463961,88.2572044,87.84990611,
90.60990337,93.38333305,96.16835842,98.96312702,
101.7657715,104.5744107,107.4709263)</p><p>y = (86.20483673,83.20379993,80.29567276,77.41496542,
74.56336272,71.74252458,68.95408524,66.19965255,
65.83194826,65.38771374,64.8663768,64.26740613,
63.59031171,62.83464514,62.04836823)</p><p>Which plot should i use to get the one side boundary using MATLAB as follow:</p><img src = "/matlabcentral/answers/uploaded_files/64999/Output.png"><p>With the points above, it is not possible to draw the complete image, but at-least it is possible to draw the boundary of the front side.
Please suggest which type of plot, surface plot i can use.</p>Arun Sharmahttp://www.mathworks.com/matlabcentral/profile/authors/1852015-arun-sharmatag:www.mathworks.com,2005:Question/222872011-11-26T00:21:28Z2016-12-08T06:02:23ZNeed help on FCM clustering <p>Is any one knows how to create 5 clusters by using FCM please. I've number of samples across number of genes, I need to cluster them into 5 clusters but I couldn't figure this out in matlab.</p>Aiman Almazroeyhttp://www.mathworks.com/matlabcentral/profile/authors/1126723-aiman-almazroeytag:www.mathworks.com,2005:Question/3158672016-12-07T18:56:47Z2016-12-08T06:00:30ZHow to add matlab functions that i have used in my guide when compiling?<p>I have finished with my gui and after compiling some parts of the gui work and other not. on you tube i have been told i have to integrate matlab functions files used in the gui when compiling but i dont know how to get these files. please help me. am using the 2013 version.</p>demeveng derrickhttp://www.mathworks.com/matlabcentral/profile/authors/8816901-demeveng-derricktag:www.mathworks.com,2005:Question/3159282016-12-08T05:50:58Z2016-12-08T06:00:27Zhow to eliminate white pixels(smoke pixels) in the rgb image<p>how to eliminate white pixels(smoke pixels) in the rgb image</p>senthil vadivuhttp://www.mathworks.com/matlabcentral/profile/authors/5134667-senthil-vadivutag:www.mathworks.com,2005:Question/3159302016-12-08T05:55:02Z2016-12-08T05:55:02Z AUTO CLUSTERING instead of setting the value of 'C' in Fuzzy C-Mean<p>I have a problem in FCM. i want it to be AUTO CLUSTERING instead of setting the value of 'C'?.
This is a normal FCM code that need manually set the C:
options = [NaN 100 0.001 0];
[centers,U,objFun] = fcm(data,3,options);</p>nur shidah ahmadhttp://www.mathworks.com/matlabcentral/profile/authors/7062368-nur-shidah-ahmadtag:www.mathworks.com,2005:Question/3159212016-12-08T05:18:52Z2016-12-08T05:44:25ZCan't acces existing struct<p>Hi, I'm learning some about matlab. By now i'm trying to get the fields names by code with fieldnames(), but trying to fix it with Material.(s) by now.</p><p>This is a part of my code with the problem:</p><pre class="language-matlab">Material.Acero.Cuadrado.C_15x15=[1 1.5] %Creates the struct
Material.Acero.Cuadrado.C_15x15 %Just to verify it's existence
s=strjoin(t,'.') %Develop in another part of the code and returns for example 'Acero.Cuadrado'
class(s) %Just for check
size(s) %Just for check
Material.(s)
</pre><p>And returns the following:</p><pre class="language-matlab">Material =
Acero: [1x1 struct]
ans =
1.0000 1.5000
</pre><pre class="language-matlab">s =
Acero.Cuadrado.C_15x15
</pre><pre class="language-matlab">ans =
char
</pre><pre class="language-matlab">ans =
1 22
</pre><pre class="language-matlab">Reference to non-existent field 'Acero.Cuadrado.C_15x15'.
</pre><pre class="language-matlab">Error in test3>Datos (line 516)
Material.(s)
</pre><pre class="language-matlab">Error while evaluating Table CellEditCallback
</pre><p>I have manage to get just s='Acero' and it works fine. So it seems that Material.(s) is ignoring the dots and is taking ,for example, 'Acero.Cuadrado.C_15x15' as a complete field name and not subfields.</p><p>I have also trying the following codes:</p><pre class="language-matlab">s=sprintf('.%s',t{1:end-1},t{end})
</pre><p>--> Returns class:char and "non-existent field" even for s='Acero'</p><pre class="language-matlab">for i=2:1:col
s=strcat(s,'.',table2(row,i))
end
</pre><p>--> Returns class:cell and "Argument to dynamic structure reference must evaluate to a valid field name."</p>Libros Construccionhttp://www.mathworks.com/matlabcentral/profile/authors/9336281-libros-construcciontag:www.mathworks.com,2005:Question/3158852016-12-07T20:52:35Z2016-12-08T05:34:34Zexporting binary matrix to excel<p>Hi using dec2bin i have converted matrix into a binary vector, now i want to export the binary vector to excel, i am facing problem that all the bits of a particular element dont appear in the single cell,.e.g ,the</p><img src = "/matlabcentral/answers/uploaded_files/64970/excel.png"><p>second element of the vector is 100, i want it to be stored as E1 in the picture, rather than it is stored by xlswrite command like the row 2. in three different cells, A2, B2 and C2</p>Hafeez Wolfhttp://www.mathworks.com/matlabcentral/profile/authors/9334811-hafeez-wolftag:www.mathworks.com,2005:Question/3159272016-12-08T05:33:03Z2016-12-08T05:33:03Znum2str not working on "solve" answers?<p>I have the following code, which doesn't work. The variables a0, a1, a2 are global variables, and they crash in the following line:</p><pre class="language-matlab">F = strcat('f(x)=',num2str(a2),'x^2+',num2str(a1),'x+',num2str(a0));
</pre><p>These variables are given values over here:</p><pre class="language-matlab">global a2;
global a1;
global a0;
syms x y z;
A = total*x + xs*y + x2*z == ys;
B = xs*x + x2*y + x3*z == xiyi;
C = x2*x + x3*y + x4*z == x2yi;
solucion = solve([A,B,C],[x,y,z]);
</pre><pre> a0 = solucion.x;
a1 = solucion.y;
a2 = solucion.z;</pre><p>All the variables in the equations are also global variables, which at the beginning of my program are set to 0 and increase to their respective values before I even begin solving the system of equations. How come none of my a's are numbers? Does solve() return other types of variables?</p>Dax Ayrtonhttp://www.mathworks.com/matlabcentral/profile/authors/9316851-dax-ayrtontag:www.mathworks.com,2005:Question/3159252016-12-08T05:29:20Z2016-12-08T05:29:20ZHow do I complete the boarder around an object and fill it in?<p>I have the following images that I found the edge of the object in the picture. How do I complete the edges all around and fill everything outside or inside the edge, or border. I am trying to segment an object. Thank you. Attached are the images and the code is below.</p><pre class="language-matlab">a = t1B;
figure, imshow(a)
</pre><pre class="language-matlab">hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(a), hy, 'replicate');
Ix = imfilter(double(a), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
figure
imshow(gradmag,[]), title('Gradient magnitude (gradmag)')
se = strel('line',16,90);
BW2 = imdilate(magnitude,se);
new = ~bwareaopen(~magnitude, 50000);
figure, imshow(BW2);
figure, imshow(new);
</pre><img src = "/matlabcentral/answers/uploaded_files/64996/t1.jpg"><img src = "/matlabcentral/answers/uploaded_files/64997/t2.jpg"><img src = "/matlabcentral/answers/uploaded_files/64998/t3.jpg">Mikehttp://www.mathworks.com/matlabcentral/profile/authors/5552499-miketag:www.mathworks.com,2005:Question/3159242016-12-08T05:28:55Z2016-12-08T05:28:55Zwarping/standardising pictures<p>I need to warped/standardised a picture into a model. Attached the picture landmarked with the interested portion cropped and the model to which I want to fit the irregular shape.</p><img src = "/matlabcentral/answers/uploaded_files/64994/picture&cropped.png"><img src = "/matlabcentral/answers/uploaded_files/64995/model.png">Matteo Tommaso Ungarohttp://www.mathworks.com/matlabcentral/profile/authors/9336530-matteo-tommaso-ungarotag:www.mathworks.com,2005:Question/3159232016-12-08T05:24:44Z2016-12-08T05:24:44ZIs CPLEX an open-source optimization toolbox?<p>I am using intlinprog solver for my problem as an integer linear programming. For the problem I am working on, I found most of the literature reviews use CPLEX instead. I am new in optimization and CPLEX, my question is: is CPLEX an open source toolbox? is it free license so that one can download it and use it?
Thanks</p>Ismaelhttp://www.mathworks.com/matlabcentral/profile/authors/1344148-ismaeltag:www.mathworks.com,2005:Question/3151272016-12-02T16:06:52Z2016-12-08T05:19:34ZROBOT LOCALIZATION AND MOTION PLANNING<p>The state of the robot is fully described by its position and orientation
xk=[xk,yk,ϕk]T
, expressed in the global coordinate frame marked with
x
and
y
. Given a control input
uk=[rk,Δϕk]T
, the robots first turns on the spot by an angle
Δϕk
and then moves in a straight line for a distance of
rk
in the direction it is facing.</p><p>Please implement the motion model as an anonymous function assigned to f that models this behaviour. This motion model will be employed to arrive at a prior estimate x^ k
of the robot pose given a posterior estimate of the pose at a previous time instance
xk−1 and control inputs uk as x^k=f(xk−1,uk). (x^k is estimate of xk). Please also provide the Jacobians with respect to the state
xk−1
and the input
uk
as anonymous functions and assign them to
Fx
and
Fu
respectively.</p><p>1
f = @(x, u) ????;</p><p>2
Fx = @(x,u) ????;</p><p>3
Fu = @(x,u) ????;</p>Kenhttp://www.mathworks.com/matlabcentral/profile/authors/1541314-kentag:www.mathworks.com,2005:Question/3159222016-12-08T05:19:26Z2016-12-08T05:19:26ZTime dependent resistance using SimScape Electrical foundation library<p>I'm trying to model a large electrical network of resistors and capacitors in SimScape using Electrical foundation library blocks. One of the resistors needs to change its resistance as a function of time, say like this:</p><pre class="language-matlab">R=R0*(1-delR*(1-exp(-t))
</pre><p>where R is resistance, R0 is the initial resistance, delR is the factor by which I want the resistance to decrease and t is time. I can't figure out how to incorporate time variance at all in to the simscape model(as I can't seem to access a time variable). There is a variable resistance block available, but I'm facing the same problem there as well, as it seems to be built to vary with respect to voltage. I'm using Matlab 2016a.</p>Venkata Subrahmanyan Govindarajanhttp://www.mathworks.com/matlabcentral/profile/authors/8785114-venkata-subrahmanyan-govindarajantag:www.mathworks.com,2005:Question/3158542016-12-07T17:40:56Z2016-12-08T05:18:39ZHelp with solve please<p>Hello i have a problem, i have this variables</p><pre class="language-matlab">d = 0.8, E = 157.0627, k= 8.8160e-7, M=1500, s=0.0025, v=2, w= 20, x = 0
</pre><p>and i have this implicit equation</p><pre class="language-matlab">C = (M./(w.*d.*sqrt(4.*pi.*E.*t))).*exp((((x-v.*t).^2)./(-4.*E.*t))-k.*t)
</pre><p>I want to calculate "t" when C=0.018, i was trying with solve but i can´t
Could you help me?</p>Jonathan Quirozhttp://www.mathworks.com/matlabcentral/profile/authors/9333879-jonathan-quiroztag:www.mathworks.com,2005:Question/3157512016-12-07T03:47:38Z2016-12-08T05:17:38ZHow to request additional data from the user in a function<p>Hi,
Thanks for reading this.</p><p>I have to call a function, then it appears I need to request more data from within the function. Data the user is supposed to type on the screen. How do I do this? The problem is stated as:</p><img src = "/matlabcentral/answers/uploaded_files/64919/Capture.JPG"><p>I have to admit I'm a little unclear with regard to what the problem statement is requesting.</p>DJ Vhttp://www.mathworks.com/matlabcentral/profile/authors/1665539-dj-vtag:www.mathworks.com,2005:Question/3158782016-12-07T20:37:45Z2016-12-08T05:12:07ZHi I have a matrix that is 100x100 and i would like to know if its possible to change the font size of the matrix when it shows as output ?<p>I only want to change the font size of the matrix, not the command window nor the script.</p>Evan Dieppahttp://www.mathworks.com/matlabcentral/profile/authors/9214148-evan-dieppatag:www.mathworks.com,2005:Question/3159202016-12-08T05:10:02Z2016-12-08T05:10:02Zsolve non linear equations using Newton iterative method<p>My equations are</p><pre> x/sqrt(x^2+y^2) = -1 + 1/1.2 * cos(phi)
y/sqrt(x^2+y^2) = 1/1.2 * sin(phi)
arg(diff((x- jy)/sqrt(x^2+y^2)),a) = pi/2 - phi</pre><p>Where,</p><pre class="language-matlab">x(a) = cos(a) - a*b*sin(a) - 1
y(a) = a*b*cos(a) + sin(a)
</pre><p>Here variables are</p><pre> a b phi</pre><p>References: https://www.dropbox.com/s/3sv4hs5z5jn3mfr/xyz.pdf?dl=0</p>Dhiraj Rhttp://www.mathworks.com/matlabcentral/profile/authors/2441497-dhiraj-rtag:www.mathworks.com,2005:Question/3157662016-12-07T06:44:29Z2016-12-08T04:56:06Zi want to concatenate two variable but getting an 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 want to concatenate two variables.
first i loaded my data which is a matrix, to both variables then store particular part of variables in another variable and then concatenate them.
Here is my code.</p><pre class="language-matlab">t=load('2');
v=load('3');
T.a =t(:,2:size(t,2));
c=v(:,2:size(v,2));
ans=cat(2,T.a,c);
</pre><p>Here '2','3' are my files.</p><p>but i am getting error...</p><p>Error using cat
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 Untitled3 (line 5)
ans=cat(2,T.a,c);
i think becoz when i load data it stores in variables with different field names.</p><p>Plz provide some solution . i have to use it</p>MAYANK RATHOREhttp://www.mathworks.com/matlabcentral/profile/authors/8631616-mayank-rathoretag:www.mathworks.com,2005:Question/1432152014-07-24T16:30:07Z2016-12-08T04:49:03ZHow to construct 3D images from 2D images taken at different depth of that object?<p>I have the 2D images of brain taken at different depth.</p><p>First of all,Every 2D images have a thickness.</p><p>1.How can I construct 3D images/higher Dimensions images from those 2D images?
I have no idea how to do that. Anyone can point the direction for me? Is it the case like reconstruction of CT slice?</p><p>2. I am using the following code to read those file in tif formal and and after that I got a file for those image. How can I show that file? Imshow don't support that.</p><p>filebase = 'C:\Users\user\Desktop\matlab';
startFrame = 1;
endFrame = 19;
%read frames, reduce size, show frames, and build volume
for i=startFrame:endFrame
filename=[filebase, num2str(i,'%2d'),'.tif']
temp=double(imresize(imread(filename), 0.5));
slice(:,:,i) = (temp(:,:,1)==255) + 2*(temp(:,:,2)==255) + 4*(temp(:,:,3)==255);
imagesc(slice(:,:,i));
colormap('gray')
drawnow
end</p><p>My english is not very good. Maybe there is something that is not very clear to you. Please ask me If you cannot understand some parts.
Thank you</p><p>John</p>tabwhttp://www.mathworks.com/matlabcentral/profile/authors/5464797-tabwtag:www.mathworks.com,2005:Question/1143422014-01-31T08:19:34Z2016-12-08T04:47:04Zk-means clustering: save the number of iterations in a matrix<p>Hello,</p><p>With the following command the number of iterations are displayed in the
Command Window.</p><p>idx = kmeans(X,30,'display','iter');</p><pre class="language-matlab">iter phase num sum
1 1 365 40.9896
2 1 60 37.0645
3 1 18 36.001
4 1 3 35.7457
5 1 1 35.6472
6 2 39 34.8684
7 2 32 34.1611
8 2 16 33.7392
9 2 11 33.3268
10 2 4 33.2144
11 2 1 33.2046
11 iterations, total sum of distances = 33.2046
</pre><p>Is there a way to save the displayed number of iterations and the total sum of distances in a matrix stored in the Workspace?</p><p>Thank you.
Best,</p><p>Pavlos</p>pavloshttp://www.mathworks.com/matlabcentral/profile/authors/2882759-pavlostag:www.mathworks.com,2005:Question/3159192016-12-08T04:43:07Z2016-12-08T04:44:57Zi have matrix matrix2D= '00000001' '00000011' '00000111' '00000100' '00000101' '00000100' '00000001' '00000010' '00000001' '00000001' '00000100' '00000011' '00000111' '00000100' '00000001' '<p>in matrix2D each element is in binary form
a b c
1 1 7,
3 2 4,
7 1 1,
4 1 4,
5 4 0,
4 3 2.
of this numbers and i want to generate another number from this binary format number and a+b+c=9 now i want to genrate another number which follow a+b+c=9. like 000000 <b>01</b> and 000001 <b>11</b> so new generated code is taken as two point crossover and new genrated number is 00000011 and 00000101 now take all entry as two point and must follow a+b+C=9</p>Pratik Anandparahttp://www.mathworks.com/matlabcentral/profile/authors/9212467-pratik-anandparatag:www.mathworks.com,2005:Question/3159182016-12-08T04:32:46Z2016-12-08T04:32:46ZHow to simulate pixel simulation in Matlab?<p><b>I want to simulate the readout circuit of image sensor.</b>
The model I want to make has a input of sample picture(bitmap form),and output which is the image added some noise. <b>I have a trouble with modeling the fixed pattern noise which is caused by the fluctuation of transistor parameter(for example,vth,gm,etc) in source follower circuit(SF).</b>
Generally,each pixel has one SF.
Is it possible for Matlab/Simulink?Please lend the wisdom.(By the way, I have been using matlab/simulink for only 1 year)</p>Taishi Sawauchihttp://www.mathworks.com/matlabcentral/profile/authors/7985621-taishi-sawauchitag:www.mathworks.com,2005:Question/6392011-01-31T19:10:16Z2016-12-08T04:11:04ZFrequency modulating a wav file?<p>Hi, i'm trying to frequency modulate an arbitary input wav file with a periodic wave. I was wondering how to do this because basic maths for frequency modulation depends on simple sine waves and i'm trying to modulate a non periodic complex waveform?</p>
<p>Any help would be greatly appreciated!</p>George Smithhttp://www.mathworks.com/matlabcentral/profile/authors/2602439-george-smithtag:www.mathworks.com,2005:Question/3159172016-12-08T04:10:52Z2016-12-08T04:10:52ZHow to refine the map?<p>Hi, I have generated a map to segment the in-focus object from the image. I have attached the image of the map. Kindly guide how can I remove the unwanted pixels present in the boundary of the region. Kindly suggest me some technique to refine this map. Thanks in advance.</p><img src = "/matlabcentral/answers/uploaded_files/64982/final%20map.jpg">Nataliyahttp://www.mathworks.com/matlabcentral/profile/authors/5953637-nataliyatag:www.mathworks.com,2005:Question/3159162016-12-08T04:02:48Z2016-12-08T04:04:03ZHow to draw the vector <p>I got all the values but I cannot plot the vectors as shown in the attachment. If I can get help please!</p><pre class="language-matlab">a=10;
b=20;
c=25;
d=30;
theta2=60;
k1=d/a;
k2=d/c;
k3=((a^2-b^2+c^2+d^2)/(2*a*c));
A=sind(theta2);
B=cosd(theta2)-k2;
C=k1*cosd(theta2)-k3;
thetatan1=A+sqrt((A^2+B^2-C^2)/(B+C));
thetatan2=A-sqrt((A^2+B^2-C^2)/(B+C));
theta41=2*atand(thetatan1);
theta42=2*atand(thetatan2);
k4=d/b;
k5=(c^2-d^2-a^2-b^2)/(2*a*b);
D=cosd(theta2)-k1+k4*cosd(theta2)+k5;
E=-2*sind(theta2);
F=k1+(k4-1)*cos(theta2)+k5;
theta3tan1=((-E+sqrt(E^2-3*D8F))/(2*D));
theta3tan2=((-E-sqrt(E^2-3*D8F))/(2*D));
theta31=2*atand(theta3tan1);
theta32=2*atand(theta3tan2);
</pre>Hisham Alfawzanhttp://www.mathworks.com/matlabcentral/profile/authors/7001134-hisham-alfawzantag:www.mathworks.com,2005:Question/3159152016-12-08T03:49:32Z2016-12-08T03:59:19ZPlotting with plot3 and patch<p>I have a script which is plotting some 3d objects made with patch. I would also like to plot the trajectory of one of the objects. I am using plot3 to do this. However, I cannot find a way to plot both on the same figure despite hold on already being used. Any thoughts?</p>Cameron Crookhttp://www.mathworks.com/matlabcentral/profile/authors/7912917-cameron-crooktag:www.mathworks.com,2005:Question/3158752016-12-07T20:31:14Z2016-12-08T03:55:56Zfunction work in matlab describtion but not work in GUI<p>The question in short is this function gIDW work if i do run in matlab and the answer appear in workspase but when i press the bttom in GUI peogram the gIDW function not work and this massage appear</p><pre> Error using .* Matrix dimensions must agree.</pre>hussein hajihttp://www.mathworks.com/matlabcentral/profile/authors/9286224-hussein-hajitag:www.mathworks.com,2005:Question/3159112016-12-08T02:25:23Z2016-12-08T03:43:34ZSubscripted assignment dimension mismatch<p>The following is my code, the problem is on the line with x(i) = -.0316.*n11 + .0108.*n21. I have not found anything that matches my problem if it does exist just the link would be appreciated.</p><pre class="language-matlab">t = linspace(0,5,100); % time of measurement of the spring system
</pre><pre class="language-matlab">t0 = (l1 + l2)/v; % time delay in s
</pre><pre class="language-matlab">n11 = (1/(wn1^2*m)).*((-.0316*(kf*Yo)-.0121*(kf*l1*Yo))).*(1-cos(wn1.*t));
</pre><pre class="language-matlab">n12 = (1/(wn1^2*m)).*((-.0316*(kf*Yo)-.0121*(kf*l1*Yo))).*(cos(wn1.*(t-t0))-cos(wn1.*t)) + (1/(wn1^2*m)).*((-.0316*(kf*Yo + kr*Yo)+.0121*(-kf*l1*Yo + kr*Yo*l2))).*(1-cos(wn1.*(t-t0)));
</pre><pre class="language-matlab">n21 = (1/(wn2^2*m)).*((.0108*(kf*Yo)-.0354*(kf*l1*Yo))).*(1-cos(wn2.*t));
</pre><pre class="language-matlab">n22 = (1/(wn1^2*m)).*((.0108*(kf*Yo)-.0354*(kf*l1*Yo))).*(cos(wn2.*(t-t0))-cos(wn2.*t)) + (1/(wn2^2*m)).*((.0108*(kf*Yo + kr*Yo)+.0354*(-kf*l1*Yo + kr*Yo*l2))).*(1-cos(wn2.*(t-t0)));
</pre><pre class="language-matlab">% Equations of motion x and theta
</pre><pre class="language-matlab">for i = 1:length(t)
</pre><pre> if (0<=t(i)) && (t(i)<=t0)</pre><pre> x(i) = -.0316*n11 + .0108*n21;</pre><pre> elseif (t0<t(i))
x(i) = -.0316.*n12 + .0108.*n22;
end
end</pre><pre class="language-matlab">for i = 1:length(t)
</pre><pre> if (0<=t(i)) && (t(i)<=t0)
theta(i) = .0121.*n11 + .0354.*n21;
elseif (t0<t(i))
theta(i) = .0121.*n12 + .0354.*n22;
end
end</pre><pre class="language-matlab">xf = x - l1.*theta; % Equation of motion for the front
</pre><pre class="language-matlab">xr = x + l2.*theta; % Equation of motion for the rear
</pre>Wes Thompsonhttp://www.mathworks.com/matlabcentral/profile/authors/8596426-wes-thompsontag:www.mathworks.com,2005:Question/3158602016-12-07T18:26:09Z2016-12-08T03:40:30ZNearest Neighbor Matching without Replacement<p>Hello there,</p><p>I am looking to match data in two vectors, x and y, based on shortest Euclidean distance. Each match should be unique; that is, numbers in vectors x and y cannot be matched twice. I have looked into knnsearch, but have not found anything that suggests the function works without replacement. Thank you!</p>Alhttp://www.mathworks.com/matlabcentral/profile/authors/5524639-altag:www.mathworks.com,2005:Question/3158502016-12-07T17:18:11Z2016-12-08T03:39:59ZHow can I acquire frames from a live video stream, acquire the frames, then use the frames to recreate the live video stream?<p>Hello.
I want to detect red objects from the live video stream (I know how to detect red objects)</p><p>What I want to know is how to acquire the frames from the original live video stream and recreate another live video stream using the processed frames and play these two video streams side by side.</p><p>Please help. I'd be really grateful to you.</p>Shinobuhttp://www.mathworks.com/matlabcentral/profile/authors/8401680-shinobutag:www.mathworks.com,2005:Question/3159072016-12-08T01:13:17Z2016-12-08T03:36:20Zhave large .h5 dataset that i need to read into matlab<p>First, I am new to matlab.</p><p>I have a large dataset that i need to read into matlab. I have already gone through all help files on read .h5 files which i don't have an issue with. however when i try to right a routine to read and then plot these files i get an error. Please see code below. The problem i have is the data files, when create, have non-sequential numbers and they change every time i run a new simulation. So i need to be able to call all the files with out knowing for certain what the numbers for each file. i thought that maybe i could use error handling to disregard the error so the program would not stop however i don't know if i could do that or if there is another way to load all the files from a folders and plot the data. the ultimate goal would be to make a movie of the data as it progresses in time, where each dataset is some time interval later in the simulation. Any help would be appreciated.</p><pre class="language-matlab">if true
filename = 'cyc0000000.h5'; %starting filename here, check this
nimages = 0100000; %number of images here, check this
[basename,remain] = strtok(filename,'0');
[start,extension] = strtok(remain,'.');
nstart=str2num(start);
for k = (nstart+1):(nstart+nimages)
filename = strcat(basename,sprintf('%07d',k),extension);
</pre><pre> n=hdf5read(filename, 'ne');
plot(r,n);</pre><pre class="language-matlab">end
</pre>Eric Dutrahttp://www.mathworks.com/matlabcentral/profile/authors/7381945-eric-dutratag:www.mathworks.com,2005:Question/3159062016-12-08T00:53:51Z2016-12-08T03:35:03ZHow to remove subplot grey space between images<p>I am trying to remove the space between and cannot figure it out. I have tried many ways and nothing is working. Is there a way to remove the space between or maybe a different way to approach this problem. The goal is to have the images touching in a grid like way</p><p>This is what prints:</p><img src = "/matlabcentral/answers/uploaded_files/64977/Screen%20Shot%202016-12-07%20at%207.55.13%20PM.png"><pre class="language-matlab">theImage = imread('BarackObama.jpg');
%theImage = imread(image);
grayScaleImage = rgb2gray(theImage);
theGrayImage = grayScaleImage > 100;
</pre><pre class="language-matlab">[height, width, dim] = size(theImage);
</pre><pre class="language-matlab">numRecsAcross = 4;
numRecsDown = 4;
</pre><pre class="language-matlab">xmin = 1;
ymin = 1;
width = (width/numRecsAcross);
height = (height/numRecsDown);
</pre><pre> xmin = uint16(xmin);
ymin = uint16(ymin);
width = uint16(width);
height = uint16(height);</pre><pre class="language-matlab">s = 1;
</pre><pre class="language-matlab">for i = 1: numRecsDown
for j = 1: numRecsAcross
block = theImage(ymin+i-i:height*i, xmin+j-j:width*j, :);
</pre><pre> color = uint8(mean(mean(block)));</pre><pre> rr = color(:,:,1);
gg = color(:,:,2);
bb = color(:,:,3);</pre><pre> RedChannel = 255 * uint8(theGrayImage);
BlueChannel = 255 * uint8(theGrayImage);
GreenChannel = 255 * uint8(theGrayImage);</pre><pre> r = ((double(rr))/255) * RedChannel;
g = ((double(gg))/255) * GreenChannel;
b = ((double(bb))/255) * BlueChannel;</pre><pre> rgbImage = cat(3, r, g, b);</pre><pre> subplot(numRecsAcross,numRecsAcross,s);
imshow(rgbImage);</pre><pre> s = s+1;</pre><pre> end
end</pre>Francisco Rogelhttp://www.mathworks.com/matlabcentral/profile/authors/8726739-francisco-rogeltag:www.mathworks.com,2005:Question/3158842016-12-07T20:51:30Z2016-12-08T03:32:59Zhow can i patch a circle in the origin of the axis?<p>wich cordinates can i use</p>juan diego villadahttp://www.mathworks.com/matlabcentral/profile/authors/7938411-juan-diego-villadatag:www.mathworks.com,2005:Question/3159122016-12-08T02:41:18Z2016-12-08T03:32:34Zvoltage sag mitigation with DVR<p>Hi, I am currently working on voltage sag and swell mitigation using DVR in simulink. I do not know why, but I am not getting desired outputs. So, can anybody check or have a look at my matlab model and rectify? Thank you in advance.It is really urgent</p>Sarvesh Gadrehttp://www.mathworks.com/matlabcentral/profile/authors/8681532-sarvesh-gadretag:www.mathworks.com,2005:Question/3159082016-12-08T02:09:48Z2016-12-08T03:25:49ZTrouble running 5 separate data sets through one code and saving the answers for each data set.<p>I have a code that calculates certain variables such as damping ratio and natural frequency for a set of data. I have also made graphs to correspond to my results. I can successfully run one data set all the way through and get the answers I am looking for. However, I have been given 5 sets of data and need to automatically run each set of data through the code, save each variable for each case, and save all of the graphs for each case. I tried using 5 stacked for loops but in the end I am only left with the variables and the graphs from the last data set. Is there an easy way to run each set of data through and end up with 5 separate plots?</p>Melissahttp://www.mathworks.com/matlabcentral/profile/authors/7535361-melissa