https://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-06-29T04:15:16Ztag:www.mathworks.com,2005:Question/376132012-05-06T20:30:23Z2016-06-29T04:15:16Zthrows to get yahtzee!?<p>I have a schoolproject where I'm about to create a function that shows how many throws u need to get a yatzy with five dices.</p><p>I think my code works to get yatzy one time, but when I try to do it 50000 times and take out the average value (suppost to be 11~) I get 18 every time.</p><p>Can anyone see whats wrong? The problem might be that my function counts every dice as a throw, when its suppost to count for example 3 dices as one throw if I "want" the function to throw all 3 at ones, just like u do in yatzy if u know the game. If u have any questions about names etc, just let me know!</p><p>Anyway, here is my code so far:</p><pre class="language-matlab">function yatzy=yatz(n)
</pre><pre class="language-matlab">MC = 0;
</pre><pre class="language-matlab">for z=1:50000;
</pre><pre class="language-matlab">i=0;
count=1;
</pre><pre class="language-matlab">for i = 1:n;
</pre><pre> kast(i)=floor(rand*6);</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">sort(kast);
</pre><pre class="language-matlab">[Y,I]= mode(kast);
</pre><pre class="language-matlab">A = ones(1,I);
</pre><pre class="language-matlab">B = Y*A;
</pre><pre class="language-matlab">dices = 5-I;
</pre><pre class="language-matlab">while dices ~= 0;
</pre><pre> O = floor(rand*6);
if O==Y;
dices = dices-1;</pre><pre> end
count=count+1;
end
korv=ones(1,n)*Y;</pre><pre class="language-matlab">MC = MC+count;
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">medel = MC/50000;
</pre><pre class="language-matlab">medel
</pre><pre class="language-matlab">end
</pre>Maxhttps://www.mathworks.com/matlabcentral/profile/authors/3467966-maxtag:www.mathworks.com,2005:Question/2928232016-06-29T04:02:24Z2016-06-29T04:07:15ZHi, i need to divide all 5 images into 16x16 block, then perform "minus" operation (i.e 1st from 3rd image, then calculate "mean").Likewise for (3rd and 5th image) and (2nd and 4th image) using block process<p>Thanks in advance</p>kaavya subramanihttps://www.mathworks.com/matlabcentral/profile/authors/6727842-kaavya-subramanitag:www.mathworks.com,2005:Question/2928172016-06-29T02:51:51Z2016-06-29T03:46:55ZI need help with determining how many rolls it takes to get 5 of a kind in yahtzee<p>I am having difficulties with matlab and now I have to write a program that will counter how many times I roll the dice until I get 5 of a kind.</p>Dave Campbellhttps://www.mathworks.com/matlabcentral/profile/authors/8202881-dave-campbelltag:www.mathworks.com,2005:Question/2928222016-06-29T03:41:57Z2016-06-29T03:41:57ZPanel GUI change content<p>Hi good morning,</p><p>I have some question according with GUI panel,
how to I change the content at panel GUI once user click to another menu the contect will be change according to user selected and the previous content will be dissapear to show the new content. I don't know how to set the code can anyone help me.
I'm just set some of the menu content at panel like this:
set(handles.display,'visible','on');
set(handles.text25,'visible','on');
set(handles.MRN,'visible','on');
set(handles.OfflineDiagnosis,'visible','on');
set(handles.DiagnosisD,'visible','on');
but when I change to another content the previous can't dissapear, what should I do the code to change the content selected at Panel GUI.
thank you</p>Nasiha Husnihttps://www.mathworks.com/matlabcentral/profile/authors/8373422-nasiha-husnitag:www.mathworks.com,2005:Question/2928062016-06-28T22:48:29Z2016-06-29T03:40:36ZFinding triangles in a k-NN graph<p>Hello,</p><p>I have a simple undirected graph represented by an adjacency matrix where (i,j)=1 if nodes i and j are connected, else (i,j)=0. I'd like to find all possible loops of three edges (triangles!) in the graph. Something like: node 1 to node 14, 14 to 50, and 50 to 1 (assuming node 1 is connected to 14, 14 to 50, and 50 to 1).</p><p>Are there any matlab tools available to do this?</p>JohnDapperhttps://www.mathworks.com/matlabcentral/profile/authors/7055028-johndappertag:www.mathworks.com,2005:Question/2928192016-06-29T03:16:55Z2016-06-29T03:37:47ZCalculating a time duration from the graph<p>Hello</p><p>I am interested in finding out the time between two points in a graph (x-axis is the time, y-axis is the quantity of interest). For testing my logic, I'm using a sinusoidal wave to see if I get the correct responses. In the sinusoidal wave defined below, I'm interested in calculating the starting and ending x-coordinate when the y-axis value is less than 0.4.</p><pre class="language-matlab">t= [0:0.1:2*pi];
a=sin(t);
figure;
h=plot(t,a);
</pre><pre class="language-matlab">for i=1:max(t)
y=get(h,'ydata');
if a < 0.4
start=get(h,'xdata');
if a > 0.4
fin=get(h,'xdata');
end
end
</pre><p>This is an infinite loop, which doesn't give any output. I'm not really familiar with matlab and am not able to figure out how to get the start and fin values above.</p><p>Any help is appreciated.</p><p>Thanks!</p>Mridul Garghttps://www.mathworks.com/matlabcentral/profile/authors/7142910-mridul-gargtag:www.mathworks.com,2005:Question/2928212016-06-29T03:28:05Z2016-06-29T03:35:45ZImprove more speed in the double loop<p>Hello everybody,</p><p>I'm trying to implement an small photogrammetric program to perform the image correction using the equations as bellow in a double loop (rows by columns):</p><pre class="language-matlab">clc clear
</pre><pre class="language-matlab">Cx = 7760/2.0; Cy = 10328/2.0; res_pixel = 5.2/1000.0;
</pre><pre class="language-matlab">x0 = -0.125000;
y0 = 0.120000;
k0 = 2.8651e-007;
k1 = -2.3991e-005;
k2 = 1.1672e-008;
k3 = -1.1518e-016;
p1 = -1.3960e-006;
p2 = -1.7870e-007;
</pre><pre class="language-matlab">IMG1 = imread('c:\temp\24_4855.tif');
</pre><pre class="language-matlab">[x1,y1,z1] = size(IMG1);
</pre><pre class="language-matlab">S = uint8(zeros(x1,y1,z1));
</pre><pre class="language-matlab">for i=1:x1
for j=1:y1
</pre><pre> x = res_pixel*((i-1)-Cx);
y = -res_pixel*((j-1)-Cy);</pre><pre> %Radial distortion k0,k1,k2,k3
r = sqrt((x^2)+(y^2));
drad_x = (k0+(k1*r^2)+(k2*r^4)+(k3*r^6))*x;
drad_y = (k0+(k1*r^2)+(k2*r^4)+(k3*r^6))*y;</pre><pre> %Decentering distortion p1,p2
ddesc_x = p1*(r^2+(2*x^2))+2*p2*x*y;
ddesc_y = p2*(r^2+(2*y^2))+2*p1*x*y;</pre><pre> %Coordinates with distortions
x_dist = x + x0 + drad_x + ddesc_x;
y_dist = y + y0 + drad_y + ddesc_y;</pre><pre> %Coordinates with distortions - double
c1 = ((x_dist/res_pixel)+Cx)+1;
l1 = ((-1*(y_dist/res_pixel))+Cy)+1;</pre><pre> %Coordinates with distortions - int
c2 = fix(((x_dist/res_pixel)+Cx)+1);
l2 = fix(((-1*(y_dist/res_pixel))+Cy)+1);</pre><pre> %Bilinear interpolation:
dx1 = double(c1 - c2);
dy1 = double(l1 - l2);
a1 = double(IMG1(c2,l2,:));
a2 = double(IMG1(c2+1,l2,:));
a3 = double(IMG1(c2,l2+1,:));
a4 = double(IMG1(c2+1,l2+1,:)); </pre><pre> RGB = uint8(a1 + (dx1*(a2 - a1)) + (dy1*(a3 - a1)) +
(dx1*dy1*(a1 - a2 - a3 + a4)));</pre><pre> Image matrix:
S(i,j,:) = RGB;
end
end</pre><p>When I test a simple double loop (without any equation) and using an image with the dimensions: x1 = 10328 and y1 = 7760, the elapsed time is 12.159344 seconds. However, when I test the double loop (with all equations) with the same image and "parfor", the elapsed time is aprox. 1200 seconds. I'm using an computer with i7 processor and 8Gb memory.</p><p>Any suggestion how I can reduce the processing time?</p><p>Thanks and Regards,</p><p>Leo.</p>Leonardo Filhohttps://www.mathworks.com/matlabcentral/profile/authors/3440502-leonardo-filhotag:www.mathworks.com,2005:Question/2928162016-06-29T02:45:27Z2016-06-29T03:20:44ZHow to get p-value, RMSE out of fitlm? <p>I use mdl = fitlm(X,y,'robust','on') to get the statistics of my regression, and I know how to get the Rsquare: R2 = md1.Rsquared.Ordinary;</p><p>My question is how do I get the p-value and RMSE out of the fitlm results?</p><p>Thanks.</p>Leonhttps://www.mathworks.com/matlabcentral/profile/authors/3133287-leontag:www.mathworks.com,2005:Question/2925712016-06-28T02:58:56Z2016-06-29T03:20:11ZCT image display error.<p>I am trying to display CT Dicom slices in a montage and used the code below but I get only some parts of the image read and not all of it. The Images are attached below. I need the actual image to be read using the program. Can anyone help me fix this.</p><p>The original images are attached as a zip file "images.zip".</p><pre class="language-matlab">clear %no variables
close all %no figures
clc %empty command window
%%
</pre><pre class="language-matlab">ff = fullfile(pwd, '2.16.840.114421.80674.9357820679.9389356679');
files = dir(fullfile(ff, '*.dcm'));
fname = {files.name};
%%
</pre><pre class="language-matlab">info = dicominfo(fullfile(ff, fname{1}));
</pre><pre class="language-matlab">voxel_size = [info.PixelSpacing; info.SliceThickness];
</pre><pre class="language-matlab">rd = dicomread(fullfile(ff,fname{1}));
sz = size(rd);
num_image = length(fname);
</pre><pre class="language-matlab">ct = zeros(info.Rows, info.Columns, num_image, class(rd));
</pre><pre class="language-matlab">for i=length(fname):-1:1
fname1 = fullfile(ff, fname{i});
ct(:,:,i) = uint16(dicomread(fname1));
end
%%
</pre><pre class="language-matlab">montage(reshape(uint16(ct), [size(ct,1), size(ct,2), 1, size(ct, 3)]), 'DisplayRange', []);
set (gca, 'clim', [0,100]);
%%
</pre><pre class="language-matlab">im = ct(:, :, 200);
maxl = double(max(im(:)));
imt = imtool(im, [0, maxl]);
</pre><p>Original Image:</p><img src = "/matlabcentral/answers/uploaded_files/55132/im1.png"><p>Read Image:</p><img src = "/matlabcentral/answers/uploaded_files/55133/im2.png">anusha reddyhttps://www.mathworks.com/matlabcentral/profile/authors/8257883-anusha-reddytag:www.mathworks.com,2005:Question/2925772016-06-28T04:38:41Z2016-06-29T03:08:23ZHow to print text on the same line ?<p>I want to print a sentence on the same line like</p><pre class="language-matlab">for i=1:100
printf('At %d', i);
end
</pre><p>So matlab must print</p><p>At 1</p><p>Then on the SAME LINE SAME PLACE it must print At 2. Now all it does is print</p><pre class="language-matlab">At 1
At 2
At 3
At 4
</pre><p>Or</p><pre> At 1 At 2 At 3 At 4 At 5</pre><p>I want matlab to overwrite the number.</p>RuiQihttps://www.mathworks.com/matlabcentral/profile/authors/6016970-ruiqitag:www.mathworks.com,2005:Question/2928182016-06-29T02:58:28Z2016-06-29T02:58:28Z'Derivative' output vibration problem in Simulink<p>The output of 'Derivative'(continuous) block in Simulink has vibration and glitches although its clean input has no vibration.</p><p>In ode5 solver it happens in a time interval but in ode4 it happens in another time interval. The problem is same for fixed time step and variable time step mode.</p><p>Someone knows the reason?</p>Jong Tai Janghttps://www.mathworks.com/matlabcentral/profile/authors/3008494-jong-tai-jangtag:www.mathworks.com,2005:Question/2925072016-06-27T15:04:38Z2016-06-29T02:58:17ZLimit of p value from multcompare?<p>(I'm having exactly the same question as this one on Stack Exchange, so I'm quoting it verbatim as follows)</p><p>It seems to me that MATLAB multcompare cannot output any p value (for pairwise comparison) smaller than 9.56061674273201e-10.</p><p>To confirm this, I did</p><pre class="language-matlab">y = [ones(100,1) 2*ones(100,1) 3*ones(100,1)];
[p,tbl,stats] = anova1(y);
[c,~,~,gnames] = multcompare(stats);
p = c(:,6)
</pre><p>and got p values for the three pairwise comparisons</p><pre class="language-matlab">p =
</pre><pre> 9.56061674273201e-10
9.56061674273201e-10
9.56061674273201e-10</pre><p>Why is there this limit in MATLAB? How should I report my p values then? It looks strange to report exactly same values for several different tests.</p>Eric H Cheonghttps://www.mathworks.com/matlabcentral/profile/authors/5042475-eric-h-cheongtag:www.mathworks.com,2005:Question/2927362016-06-28T14:25:58Z2016-06-29T02:50:22ZHow can i write any vector into short form?<p>I have a vector</p><pre> V = [0 0 0 -45 45 45 -45 90 90]</pre><p>i want to view it as countable form i.e</p><pre> [(0)3, -45, (45)2, -45, (90)2] </pre><p>or</p><pre> [(0)*3, -45, (45)*2, -45, (90)*2] </pre><p>or any other counted form. May be by using symbolic tool. please help me.</p>Triveni https://www.mathworks.com/matlabcentral/profile/authors/6565084-trivenitag:www.mathworks.com,2005:Question/1292012014-05-11T20:21:04Z2016-06-29T02:48:00Zplotting voice segments in sound file<p>So my project is to take a .wav file with speech segments and create a script that will label the voice portions on the plot of the actual speech based on its spectrum.
So, we know that voice frequencies range from 85-400 Hz.
I've taken the FFT of the sample and the frequency distribution is strange.
Very high at the low range and high range with almost nothing in the voice range.
There's not a lot of other noise in the sample.
any advice would be appreciated.
What I would like to do is measure frequency across time and label parts that fall within in speech frequencies as the speech portions.</p>Josephhttps://www.mathworks.com/matlabcentral/profile/authors/5144931-josephtag:www.mathworks.com,2005:Question/2927852016-06-28T19:50:06Z2016-06-29T02:46:03ZHow can I see if an image is symmetric/centered?<p>Hi,</p><p>I have to determine if a DSLR camera is properly centered in its underwater container. I took a picture using the camera far back enough to have an image of the o-ring of the container against a plain background. I have imported this image as a JPG and want to determine if the circle is centered/ how far off center it is. Ideas?
Thank you!</p>Rachel Herrerahttps://www.mathworks.com/matlabcentral/profile/authors/8379635-rachel-herreratag:www.mathworks.com,2005:Question/2819632016-05-01T11:11:46Z2016-06-29T02:40:26ZWhy I receive an error in Fuzzy Logic Controller? Fuzzy Logic Controller': Initialization commands cannot be evaluated. Attempt to modify 'fuzwiz' which is a locked (read-only) library<p>I built an fuzzy logic controller for traction control.Every time I run my simulink model , an error will appear.
"Fuzzy Logic Controller': Initialization commands cannot be evaluated. Attempt to modify 'fuzwiz' which is a locked (read-only) library"</p><p>When I rerun the simulink model , the error disapperas.</p>Pengcheng Zhaohttps://www.mathworks.com/matlabcentral/profile/authors/7355936-pengcheng-zhaotag:www.mathworks.com,2005:Question/2927932016-06-28T20:52:16Z2016-06-29T02:38:52Zhow can I make only one isoline in a color image of many different temperatures?<p>i did a image of sea surface temperature and i wanna trace a isoline of 22 degrees celcius. how can i do it?</p>João Victor Koppehttps://www.mathworks.com/matlabcentral/profile/authors/8379799-joao-victor-koppetag:www.mathworks.com,2005:Question/2928032016-06-28T22:14:07Z2016-06-29T02:31:19Zshifting an image vertically down.<p>Hi, I want to shift a picture vertically down by 50 pixels here is my code:</p><pre class="language-matlab">X=imread('photo1.jpg');
X_double=double(X);
[m,n]=size(X_double);
E=eye(n);
T=zeros(n,n);
r=50;
T(1:r,:)=E(n-(r-1):n,:);
T(r+1:n,:)=E(1:n-r,:);
X_shift=T*X_double
</pre><p>I'm trying to make a transformation matrix and then multiply the resulting matrix by the image matrix "X". I keep getting an error though:</p><p>"Error using <b>, inputs must be 2-D, or at least one input must be scalar. To compute elementwise TIMES, use TIMES (.</b>) instead."</p><p>Any help is much appreciated, thanks.</p>Odom Senghttps://www.mathworks.com/matlabcentral/profile/authors/7230141-odom-sengtag:www.mathworks.com,2005:Question/2928152016-06-29T01:49:40Z2016-06-29T02:29:23ZHow can I compute the direction of gradient at each pixel of an image I ??<p>I need MatLab code to compute gradient direction atan(y/x) for image at each pixel</p>Abdelrahiem Hashemhttps://www.mathworks.com/matlabcentral/profile/authors/8121700-abdelrahiem-hashemtag:www.mathworks.com,2005:Question/2927552016-06-28T16:19:11Z2016-06-29T02:28:22ZTexture for Irregular Regions<p>I would like to know if it has a way to calculate texture for irregular regions.
I plan to calculate the texture for irregular regions, who came from the Watershed, and then create a similarity matrix. However, I found no descriptors for this. I tried GLCM to calculate Contrast, Energy and Uniformity for each region, but was not good.</p><p><b>Do you know any texture descriptor that's good to use in irregular regions?</b></p>Kauê Duartehttps://www.mathworks.com/matlabcentral/profile/authors/7849579-kaue-duartetag:www.mathworks.com,2005:Question/2928102016-06-29T00:03:28Z2016-06-29T02:20:50Z2016b provides an answer to the operation [1 2 3 4 5].' + [1 2 3 4] whereas 2015b indicates 'Matrix dimensions must agree'. 2016b's behaviour is not clearly documented. Is it correct?<p>2016b
a=1:5</p><p>a =</p><pre> 1 2 3 4 5</pre><p>K>> b=1:4</p><p>b =</p><pre> 1 2 3 4</pre><p>K>> a.' + b</p><p>ans =</p><pre> 2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8
6 7 8 9</pre>Craighttps://www.mathworks.com/matlabcentral/profile/authors/2404810-craigtag:www.mathworks.com,2005:Question/2926622016-06-28T10:19:05Z2016-06-29T01:51:56Zhow to put two doubles coulmns and third is strings in uitable GUI?<p>I am trying to get the results of my predication to be in two columns where zeros and ones while the third column give me the closest neighbours based on KNN using the Names</p><p>i tried the following:</p><pre class="language-matlab">resultdata= [Double' doubleout KNnames];
columnformat = {'numeric','numeric','char'};
set(handles.uitable2, 'Data',resultdata , 'ColumnFormat',columnformat);
</pre><p>but not working
I want to be like the following knowing that I loaded the first columns from files and the third two from another excel file</p><pre> Column1 cloumn2 column 3
1 1 y1
0 1 y3</pre>essamhttps://www.mathworks.com/matlabcentral/profile/authors/5569078-essamtag:www.mathworks.com,2005:Question/2928022016-06-28T22:03:26Z2016-06-29T01:42:09ZArrange a set of elements in an array<p>Hello,</p><p>So i have an array that goes like this:</p><pre> A=
[1
4
3
2
1
4
3
2
1
4
3
2
1
4
3
2
.
.
.</pre><pre> ]</pre><p>I want to arrange it as</p><pre class="language-matlab">A=
[4
3
2
1
4
3
2
1
4
3
2
1
4
3
2
1
4
3
2
1
]
</pre><p>How can I do this?</p>Soumyatha Gavvalahttps://www.mathworks.com/matlabcentral/profile/authors/6816133-soumyatha-gavvalatag:www.mathworks.com,2005:Question/2928132016-06-29T01:04:27Z2016-06-29T01:34:55Zi need a matlab code for ModLEACH and iModLeach protocols <p>hi i need a matlab code for ModeLeach and iModeLEACH protocols to make a comparison between them.can someone help me please.</p>salma salmahttps://www.mathworks.com/matlabcentral/profile/authors/8376270-salma-salmatag:www.mathworks.com,2005:Question/2928142016-06-29T01:24:22Z2016-06-29T01:31:39Zpls give me an exact formula for Mathew's correlation coeffficient for MULTICLASS<p>Mathew's correlation coeffficient for MULTICLASS</p>praseena prahladhttps://www.mathworks.com/matlabcentral/profile/authors/7639092-praseena-prahladtag:www.mathworks.com,2005:Question/2928122016-06-29T00:53:37Z2016-06-29T00:53:37ZExtracting data from columns of one array to another based on criteria in a column, with different length arrays<p>I have two arrays, A and B (attached as excel files). I need to extract columns 4 and 5 from array B to columns 6 and 7 of array A. This needs to be done based on the values in the first 3 columns (year, month, day). So where the dates of array A and B are the same, I need the associated values from columns 4 and 5 in array B output to array A. Any help would be great.</p>Tyler Smithhttps://www.mathworks.com/matlabcentral/profile/authors/7221810-tyler-smithtag:www.mathworks.com,2005:Question/2925942016-06-28T06:34:43Z2016-06-29T00:08:19ZHow to smooth this curve so that I can find the sharpest turning point<p>I have a curve plotted below:</p><img src = "/matlabcentral/answers/uploaded_files/55147/Untitled1.png"><p>I want to find out the sharpest turning point indicated in the figure by locating the maximal second derivative. But since the curve is not smooth, the second derivative has many peaks, even after I filtered the curve. The same is true for calculating curvatures. So I was wondering if I can fit the curve by some "good" smooth curve which has a single peak of the second derivative so that I can easily pick out the sharpest turning point via diff function. But since I'm not very familiar with curve-fitting, I ask here in hope that someone can help. Btw, if you think you have a better idea than the curve-fitting and calculating the the second derivative, you are welcomed to post your (correct) idea here. Thanks a lot.</p>zzzhhhhttps://www.mathworks.com/matlabcentral/profile/authors/7253780-zzzhhhtag:www.mathworks.com,2005:Question/2925522016-06-27T21:27:36Z2016-06-29T00:03:03ZEfficient method of summing the values in multiple images on GPU?<p>I have a series of images sitting on GPU in a 71x71x5000 matrix.</p><p>Is there an efficient method of finding the sum of all elements in each 71x71 image on the GPU?</p><p>I wanted to do something similar to this but it isn't so simple.</p><pre class="language-matlab">sums = pagefun(@sum, images)
</pre>Christopher Desmondhttps://www.mathworks.com/matlabcentral/profile/authors/8327321-christopher-desmondtag:www.mathworks.com,2005:Question/2928092016-06-28T23:46:55Z2016-06-28T23:51:02ZGet all coef at one level from Wavelet Packet<p>Let</p><pre class="language-matlab">wpt = wpdec(x,'haar',3);
</pre><p>How can I get all coefficients of all nodes from one level at one time without using the for-loop? For examples</p><pre class="language-matlab">coef = [wpcoef(wpt,[2 0]); ...,wpcoef(wpt,[2 3])];
</pre><p>Thanks.</p>Zahi Kakishhttps://www.mathworks.com/matlabcentral/profile/authors/3596877-zahi-kakishtag:www.mathworks.com,2005:Question/736392013-04-26T05:12:10Z2016-06-28T23:43:19Zsending and receiving IMAGE using serial port(USB to serial)<p>Hi friends,</p><p>Actually I have an image which need to be transferred via serial port. As my laptop dosent contain serial port i am using USB to serial convertor.I am sending image from one computer other using two USB to serials and null modem. I am doing this for testing purpose and later null modem will be replaced by 8051 controller. I wrote a code for transferring but i am unable to receive data proper control. Please check the below code.</p><p><b>For Transfering</b></p><pre class="language-matlab">if true
</pre><pre> SendData=serial('COM1','BaudRate',256000);
fopen(SendData);
[rows,columns]=size(Encryptedimage);
for k=1:3
for i=1:rows
for j=1:columns
data=num2str(EncryptedImage(i,j,k));
fprintf(SendData, '%c' , '*');
fprintf(SendData, '%s',data);
end
end
end
fclose(SendData);
delete(SendData);
clear SendData;</pre><pre class="language-matlab">end
</pre><p><b>For receiving</b></p><pre class="language-matlab">if true
</pre><pre class="language-matlab">recData=serial('COM2','BaudRate',256000);
fopen(recData);
while(1)
Input1=fread(receiveTemp)
</pre><pre> if(isempty(Input1))
continue;
else
disp('Value received')
for k=1:3
for i=1:rows
for j=1:columns</pre><pre> Input1=char(Input1);
Input1=sscanf(Input1, '%d');
EncryptedImage1(i,j,k)=Input1;
Input1=fread(receiveTemp);</pre><pre> end
end
end
end
if(i==rows & j==columns & k==3)
break;
end
end</pre><pre class="language-matlab">end
</pre><p>Now problem is while receiving Input1 is getting around 120 values at a time.
please help me in rectifying this issue.</p>srikanthhttps://www.mathworks.com/matlabcentral/profile/authors/3816884-srikanthtag:www.mathworks.com,2005:Question/2921972016-06-24T18:36:37Z2016-06-28T23:42:13ZColor Different Scatter Points Based on Group<p>Hello,</p><p>I have a great deal of points on a 3D scatter plot that I need to be shown in different colors. They need to be categorized in color based on a label that they are given in the data set. All examples I have seen for coloring markers in scatter plots has been based on distance/position (which is not what I need).</p><p>Any help with how to code color markers based on grouping/labeling would be appreciated!</p>Brian Tomblinhttps://www.mathworks.com/matlabcentral/profile/authors/7194600-brian-tomblintag:www.mathworks.com,2005:Question/2928012016-06-28T22:00:08Z2016-06-28T23:27:50ZMex Fortran on Mac OS X El Capitan with Matlab 2016a<p>Hi,</p><p>I am trying to compile mex fortran file on Mac os x El Capitan with MATLAB 2016a, but I have an error message like below....</p><pre class="language-matlab">>> mex -v HausMex.f
Verbose mode is on.
Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require the use of
-largeArrayDims and remove the -compatibleArrayDims option.
For more information:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
... Looking for compiler 'gfortran' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'which gfortran' ...No.
... Looking for file '/usr/local/bin/gfortran' ...Yes.
... Looking for folder '/usr/local/bin' ...Yes.
... Executing command 'which gfortran' ...No.
... Looking for file '/usr/local/bin/gfortran' ...Yes.
... Executing command '/usr/local/bin/gfortran -print-file-name=libgfortran.dylib' ...Yes ('/usr/local/gfortran/lib/libgfortran.dylib').
... Looking for folder '/usr/local/gfortran/lib' ...Yes.
... Executing command 'which gfortran' ...No.
... Looking for file '/usr/local/bin/gfortran' ...Yes.
... Executing command '/usr/local/bin/gfortran -print-file-name=libgfortranbegin.a' ...Yes ('/usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0/libgfortranbegin.a').
... Looking for folder '/usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.11').
Found installed compiler 'gfortran'.
Options file details
-------------------------------------------------------------------
Compiler location: /usr/local/bin
Options file: /Users/jongkwan.kim/.matlab/R2016a/mex_FORTRAN_maci64.xml
CMDLINE1 : /usr/local/bin/gfortran -c -DMX_COMPAT_32 -I"/Applications/MATLAB_R2016a.app/extern/include" -I"/Applications/MATLAB_R2016a.app/simulink/include" -fexceptions -m64 -fbackslash -O /Users/jongkwan.kim/Documents/Research/WRF_Hydro/RDHMvsWRF/HausMex.f -o /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o
CMDLINE2 : xcrun -sdk macosx10.11 clang -Wl,-twolevel_namespace -undefined error -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2016a.app/extern/lib/maci64/fexport.map" -O /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o -L"/Applications/MATLAB_R2016a.app/bin/maci64" -lmx -lmex -lmat -L"/usr/local/gfortran/lib" -lgfortran -L"/usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0" -lgfortranbegin -o HausMex.mexmaci64
CMDLINE3 : rm -f /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o
FC : /usr/local/bin/gfortran
FDEFINES : -DMX_COMPAT_32
FFLAGS : -fexceptions -m64 -fbackslash
INCLUDE : -I"/Applications/MATLAB_R2016a.app/extern/include" -I"/Applications/MATLAB_R2016a.app/simulink/include"
FOPTIMFLAGS : -O
FDEBUGFLAGS : -g
LDF : xcrun -sdk macosx10.11 clang
LDFLAGS : -Wl,-twolevel_namespace -undefined error -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2016a.app/extern/lib/maci64/fexport.map"
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2016a.app/extern/lib/maci64/fexport.map"
LINKLIBS : -L"/Applications/MATLAB_R2016a.app/bin/maci64" -lmx -lmex -lmat -L"/usr/local/gfortran/lib" -lgfortran -L"/usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0" -lgfortranbegin
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
DEVELOPER_DIR_CHECK :
GFORTRAN_INSTALLDIR : /usr/local/bin
GFORTRAN_LIBDIR : /usr/local/gfortran/lib
GFORTRANBEGIN_LIBDIR : /usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
SDKVER : 10.11
MATLABROOT : /Applications/MATLAB_R2016a.app
ARCH : maci64
SRC : /Users/jongkwan.kim/Documents/Research/WRF_Hydro/RDHMvsWRF/HausMex.f
OBJ : /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o
OBJS : /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o
SRCROOT : /Users/jongkwan.kim/Documents/Research/WRF_Hydro/RDHMvsWRF/HausMex
DEF : /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.def
EXP : HausMex.exp
LIB : HausMex.lib
EXE : HausMex.mexmaci64
ILK : HausMex.ilk
MANIFEST : HausMex.mexmaci64.manifest
TEMPNAME : HausMex
EXEDIR :
EXENAME : HausMex
OPTIM : -O
LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'gfortran'.
/usr/local/bin/gfortran -c -DMX_COMPAT_32 -I"/Applications/MATLAB_R2016a.app/extern/include" -I"/Applications/MATLAB_R2016a.app/simulink/include" -fexceptions -m64 -fbackslash -O /Users/jongkwan.kim/Documents/Research/WRF_Hydro/RDHMvsWRF/HausMex.f -o /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o
f951: Warning: Nonexistent include directory â€˜/Applications/MATLAB_R2016a.app/simulink/includeâ€™ [-Wmissing-include-dirs]
/Users/jongkwan.kim/Documents/Research/WRF_Hydro/RDHMvsWRF/HausMex.f:59:26:
call Hausdorff(%val(pr_out), %val(pr_in1), mG1,
1
Warning: Type mismatch in argument â€˜hausdistâ€™ at (1); passed INTEGER(4) to REAL(8)
</pre><pre class="language-matlab">xcrun -sdk macosx10.11 clang -Wl,-twolevel_namespace -undefined error -mmacosx-version-min=10.11 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2016a.app/extern/lib/maci64/fexport.map" -O /var/folders/sb/nn380qyj7js3bqzqc2lsqkyccr014t/T/mex_323792336433392_2725/HausMex.o -L"/Applications/MATLAB_R2016a.app/bin/maci64" -lmx -lmex -lmat -L"/usr/local/gfortran/lib" -lgfortran -L"/usr/local/gfortran/lib/gcc/x86_64-apple-darwin14/5.2.0" -lgfortranbegin -o HausMex.mexmaci64
Error using mex
Undefined symbols for architecture x86_64:
"_mxgetm_", referenced from:
_mexfunction_ in HausMex.o
"_mxgetn_", referenced from:
_mexfunction_ in HausMex.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
</pre><p>If you have any clue to figure out, please leave a comment on it.</p><p>Thanks,</p>Jongkwanhttps://www.mathworks.com/matlabcentral/profile/authors/4144619-jongkwantag:www.mathworks.com,2005:Question/2928082016-06-28T23:23:43Z2016-06-28T23:23:43ZHow to plot radiance and reflectance after importing a .bil from a multiband read ?<p>I imported a subimage of a multiband image into MATLAB using multiband read. I am trying to figure out how to plot various thing such as Radiance, Reflectance etc. I have only used softwares to these in the past and it did calculation under the hood so no idea how to do this. Thanks !</p>mjpatel7https://www.mathworks.com/matlabcentral/profile/authors/8356094-mjpatel7tag:www.mathworks.com,2005:Question/2928002016-06-28T21:32:56Z2016-06-28T23:14:51ZHow to limit the dimension of a 3D matrix?<p>Hi all,</p><p>I'm new to Matlab and currently working on a project which takes in frames of a tif video file(nxmx3010) and builds some 3D images for each 14 frames. . But now, the problem I'm facing is:
When I take the first 14 frames of the file, the output 3D image(nxmx14) is good enough for me to do some manipulations, but then, the 3D image of the next 14 frames are having the starting frame:15 and ending frame:28, but, in the 3D image, the dimensions are being represented as nxmx28. The problem with this is, the new 3D matrix is having zero pixels in the 1-14 frames and the rest frames in the matrix are good.</p><p>My question is, how to not include the 1-14 empty frames while building 15-28 frame 3D matrix?</p>Varshini Guddantihttps://www.mathworks.com/matlabcentral/profile/authors/7925808-varshini-guddantitag:www.mathworks.com,2005:Question/2928072016-06-28T22:56:09Z2016-06-28T23:05:48ZMatlab Function for name algorithm<p>Somebody please help I have no idea what I am doing. Any tips or advice will be appreciated!</p><p>Write a function that will take a single input: a number x
It will return a single number that represents p(x)
where p is a polynomial that represents your surname, according to the following algorithm.</p><p>1. Replace each letter of your surname by the positive integer it corresponds to in the alphabet: a is replaced by 1, b is replaced by 2, and so on.</p><p>2. Subtract 13 from each of those numbers</p><p>3. Divide each of those numbers by 6</p><p>4. Divide each of those numbers by 2^(i−1) where i represents the position of the letter in the array. I.e. the first number is divided by 2^0 the second number by 2^1 and so on.
5.Label the resulting numbers in order where n is the number of letters in your name. The polynomial is</p><p>p(x)=a0+a1x+⋯+an−1x^(n−1).</p><p>For example, if your name were Lee, the steps would go like this.
1. [12 5 5]</p><p>2.[-1 -8 -8]</p><p>3.[-0.1667 -1.333 -1.333]</p><p>4.[-0.1667 -0.6667 -0.3333]</p><p>5.p(x)=−0.1667−0.6667x−0.3333x2</p>Christyna Georgehttps://www.mathworks.com/matlabcentral/profile/authors/8379805-christyna-georgetag:www.mathworks.com,2005:Question/23812011-03-02T22:45:38Z2016-06-28T22:56:27ZAccessing Matrix Rows using Logical Indexing<p>This is probably a very simple question to answer, and I'm sure its been asked a million times, but I just can't seem to find an answer that works for me.</p>
<p>Let's say I have an array like this:</p>
<p>A = [1 1 1 1;2 2 2 2;3 3 3 3;4 4 4 4];</p>
<p>A =</p>
<pre> 1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4</pre>
<p>Now, I want to somehow return all the rows where the values in the second column are greater than 3.</p>
<p>I know I can get the logical indices like this:</p>
<p>B = A(:, 2) > 2;</p>
<p>B =</p>
<pre> 0
0
1
1</pre>
<p>Now, if I then do this:</p>
<p>C = A(B);</p>
<p>C =</p>
<pre> 3
4</pre>
<p>What I get back is a vector that contains the values from the first column who's rows correspond to the indices from B that are 1.</p>
<p>What I want instead though, is all four columns instead of just the first column.</p>
<p>C =</p>
<pre> 3 3 3 3
4 4 4 4</pre>
<p>So far, the only way I know of to get this to work, is to use a for loop, like this:</p>
<pre class="language-matlab">counter = 1;
for i = 1:size(A, 1)
if (A(i, 2)) > 2
C(counter, :) = A(i, :);
counter = counter + 1;
end
end
</pre>
<p>This is kinda inefficient though, since it needs to loop through every element instead of using MATLAB's powerful array processing features.</p>
<p>Can someone tell me how to accomplish what I'm trying to, without using loops?</p>
<p>Thanks!</p>Kiran Ramaswamyhttps://www.mathworks.com/matlabcentral/profile/authors/2260057-kiran-ramaswamytag:www.mathworks.com,2005:Question/2928052016-06-28T22:30:34Z2016-06-28T22:38:44ZHow to write matlab commands for partial sums<p>I am trying to write this function in matlab and am having trouble, can someone help?</p>Christyna Georgehttps://www.mathworks.com/matlabcentral/profile/authors/8379805-christyna-georgetag:www.mathworks.com,2005:Question/2925282016-06-27T17:39:11Z2016-06-28T22:34:29Ztransfer function frequency response<p>how to get transfer function from this time response plot? Red is input and blue is output....</p>Zhe Liuhttps://www.mathworks.com/matlabcentral/profile/authors/4587426-zhe-liutag:www.mathworks.com,2005:Question/2928042016-06-28T22:25:24Z2016-06-28T22:25:24ZGiven cout matrix, plot contours<p>I am trying to recreate what the MATLAB contour, contourf, etc. functions do, except I don't want to create it from a grid. I actually have a vector of contours that is formatted exactly like the cout in the typical function call</p><p>[cout,hout] = contour(...)</p><p>The first column in cout lists the contour level and number of points that define the contour (for example [55;337] which means that the first 55-dB contour has 337 points). Then after the next 337 columns of X-Y coordinates, I get the next contour (for example [60;123] which means 60-dB contour has 123 points).</p><p>In essence I want to reverse the process. This format is how MATLAB stores the data to create contour plots, but I want to plot the contours given that I have them stored in the proper format in the cout handle.</p><p>The key here is that I have multiple contour "islands" (i.e. two distinct contours associated with the same decibel level) and I want to be able to plot them together as one contour with a single label, but without trying to connect them. If I had the grid, I would just use the contour function and let MATLAB's internal functions take care of the contour formatting. But I only have the vector of contour coordinates.</p><p>I tried to open the contour function's source code in MATLAB to see how they do it, but this just calls another function contourHGUsingMATLABClasses. I tried to open this one and I could not access it.</p><p>Any help would be much appreciated.</p>Matthewhttps://www.mathworks.com/matlabcentral/profile/authors/2701039-matthewtag:www.mathworks.com,2005:Question/2927962016-06-28T21:01:12Z2016-06-28T22:16:29ZRun single equation many times <p>Here I have code that finds W over again 1000 times</p><pre class="language-matlab">nsample1 = 255;
nsample2 = 160;
X = 1.2 + 0.15*randn(1,nsample1);
Y = 1.1 + (1.25-1.1)*rand(1,nsample2);
B = [X Y];
c = 1e3;
for i = 1:c;
W(i+1,:) = 10*sum(B);
end
</pre><p>When I run the code it goes 1000 times, all outputs are the same. I want 1000 outputs that are nearly the same to eachother. X and Y using rand and randn to generate random numbers to get a different B each time, do I have something wrong in my for loop? Supposed to be like a monte carlo simulation.</p>Luke Radcliffhttps://www.mathworks.com/matlabcentral/profile/authors/8207473-luke-radclifftag:www.mathworks.com,2005:Question/2685272016-02-17T05:38:18Z2016-06-28T22:03:08ZHow Can I know the presence of an individual person in a Video in terms of time frame?? <p>For example say in a 10 minutes video, a person is there for 'x' min, I would like to know the time length and time frame of the Person present in the video.
Thanks in Advance!!</p>kanaka rajuhttps://www.mathworks.com/matlabcentral/profile/authors/7640655-kanaka-rajutag:www.mathworks.com,2005:Question/2715702016-03-05T04:49:33Z2016-06-28T21:59:48ZConcentrated Solar Power Generation Systems<p>According to this webpage - <a href = "http://www.mathworks.com/solutions/energy-production/solar-power.html">http://www.mathworks.com/solutions/energy-production/solar-power.html</a> - Simulink can be used to design concentrated solar power (CSP) generation systems. Does anyone know where could I find an existing model of a CSP plant on Simulink? I browsed all the examples in the documentation but I couldn't find anything related to concentrated solar power.</p><p>Thanks!</p>Carlos Emilio Perez Damashttps://www.mathworks.com/matlabcentral/profile/authors/7278578-carlos-emilio-perez-damastag:www.mathworks.com,2005:Question/2927972016-06-28T21:04:52Z2016-06-28T21:52:17ZHow to set semilog axis limit<p>How to set semilog limit on x axis?
I want it to be from 100 Hz to 15 000 Hz.</p>Claymzhttps://www.mathworks.com/matlabcentral/profile/authors/8110180-claymztag:www.mathworks.com,2005:Question/2927992016-06-28T21:18:10Z2016-06-28T21:51:40ZEfficient moving average of scattered data<p>I have some scattered data and I'd like to take something similar to a moving average, where I average all values with in some radius of each point. I can do this with a loop, but I'd like a more efficient approach. Any ideas?</p><p>Here's a working example I'd like to make more efficient:</p><pre class="language-matlab">x = randi(100,45,1) + 20+3*randn(45,1) ;
y = 15*sind(x) + randn(size(x)) + 3;
</pre><pre class="language-matlab">figure
plot(x,y,'bo')
</pre><pre class="language-matlab">radius = 10;
</pre><pre class="language-matlab">ymean = NaN(size(x));
for k = 1:length(x)
</pre><pre> % Indicies of all points within specified radius:
ind = abs(x-x(k))<radius; </pre><pre> % Mean of y values within radius:
ymean(k) = mean(y(ind));
end</pre><pre class="language-matlab">hold on
plot(x,ymean,'ks')
legend('scattered data','radial average','location','southeast')
</pre><img src = "/matlabcentral/answers/uploaded_files/55198/test.png">Chad Greenehttps://www.mathworks.com/matlabcentral/profile/authors/1062128-chad-greenetag:www.mathworks.com,2005:Question/2927762016-06-28T18:53:53Z2016-06-28T21:40:39ZWhy do I have to register in order to watch some webinars?<p>Why do I need to register before watching some webinars? What is the registration for?</p>Samuele Contihttps://www.mathworks.com/matlabcentral/profile/authors/6298079-samuele-contitag:www.mathworks.com,2005:Question/2919242016-06-23T17:05:39Z2016-06-28T21:37:15ZEfficiently Swapping Columns in a Matrix<p>Is there a more efficient/faster way to switch out two columns in a matrix than calling:</p><pre class="language-matlab">A(:,[i j]) = A(:,[j i]);
</pre><p>If anyone knew of faster implementation (possibly even using MEX), I would greatly appreciate them sharing.</p>Kyle Marocchinihttps://www.mathworks.com/matlabcentral/profile/authors/6284322-kyle-marocchinitag:www.mathworks.com,2005:Question/2927892016-06-28T20:00:33Z2016-06-28T21:33:43ZI am an intern. I have Matlab Student edition installed on my computer. Am I allowed to use this for a research paper I am coauthoring which will be published?<p>I am currently an intern doing research in the physics field. My boss was an old professor I had, and she has Matlab installed for research purposes but I have figured it would be easier to write the code and do the research with my own computer. This is not a requirement for a course, and the paper to be published will largely contain plots from my code.</p><p>Is it against my student license agreement to use the version on my own computer for this research if there is a license on the school's computer?</p><p>How could they tell?</p><p>Why should it make a difference whether I type on one computer versus another? I'm writing the same code either way and it's going to end up in the same place.</p><p>It's a few questions, but I feel they are important to know the answers to before this paper is written and published.</p>Zachary Henryhttps://www.mathworks.com/matlabcentral/profile/authors/6839483-zachary-henrytag:www.mathworks.com,2005:Question/1164792014-02-17T17:27:59Z2016-06-28T21:30:43ZWhy does parpool take so long to start up for the first time in a MATLAB session?<p>Hi all,</p><p>I've recently set up MATLAB's Distributed Computing Server for my cluster of 30 workers across three machines. When I run the parpool command for the first time in a MATLAB session, it takes over 30 minutes to connect to the 30 workers. Thereafter, it takes less than 3 minutes. Anyone know why this might be, and how to decrease the wait time?</p><p>I have two dual six-core machines (24) and one dual quad-core (8). I'm reserving one core for the client MATLAB session and another for the MATLAB Job Scheduler (at the recommendation of MathWorks). I'm running MATLAB R2013b on Windows 7 Pro 64-bit.</p><p>Thanks!</p>Edwardhttps://www.mathworks.com/matlabcentral/profile/authors/4865197-edwardtag:www.mathworks.com,2005:Question/2927952016-06-28T21:00:39Z2016-06-28T21:21:37ZReplace A single element of matrix<p>Hi, what I want to do is replace a single value in the 201X201 identity matrix to form a transformation matrix. I know how to form the identity matrix, but im having trouble figuring out how to replace a value. I want to replace the zero in the 201st row and 1st column with a 240. I know this probably has a an easy solution, but any help is appreciated, thanks!</p>Odom Senghttps://www.mathworks.com/matlabcentral/profile/authors/7230141-odom-sengtag:www.mathworks.com,2005:Question/2927882016-06-28T19:54:52Z2016-06-28T21:15:19ZSubstituing symbolic variable with the element of a matrix before using ode solver<p>So, I have this explicit ODE system (named Y):</p><pre> Y =
(0.5*(1.95e290*cos(sin(3.0*t))^2*cos(sin(t))*sin(3.0*t) + [...] + 3... Output truncated. Text exceeds maximum line length of 25 000 characters for Command Window display.
-(0.5*(8.58e290*cos(sin(3.0*t))^2*sin(sin(t))*sin(3.0*t) + [...] + 4.16e253*cos(sin(3.0*t))*sin(sin(3.0*t))^4*cos(sin(t))^2*sin(sin(t))... Output truncated. Text exceeds maximum line length of 25 000 characters for Command Window display.
-(0.5*(2.13e295*cos(sin(3.0*t))^2*cos(sin(t))^2*sin(t) + [...] +3.98e260*cos(sin(3.0*t))^2*sin(sin(3.0*t))^3*cos(sin(t))*sin(sin(t))^4*sin(30.0*t)^3*sin(t) + 4.16e2 ... Output truncated. Text exceeds maximum line length of 25 000 characters for Command Window display.</pre><p>in which each equation of the equations systems depends of 4 variables, which are the time "t", "theta1p(t)", "theta2p(t)" and "theta3p(t)". Now, as you can see, the equations of this system are kinda long and I need to find a way to substitute the thetaXp by a y(X) so I can use this system of equation with the ODE solver function ode45. That means that in Y above, I need to substitute:</p><pre class="language-matlab">theta1p with y(1)
theta2p with y(2)
theta3p with y(3)
</pre><p>So that I may be able to do:</p><pre> tspan=[0 10]
initcond=[0 ; 0 ; 0]
[t,y45]=ode45(Y,tspan,initcond)</pre><p>I already tried doing substitutions such as</p><pre> [t,y45]=ode45(@(t,y) (subs(Y,[theta1p ; theta2p ; theta3p],[y(1) ; y(2) ; y(3)])),tspan,initcond)</pre><p>but it doesn't seem to work. If it's of any help, I've joined my code to this post and I identified the section where I'm stuck by a series of "HERE" that are hard to miss (it's near the end of the code)</p>VincentLechttps://www.mathworks.com/matlabcentral/profile/authors/8325191-vincentlec