http://de.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2016-08-25T18:25:48Ztag:de.mathworks.com,2005:Question/2594002015-12-08T15:32:12Z2016-08-25T18:19:40ZHow do you convert base m to base n<p>Hello guys. I know this is stupid but can someone help me about this. Im asked to convert any number or letter from base m to base n. from bimary to deci, vice versa, binary to hexa and vice versa, and binary to octal and vice versa WITHOUT using inbuilt matlab conversiom commands. Im only limited to the REM and MOD command. Can someone help me? I really dont know what todo. Thank you</p><p>So after reading comments Im heartly to say sorry. It's my first time here and I only rushed the question.</p><p>So here I first converted my input to a string using string2num. Then I used the length function to determine length of input. Now i'm stuck at the conversion. Because it is required that the code is IN general, not in piece by piece. Like binary to 3 binary to 4 like that. I know that using modulo and then having a remainder 0 will OUTPUT 0 and remainder 1 will OUTPUT 1 If we were to convert base m to base 2. I really am stuck now for the general coding, cause iknow theres a division and multiplication process here. Sorry for taking up your precious time</p>Riven Yvethttp://de.mathworks.com/matlabcentral/profile/authors/7384565-riven-yvettag:de.mathworks.com,2005:Question/3009002016-08-25T16:58:26Z2016-08-25T18:16:21ZMatrix linear indexing: how to add more than once to the same index<p>Here is my question. Let's imagine we have this matrix:</p><pre class="language-matlab">A = [1 2 ; 3 4];
</pre><p>So if I use linear indexing to add 1 to, for instance, positions 1 and 3:</p><pre class="language-matlab">A([1 3]) = A([1 3]) + 1
</pre><pre class="language-matlab">A =
</pre><pre> 2 3
3 4</pre><p>Now, let's imagine that, having the initial A matrix, I have an index vector in which some indices are repeated. For example, I need to add twice 1 to the first position, and once to the index 3:</p><pre class="language-matlab">A([1 3 1])=A([1 3 1])+1
</pre><pre class="language-matlab">A =
</pre><pre> 2 3
3 4</pre><p>And surprisingly I get A(1,1)=2, instead of A(1,1)=3. How can I make it work?</p><p>The first idea was to put it inside a loop, but the matrix is normally big and this operation runs many times, and it becomes very slow. Any ideas?</p><p>Thank you very much in advance!</p>Pablo García Auñónhttp://de.mathworks.com/matlabcentral/profile/authors/5164958-pablo-garcia-aunontag:de.mathworks.com,2005:Question/558192012-12-05T18:21:32Z2016-08-25T18:15:05ZHow to convert daily data to monthly?<p>I have huge number of precipitation daily data in a column (say for 60 years) for 400 meteorological stations. Now I need to convert it to monthly. How can I do that? thanks.</p>Mohammadhttp://de.mathworks.com/matlabcentral/profile/authors/3643720-mohammadtag:de.mathworks.com,2005:Question/3008752016-08-25T13:59:00Z2016-08-25T18:14:52ZAn empty do loop giving seg fault with OpenMP while mexing with fortran<p>Hello,</p><p>I have a code which uses a 'parallel do' construct. When I run the code in serial, it works w/o any problem. But when I parallelize it, it gives seg fault. I tried omitting some parts of the code out for testing purposes. At the end, I endded up with the below which still gave the seg fault error.</p><pre class="language-matlab">!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(i,adjDist,j,k)
do i = 1,nNods
adjDist = zero
do j = 1,nDim
do k = 1,nAdj
if (nodAdj(i,k).eq.0) cycle
adjDist(k,j) = XYZ(nodAdj(i,k),j) - XYZ(nods(i),j)
enddo
enddo
enddo
!OMP END PARALLEL DO
</pre><p>Here 'adjDist' is a (nAdj x nDim) array and all the other variables are properly defined shared variables. Do you have any idea about what causes this to give seg fault? Before I was using the following statement;</p><pre> adjDist(:,j) = XYZ(nodAdj(i,:),j) - XYZ(nods(i),j)</pre><p>not to have the third do-loop with index 'k', but then I even changed it not to allocate/deallocate any memory, although I am not sure if Fortran allocates any extra memory in such a case. But in any case, apparently that is not the reason.</p><p>Thanks!</p><p>Ugur</p>Ugurhttp://de.mathworks.com/matlabcentral/profile/authors/4972046-ugurtag:de.mathworks.com,2005:Question/3007742016-08-24T18:39:44Z2016-08-25T18:14:49ZTo find area of interest from image<p>Hi all. I have a problem for getting the interested roi from image. They are three dimensional image. I want to remove unnecessary parts from that and make them new one. But the interested area on image sometimes vertical sometimes not. there are two examples there. how can i determine this. After finding this im going to apply lbp there.
Or apply to lbp to all image after gray level convertion. Then calculate the pixel values and get rid of the background. The original image and wanted part for extarcting lbp values is attached
thanks for suggestions</p>alihttp://de.mathworks.com/matlabcentral/profile/authors/1011711-alitag:de.mathworks.com,2005:Question/3009072016-08-25T18:10:03Z2016-08-25T18:23:13Zlabelling elements in an array<p>I have a matrix G with</p><pre class="language-matlab">labelsG = {'Delusions','Hallucinations','Flattened','Inappropriate','Poverty','Thought'};
</pre><p>I have performed constrained PCA and a rotation to get a new variable, Predictor_weights.
Each element of Predictor_weights is how much a given column of G (symptom) can predict variation in another matrix (Z).</p><p>I took the four most extreme values of Predictor_weights, and called this new variable absmax_Predictor_weights.</p><pre class="language-matlab">[~, index] = sort(abs(Predictor_weights), 'descend');
absmax_Predictor_weights = Predictor_weights(sub2ind(size(Predictor_weights), index(1:4, :), repmat(1:size(Predictor_weights, 2), 4, 1)));
</pre><p>MY QUESTION:</p><p>How can I assign my labels of G to the numeric elements of absmax_Predictor_weights? Each numeric element of absmax_Predictor_weights relates to a column of G.</p><p>Hope that makes sense, and thank you!</p>kunderhill16http://de.mathworks.com/matlabcentral/profile/authors/8586021-kunderhill16tag:de.mathworks.com,2005:Question/3007812016-08-24T19:07:00Z2016-08-25T18:05:58ZI have a code for spectral analysis but I don't 100% understand it?<p>Hey guys, so as the title says I have a script that I can use to analyse some raw EEG data (.edf). Although I have the code and can use it I don't really understand what it's doing at each stage and I'd really like to.</p><p>After the conversion the data is averaged - I assume this is to remove noise?
Then something called an elliptic filter is 'setup' and 'applied' to the data - I don't really understand what this is doing?</p><pre class="language-matlab">[order, Wn] = ellipord([fmin/(fs/2), fmax/(fs/2)], [(fmin-1)/(fs/2), (fmax+1)/(fs/2)], Rp, Rs);
[B,A] = ellip(order, Rp, Rs, [fmin/(fs/2), fmax/(fs/2)]);
</pre><p>Then ranksums values are calculated and this is used to work out something called the energy? Energy values are obtained for each of the 'channels' which corresponds to an electrode on the EEG. I have no idea what this means, the code is as follows:</p><pre class="language-matlab">for j=1:14 [p(j),H(j),STATS(j,:)] = ranksum(Energy_EEGH(j,:),Energy_EEGL(j,:),'tail','right') end
</pre><p>And the output gives me 'p' and 'H' values. I understand that p values show whether or not a result set is statistically significant? So < 0.05 proves the working hypothesis and vice versa? However I don't understand what H values are and from what I can tell they can only be 0 or 1, 0 being bad and 1 being good?
Thanks a lot.</p>Haissam Adilhttp://de.mathworks.com/matlabcentral/profile/authors/8303614-haissam-adiltag:de.mathworks.com,2005:Question/3008842016-08-25T15:10:40Z2016-08-25T17:57:53ZHow to correct for loop?<p>I have a matrix : A =</p><pre> 1 0 0 4
1 0 3 4
1 2 0 4
1 2 3 4</pre><p>I need to make this operation using values of the matrix A:</p><pre> 1 0 0 4 ====> D(1,4)*50
1 0 3 4 ====> D(1,3)*50+D(3,4)*180
1 2 0 4 ====> D(1,2)*50+D(2,4)*180
1 2 3 4 ====> D(1,2)*50+D(2,3)*180+D(3,4)*180</pre><p>Here, D is another matrix which has certain values:</p><pre> 0 22.2794 33.7859 45.0000
22.2794 0 15.4008 23.0367
33.7859 15.4008 0 14.9726
45.0000 23.0367 14.9726 0</pre><p>The main important thing is:</p><p>Between the 1 and any other values should multiply to 50,</p><p>Between other numbers as 2 and 4, or 3 and 5 should multiply to 180</p><p>I tried this code below, but something is wrong::</p><p>m = size(A,1);</p><p>result = zeros(m,1);</p><p>for k=1:m</p><pre> x = find(A(k,:));
for n=2:numel(x)
result(k) = result(k) + (D(x(1),x(n))*50)+(D(x((n+1)-1),x(n+1))*180);
end
end</pre><p>Could anyone help me?</p><p>Results should be:</p><p>45*50= 2250</p><p>33.7859*50 + 14.9726*180= 4.3844e+03</p><p>22.2794*50 + 23.0367*180= 5.2606e+03</p><p>22.2794*50 + 15.4008*180 + 14.9726*180= 6.5812e+03</p><p>Results:</p><p>2250</p><p>4.3844e+03</p><p>5.2606e+03</p><p>6.5812e+03</p>Beibit Sautbekhttp://de.mathworks.com/matlabcentral/profile/authors/7311072-beibit-sautbektag:de.mathworks.com,2005:Question/3000902016-08-18T20:48:26Z2016-08-25T18:25:48Zconvert the time domain signal into frequency domain signal<p>Hi,
I have represented the acceleration data of 3 axes(x, y, and z) in time domain as shown in the Graph</p><img src = "/matlabcentral/answers/uploaded_files/58057/neamah.jpg"><p>I would like to extract from the acceleration data some measurements (e.g. mean, energy, entropy and correlation) in the frequency domain. Therefore, I applied <b>FFT</b> transform in order to convert the time domain signal into frequency domain signal.</p><pre> xx= fft(x_Segments{1});
plot(xx)
yy= fft(y_Segments{1});
plot(yy)
zz= fft(z_Segments{1});
plot(zz)</pre><p>However, the resulted graphs make no sense( so strange) which is not expected at all !!
This is an example of the frequency domain signal of the x-axis.</p><img src = "/matlabcentral/answers/uploaded_files/58058/fft.jpg"><p><b>Note, x_Segments, y_Segments, and z_Segments contain the data of X, Y, Z axes respectively</b></p><p>As we can see the graph doesn't make sense, so, is there any steps that I should follow before using the FFT function to get the expected frequency domain signal?</p><p>I really appreciate your help guys.
thanks</p>neamah al-naffakhhttp://de.mathworks.com/matlabcentral/profile/authors/7635969-neamah-al-naffakhtag:de.mathworks.com,2005:Question/3009062016-08-25T17:45:36Z2016-08-25T17:47:33ZHow to Pass Complex structure From Matlab WorkSpace to .Net Application ?<p>I have a structure in Matlab workSpace Ex Person. Now I wish to Pass this structure to my .Net Application So that I can launch GUI so that user can can Modify that easity and then Pass the Modified structure back to workspace.</p><p>%Declaring Struct.
person.LastName = 'Clinton'
person.Name = 'Donald'</p><p>%Loading .Net DLL
asm = NET.addAssembly('ModifyStructTool.dll');
self.f=ViewModifyCalTool.MainForm('');
self.f.SetObj(p)</p><p>Error: No method 'SetObj' with matching signature found for class 'ViewModifyCalTool.MainForm'.</p><p>.Net Code
public struct Person
{
public string Name;
public string LastName;
}</p><pre> public void SetObj(Person varargin)
{
//Launch GUi and Edit.
}</pre><p>When I call the function 'SetObj' it gives below error
Error: No method 'SetObj' with matching signature found for class 'ViewModifyCalTool.MainForm'.</p><p>I am not sure how to Cast/Marshal struct from Matlab to C#</p>Jatin Sonihttp://de.mathworks.com/matlabcentral/profile/authors/8017816-jatin-sonitag:de.mathworks.com,2005:Question/3000062016-08-18T10:13:40Z2016-08-25T17:41:39ZAccessing Numerical Value of an array in for loop in mupad<p>while coding in mupad, i cannot access the numerical value of array elements, for eg;
in for loop, if the code is: s=100*T[K],the result is "100*T[2]" ,but i need 200, when T[2]=2</p>ashok jadhavhttp://de.mathworks.com/matlabcentral/profile/authors/2795365-ashok-jadhavtag:de.mathworks.com,2005:Question/3009052016-08-25T17:38:53Z2016-08-25T17:38:53ZHow do I enumerate a family of 0-1 matrices<p>I'm trying to generate the family of all 10-by-3 matrices, where each matrix in the family, call it S, has the property that S(i,j)= 0 or 1 for i=1..10 and j=1..3, and that each of the 10 row sums of S equals 1, i.e. S(i,1)+S(i,2)+S(i,3)=1, for i=1..10.</p>Paul Fishbackhttp://de.mathworks.com/matlabcentral/profile/authors/3054555-paul-fishbacktag:de.mathworks.com,2005:Question/3009042016-08-25T17:38:18Z2016-08-25T17:38:37ZConvert matrices of latitude and longitude to reference object<p>I have an MxN data array, and each datapoint also has an associated latitude and longitude that are not regularly spaced. I can display the data using pcolorm, but I want to export it as a geotiff. Geotiffwrite requires the input R, but I haven't found an obvious way to convert the matrices of lat and lon into R.</p>Kevin Cannonhttp://de.mathworks.com/matlabcentral/profile/authors/3811407-kevin-cannontag:de.mathworks.com,2005:Question/3004322016-08-22T08:00:20Z2016-08-25T17:32:54ZIs MATLAB permanant or renewal when I purchased the MATLAB standard version ? <p>Is MATLAB permanant or renewal when I purchased the MATLAB standard version ?</p>JINSOL.KIMhttp://de.mathworks.com/matlabcentral/profile/authors/5670871-jinsol-kimtag:de.mathworks.com,2005:Question/3001212016-08-19T06:20:07Z2016-08-25T17:29:29ZHow do I get my Activation key<p>I have been using the trial version but it expired a few days ago. I just paid for the full version. I should be able to activate matlab from the trial version but it is asking me for an activation key which I assumed I would have been given to me when I paid for it, but all they gave me was a link do download matlab, even though I already have it downloaded as a trial.</p>nicolas michaelhttp://de.mathworks.com/matlabcentral/profile/authors/8434703-nicolas-michaeltag:de.mathworks.com,2005:Question/3007112016-08-24T09:37:15Z2016-08-25T17:26:02Zhow to convert data in UTC to a specific local time<p>I have a one-year hourly data in UTC time. How do I convert the data to a specific local time say for example -5 UTC.</p>Saeed Bellohttp://de.mathworks.com/matlabcentral/profile/authors/4403257-saeed-bellotag:de.mathworks.com,2005:Question/3008762016-08-25T14:01:07Z2016-08-25T17:25:07ZLoop through multiple csv files<p>I have 2550 csv files. I have created a code that calculates a value for one of the files, but i need to loop over all 2550 and add together that value calculated for each csv file.</p>mcl1993http://de.mathworks.com/matlabcentral/profile/authors/5633381-mcl1993tag:de.mathworks.com,2005:Question/3009032016-08-25T17:23:14Z2016-08-25T17:23:14ZIs there a replacement script for "Movie_from_frames" that will generate avi files?<p>Since I can no longer use avifile(movie_file_name,'compression','None'), what is the replacement?</p>Dwight Swetthttp://de.mathworks.com/matlabcentral/profile/authors/3223812-dwight-swetttag:de.mathworks.com,2005:Question/3009012016-08-25T17:02:59Z2016-08-25T17:21:13ZIllegal use of reserved keyword "else".<pre class="language-matlab">if ( found )
[r, pclon, pclat] = cspice_reclat( point );
% Let re, rp, and f be the satellite's longer equatorial
% radius, polar radius, and flattening factor.
re = radii(1);
rp = radii(3);
f = ( re - rp ) / re;
[pdlon, pdlat, alt] = cspice_recgeo( point, re, f );
% Compute illumination angles at the surface point.
[phase, solar, emissn] = cspice_illum( satnm, et, ABCORR, scnm, point );
% Display results. Convert angles from radians to degrees
% for output.
fprintf( 'Intercept planetocentric longitude (deg): %11.6f\n',... R2D*pclon )
fprintf( 'Intercept planetocentric latitude (deg): %11.6f\n',... R2D*pclat )
fprintf( 'Intercept planetodetic longitude (deg): %11.6f\n',... R2D*pdlon )
fprintf( 'Intercept planetodetic latitude (deg): %11.6f\n',... R2D*pdlat )
fprintf( 'Range from spacecraft to intercept point (km): %11.6f\n',... dist )
fprintf( 'Range from spacecraft to target center (km): %11.6f\n',... norm(obspos) )
fprintf( 'Intercept phase angle (deg): %11.6f\n',... R2D*phase )
fprintf( 'Intercept solar incidence angle (deg): %11.6f\n',... R2D*solar )
fprintf( 'Intercept emission angle (deg): %11.6f\n',... R2D*emissn )
else
disp( ['No intercept point found at ' time ] )
end
</pre>Ujjal Deyhttp://de.mathworks.com/matlabcentral/profile/authors/5121831-ujjal-deytag:de.mathworks.com,2005:Question/3009022016-08-25T17:13:49Z2016-08-25T17:16:52ZHow to draw pareto front of my given code<p>Please help me to find pareto front of given objective functions. I am beginner in matlab so please give little explanation. If my question is not clear please let me know I will more explain. thanks</p><pre class="language-matlab">function [f]=task1(x)
clc
i=1;
pop_size=100;
V=13;
y=randi([0 1],pop_size,V);
y(:,2)=~y(:,1);
y(:,3)=~y(:,4);
y(:,5)=~y(:,6);
y(:,12)=~y(:,13);
while i:pop_size
x=y(i,:);
f(1)=15*x(1)+20*x(2)+30*x(3)+25*x(4)+40*x(5)+35*x(6)+35*x(7)+50*x(8)+20*x(9)+23*x(10)+30*x(11)+45*x(12)+50*x(13);
y(i,V+1)=f(1);
f(2)=5*x(1)+3*x(2)+4*x(3)+5*x(4)+4*x(5)+6*x(6)+5*x(7)+8*x(8)+5*x(9)+3*x(10)+2*x(11)+7*x(12)+6*x(13);
y(i,V+2)=f(2);
f(3)=6*x(1)+4*x(2)+2*x(3)+2*x(4)+3*x(5)+4*x(6)+4*x(7)+4*x(8)+2*x(9)+3*x(10)+3*x(11)+4*x(12)+3*x(13);
y(i,V+3)=f(3);
f(4)=2048*x(1)+1024*x(2)+256*x(3)+512*x(4)+256*x(5)+512*x(6)+1024*x(7)+1024*x(8)+512*x(9)+512*x(10)+256*x(11)+1024*x(12)+512*x(13);
y(i,V+4)=f(4);
a= [y(i,[14 15 16 17])];
i=i+1;
end
end
</pre>Asad Abbashttp://de.mathworks.com/matlabcentral/profile/authors/7681762-asad-abbastag:de.mathworks.com,2005:Question/2604542015-12-15T16:58:47Z2016-08-25T17:03:49Zavr-gcc.exe -Application Error The application was unable to start correctly (0xc0000142). Click OK to close the application.<p>I have problem in connecting matlab 2014a(64-bit) and arduino uno when I enter
>>a=arduino()
after some time it gives an error:</p><p>"Updating server code on Arduino Uno (COM3). Please wait." then</p><p>avr-gcc application failed dialog box appear with error code 0xc0000142 when I click ok then in command window appear:
"Cannot program Arduino board Uno (COM3). Please make sure the board is supported and the port and board type are correct."</p><p>my arduino port is com26.</p>Danish Anwarhttp://de.mathworks.com/matlabcentral/profile/authors/5313470-danish-anwartag:de.mathworks.com,2005:Question/3008712016-08-25T13:36:45Z2016-08-25T17:01:51Zcannot change the size of dicom image<p>Hi there,</p><p>I am trying some algorithms on jpeg image compression. I started from basic structures. For instance I take a jpeg image (uint8), apply dct transform, then quantization and idct to reconstruct the image. I obtained good results that I reduced 7MB to kilobytes. As you know i call "imread" and "imwrite" while reading and writing.</p><p>Then I wanted to apply this basic algorithm to a dicom image which has 29MB size. When I "imshow" the results I see the difference when compared to original image. Well, then I call "dicomwrite" the image. I see that the compressed image is still 29MB. Why is that?</p><p>I thought maybe this happens because the dicom image is in "uint16" form, on the other hand the quantization table is for 8bit images. However, I multiplied all the pixels of the original dicom by zero. So I have just a black image with the sizes of original image, then I write it. But the new image is still 29MB. So i think it is not about the compression algorithm.</p><p>Please help, I have to figure it out
Thanks in advance</p>Huseyinhttp://de.mathworks.com/matlabcentral/profile/authors/4374894-huseyintag:de.mathworks.com,2005:Question/1703632015-01-17T16:17:48Z2016-08-25T16:58:27ZPlot Surface when Z is not a function of X and Y<p>Hi everyone.</p><p>I am trying to plot my data in 3D surface.
However, it currently does not work since my <b>X,Y, and Z are independent.</b>
Z is not F(X,Y).
I also try to use meshgrid but still does not work.
The reason that I want to plot surface because my scatter plot points are trade-off.
Thus, if i can show it in surface, it will be easier to interpolate my trade-off.
Do I have any other ways to use surf function?</p><p>Thank you very much.</p>OoMhttp://de.mathworks.com/matlabcentral/profile/authors/3656365-oomtag:de.mathworks.com,2005:Question/3008992016-08-25T16:57:22Z2016-08-25T16:57:22ZSign difference between coeff=pca(X) and [~,~,v] = svd(X)<p>I am experiencing sign differences between my computations for principal component analysis using the pca function and the svd function. Consider this matrix:</p><pre class="language-matlab">X = magic(4)
X =
</pre><pre> 16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
coeff = pca(X) %this will automatically save only the first few principal components
coeff =</pre><pre> 0.5000 0.6708 0.4458
-0.5000 -0.2236 0.3573
-0.5000 0.2236 0.6229
0.5000 -0.6708 0.5344</pre><p>Now when I do svd, I get the following results.</p><pre class="language-matlab">x0 = bsxfun(@minus,X,mean(X,1)); %first center the data
[~,~,v] = svd(x0)
v =
</pre><pre> -0.5000 0.6708 -0.4458 -0.3182
0.5000 -0.2236 -0.3573 -0.7565
0.5000 0.2236 -0.6229 0.5586
-0.5000 -0.6708 -0.5344 0.1202</pre><p>So I get essentially negatives of the first and third principal component. Does anyone know why this is?</p>Noelhttp://de.mathworks.com/matlabcentral/profile/authors/4297820-noeltag:de.mathworks.com,2005:Question/3008612016-08-25T12:12:28Z2016-08-25T16:48:04ZMATLAB documentation claims that the output of rgb2ycbcr MATLAB inbuilt command is in the range [0, 1] for RGB input image of class double. However, its output is not in the mentioned range. Why?<p>I am using the following commands:-
A = imread('Lena_color_512.bmp');
Ad = double(A);
Aybr = rgb2ycbcr(Ad);
Intensity values of the 3-D matrix Aybr are not in the range [16/255, 235/255].
Can anybody tell the possible reason for this or is there an implementation error?</p>Sam Khttp://de.mathworks.com/matlabcentral/profile/authors/7720252-sam-ktag:de.mathworks.com,2005:Question/3008962016-08-25T16:24:41Z2016-08-25T16:45:22ZCompare pair of rows in a matrix<p>Suppose I have a Matrix like A = [12.05; 12.10; 12.25; 12.45] and I want to find difference between A(1) and A(2) then A(2) and A(3) and so on. Basically I am trying to compare time column and I have a huge data set with maybe 900,000 rows. I used a simple for loop which seems to take a very long time (naturally). Can you help me optimize this issue. Here's my code.</p><pre class="language-matlab">for j = 1:(length(usr)-1)
t11 = usr(j,5);
t22 = usr(j+1,5);
secs = fix((datenum(t22) - datenum(t11)) * 86400);
if (secs > 600 && secs < 1800)
placesLat = [placesLat;usr((j+1),2)];
placesLong = [placesLong;usr((j+1),3)];
end
end
</pre><p>Where <i>placesLat</i> and <i>placesLong</i> are just an array. I cannot assign memory before hand because I am not sure about the final result length.</p><p>Thanks in advance.</p>Neelabh Panthttp://de.mathworks.com/matlabcentral/profile/authors/7393498-neelabh-panttag:de.mathworks.com,2005:Question/3008982016-08-25T16:33:19Z2016-08-25T16:33:19Zcreating a 3d sphere (as a mask) on a 3D image<p>I am using a 3D raw image (size of PET image(float) is [84*71*103] with spacing size of 4.07*4.07*3 mm). what I want to do is, using the voxel coordinates that correspond to center of the tumor(defined by me) [116,177,86], create a sphere in which the center of a sphere will be the same as the center of the tumor. The diameter of the sphere I want to change to a maximum of a little bigger than the tumor itself. So the sphere is basically going to be serving as a mask which is overlaid with the image and I can get the statistics of the values of the image within that spherical shape. I hope I have made it clear enough. I would really appreciate your help.My code is not working correctly, I am very confused in how to proceed.
{</p><pre class="language-matlab">fid_1 = fopen('I:\PatientData\PET1_DIFF.img','r','l');
pet1_diff = fread(fid_1,'float32');
pet1_diff = reshape(pet1_diff, [84 71 103]);
pet1_diff = imrotate(pet1_diff,90,'nearest','crop');
figure(1);
imagesc(pet1_diff(:,:,30)); title('PET1_DIFF');
fclose(fid_1);
</pre><pre class="language-matlab">imageSizeX = 84;
imageSizeY = 71;
imageSizeZ = 103;
[columnsInImage rowsInImage pagesInImage] = meshgrid(1:imageSizeX, 1:imageSizeY, 1:imageSizeZ);
%creating the sphere in the image.coordinates of sphere center(tumor center)
centerX = 116;
centerY = 177;
centerZ = 86;
radius = 5;
sphereVoxels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 + (pagesInImage - centerZ).^2 <= radius.^2;
% sphereVoxels is a 3D "logical" array.
% Now, display it using an isosurface and a patch
fv = isosurface(sphereVoxels,0);
patch(fv,'FaceColor',[0 0 .7],'EdgeColor',[0 0 1]);
view(45,45);
axis equal;
title('Binary volume of a sphere')
}
</pre>Hodahttp://de.mathworks.com/matlabcentral/profile/authors/5393126-hodatag:de.mathworks.com,2005:Question/3008972016-08-25T16:31:00Z2016-08-25T16:31:00Zwheneve i want to install data "digilent" in matlab it says i get this message<pre> "annot download http://www.digilentinc.com/Data/Products/WAVEFORMS/digilent.waveforms_v2.4.4.exe:"</pre>umer farooqfasthttp://de.mathworks.com/matlabcentral/profile/authors/8046612-umer-farooqfasttag:de.mathworks.com,2005:Question/3008802016-08-25T14:46:27Z2016-08-25T16:30:54ZWhat is best practice to determine if input is a figure or axes handle?<p>I've been confused about MATLAB graphics since change to the new graphics system. I do not know how I can check for a variable being a handle to a figure or axes. Functions that come to mind are:</p><pre class="language-matlab">ishandle
isgraphics
ishghandle
isa(x,'matlab.ui.Figure') % x being the variable representing a Figure or Axes
isa(x,'matlab.graphics.axis.Axes') % wow, these really are cumbersome commands!
% etc.
</pre><p>What are best practices to ensure maximal compatibility with most MATLAB versions to detect what kind of input I'm dealing with? Why are there no</p><pre class="language-matlab">isfigure
</pre><p>or</p><pre class="language-matlab">isaxes
</pre><p>functions built-in?</p>Erikhttp://de.mathworks.com/matlabcentral/profile/authors/2298782-eriktag:de.mathworks.com,2005:Question/3008942016-08-25T04:00:00Z2016-08-25T16:19:02ZHow do I model a Bus Bar in Simscape Power Systems (SimPowerSystems)?<p>How do I model a Bus Bar in Simscape Power Systems (SimPowerSystems)?</p>MathWorks Support Teamhttp://de.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:de.mathworks.com,2005:Question/3007282016-08-24T11:35:40Z2016-08-25T16:18:26ZWhat Polyspace files should I archive along with source code, etc.?<p>At release time I archive all source code (*.cpp, <b>.h, etc.), make files (</b>.mak), final executable (*.exe), release notes, etc. into a code management system (e.g. ClearCase, git, etc.) I don't archive compiler intermediate files (*.bin, *.map, etc.) because they'd all be regenerated anyway. The idea is to create a complete but minimal snapshot of what I did that can be used to reconstruct the release from scratch.</p><p>What is the minimum file set I should archive for Bug Finder and Code Prover scripts? e.g. *.psprj, *.pscp, *.log, *.pdf (test reports from final run), etc.? That saves me from recreating the test setup and matches reports to version.</p>Scott Berghttp://de.mathworks.com/matlabcentral/profile/authors/7259353-scott-bergtag:de.mathworks.com,2005:Question/3000142016-08-18T11:10:24Z2016-08-25T16:11:12ZParpool slow with chol operation<p>Hi, I found a bottleneck in my code, and I can't understand what is happening.
I tried this in several computers and matlab versions (2014 and 2016) , and I found more or less the same pattern.</p><p>Suppose you have a large matrix operation, like a Choleski Decomposition of a large matrix. Well, if I parallelize across several cores (no matter how many, 4 ,8 ,16, regardless of the amount), I get that the single operation runs much slower.
Example:
Create this objects</p><pre class="language-matlab">z=randn(5200); Z=z*z'; zm=randn(1,5200);
</pre><p>open your parpool, and run a Chol. Decomp. in a parfor, you get for instance 3 seconds.</p><pre class="language-matlab">tic; parfor j=1:16; chol(Z,'lower'); end; toc
</pre><p>Now if you do the same in a standard sequential loop, you get the same result in similar time (or even a bit less)!!!</p><pre class="language-matlab">tic; for j=1:16; chol(Z,'lower'); end; toc
</pre><p>Why does this happen? What can I do to parallelize this code (my package does lot of things more than just a Choleski...) without penalizing so much the performance of a single task?</p><p>Many thanks in advance.</p>Francesco Chttp://de.mathworks.com/matlabcentral/profile/authors/4950204-francesco-ctag:de.mathworks.com,2005:Question/3007772016-08-24T18:51:56Z2016-08-25T16:03:10ZSending UDP Packets from Perl Script to SImulink<p>Hello Everyone ,</p><p>I have bunch of numbers which I get from a hardware which needs to be sent to Simulink via UDP-Ethernet connection.
I tried to use UDP Receive block in Simulink and exported the data to workspace. But I am not able to get any data .. What i get is all zeros.</p><p>Here is the sample Perl Script</p><pre> #!/usr/bin/perl
#udpclient.pl</pre><pre class="language-matlab">use IO::Socket;
use warnings;
use Time::HiRes qw (sleep);
</pre><pre class="language-matlab">my ($socket,$data);
#my $in_file_name = $ARGV[0];
$in_file_name='C:\Users\PQRST\Documents\Example.csv';
</pre><pre class="language-matlab">open(INFILE,"<",$in_file_name) or die "Not able to open test file $!";
</pre><pre class="language-matlab">$socket = IO::Socket::INET->new (PeerAddr => 'localhost',
PeerPort => 5005,
Type => SOCK_DGRAM,
Proto => 'udp') or die "ERROR in
+ Socket Creation : $!\n";
</pre><pre class="language-matlab">while (<INFILE>)
{
chomp;
if($. != 1) #skip first line
{
$data=$_; # Data would be in String format
</pre><pre> $socket->send("$data");
sleep(0.25);
} </pre><pre class="language-matlab">}
</pre><pre class="language-matlab">$socket->close();
</pre><p>Instead of directly running the script on hardware , I am just sending the data to myself ("localhost") and I am keeping '0.0.0.0' at port 5005 to receive data from all. Can anyone give me insight on this .. Any help would be appreciated...</p>A P Shttp://de.mathworks.com/matlabcentral/profile/authors/4801875-a-p-stag:de.mathworks.com,2005:Question/3008922016-08-25T15:46:55Z2016-08-25T16:01:18Zreadtable - renaming variables after creating<p>Hi,</p><p>I'm using readtable to read in and create a table of data in a text file. The way the text file is written there is no row containing the header names. Hence readtable names the columns Var1, Var2, ...</p><p>Is there a way of renaming these names to something more descriptive after the table has been formed?</p><p>Thank you</p>jlt199http://de.mathworks.com/matlabcentral/profile/authors/8271277-jlt199tag:de.mathworks.com,2005:Question/2768372016-04-03T07:53:22Z2016-08-25T15:59:40Z get this error when I try to install the data acquisition toolbox package on Matlab 2013a by the Support Package Installer:<p>I get this error when I try to install the data acquisition toolbox package on Matlab 2013a by the Support Package Installer:</p><pre class="language-matlab">Cannot download http://www.digilentinc.com/Data/Products/WAVEFORMS/digilent.waveforms_v2.4.4.exe: The server did not find a resource to match this request..
</pre><p>Does anybody know how to fix it?</p><p>Thanks in advance for any help.</p>zaid mohd ghanihttp://de.mathworks.com/matlabcentral/profile/authors/7852576-zaid-mohd-ghanitag:de.mathworks.com,2005:Question/3008932016-08-25T15:59:15Z2016-08-25T15:59:15ZSome of the plot elements are missing, when I change the linestyle<p>I was trying to make a nice plot contaning 2 lines, but when I change the linestyle for one of the lines, the label is not shown on the figure, also when I save the plot it does not save the values on the axis. But the funny thing is when I change the linestyle to another one(which is not suitable for me) it works fine. So here is my NOT working code:</p><p>ang1=AngleDifference.signals.values(:,1);</p><p>ang2=AngleDifference.signals.values(:,2);</p><p>t=AngleDifference.time;</p><p>plot(t,ang1,'r',t,ang2,'b--','LineWidth',2);</p><p>h_legend=legend('$q_1$','$q_2$');</p><p>set(h_legend,'FontSize',20,'Interpreter','latex');</p><p>set(gca,'FontSize',20);</p><p>xlabel('Time[s]');
ylabel('Angles[rad]');</p><p>grid</p><p>print('images\report\AngleDifference','-dpng')</p><p>And the working but NOT suitable:</p><p>ang1=AngleDifference.signals.values(:,1);</p><p>ang2=AngleDifference.signals.values(:,2);</p><p>t=AngleDifference.time;</p><p>plot(t,ang1,'r',t,ang2,'bo','LineWidth',2);</p><p>h_legend=legend('$q_1$','$q_2$');</p><p>set(h_legend,'FontSize',20,'Interpreter','latex');</p><p>set(gca,'FontSize',20);</p><p>xlabel('Time[s]');
ylabel('Angles[rad]');</p><p>grid</p><p>print('images\report\AngleDifference','-dpng')</p><p>The only difference between the two is that at the plot instead of 'b--' appears 'bo'. Any suggestion what could be the problem?</p>Zoltan Nagyhttp://de.mathworks.com/matlabcentral/profile/authors/8238457-zoltan-nagytag:de.mathworks.com,2005:Question/3008872016-08-25T15:18:32Z2016-08-25T15:55:22ZA problem with mvnrnd and mvnpdf<p>Hi, I am using mvnrd to generate samples for 100 examples. Then I use mvnpdf to evaluate the possibility of these samples. But the possibilities I got are all 0. I just want to get samples from multivariate normal distribution. Here is the code
H = mvnrnd(zeros(1, 620), eye(620), 100);
mvnpdf(H(1,:),zeros(1, 620), eye(620));</p>Lening Lihttp://de.mathworks.com/matlabcentral/profile/authors/6970380-lening-litag:de.mathworks.com,2005:Question/3008912016-08-25T15:42:27Z2016-08-25T15:42:27Zstudent version matlab for mac<p>Is there a student version of Matlab for mac users?</p>Lawrence Cheunghttp://de.mathworks.com/matlabcentral/profile/authors/8592969-lawrence-cheungtag:de.mathworks.com,2005:Question/3008852016-08-25T15:13:41Z2016-08-25T15:38:54ZAnybody know a work-around for plotting multiple-input anonomous functions with fplot ?<p>Hi. Sometimes I like to have anonymous functions that can take multiple inputs but not necessarily be multivariable.
For a trivial example, if I wanted to show how a decaying sinusoid changes with amplitude and frequency - I could do</p><pre class="language-matlab">syms x
myFun = @(A,w,x) A*cos(w*x)*exp(-w*x);
figure(1); ezplot(myFun(1,100,x),[-1,1]); axis tight
</pre><p>My function is still 1D, even though I have multiple inputs. This kind of works using EZPLOT, but sometimes the curve has regions that are blank ! It seems that FPLOT handles these issues better. Using FPLOT:</p><pre> myFun2 = @(x) 1*cos(100*x)*exp(-100*x);
figure(2); fplot(myFun2,[-1,1]); axis tight</pre><p>FPLOT gives good result, but I cannot use the multiple-input function.</p><p>I guess that the best way to solve this issue would be to use a MATLAB function that takes the anonymous function as an argument and returns a string that can be used as the input-function for FPLOT. Any ideas ?</p>Ronny Landsverkhttp://de.mathworks.com/matlabcentral/profile/authors/3787340-ronny-landsverktag:de.mathworks.com,2005:Question/3003602016-08-21T17:11:10Z2016-08-25T15:26:27ZHow to connect NIKON DSLR camera to matlab?<p>hi, i have nikon D90 camera and i would like to connect it with matlab for doing live video streaming. But matlab doesn't detect the camera. The hardware browser of image acquisition tool doesn't show the device name. what should i do.? pls help out.</p>sajeesh chttp://de.mathworks.com/matlabcentral/profile/authors/8512277-sajeesh-ctag:de.mathworks.com,2005:Question/3008902016-08-25T15:25:42Z2016-08-25T15:35:19Zvpasolve for nonlinear system of equations instead of fsolve for complex valued results <p>I have nonlinear 2 quite complex equations for 2 unknowns. At first, I used fsolve. But, because the equations are complex valued, I was taught vpasolve should be used instead of fsolve.</p><p>The following is the code for this problem.</p><pre class="language-matlab">X = sym('x', [1,2]);
T = 1/100;
F = torder1(X,T);
sols = vpasolve(F, X);
sols.x1
sols.x2
</pre><p>Below is torder1.m function called from above script.</p><pre class="language-matlab">function F=torder1(x,T)
x_1=[0:0.01:1];
b=0.6;
</pre><pre class="language-matlab">syms x_1 h theta
</pre><pre class="language-matlab">f_11 = 1-( (h+(x_1-b)*theta)^2/(h+(x_1-b)*theta-1*x_1*(1-x_1))^2 );
f_21 = (x_1-b)/2*( 1-( (h+(1-b)*theta)^2/(h+(x_1-b)*theta-x_1*(1-x_1))^2 ));
</pre><pre class="language-matlab">fint_1 = int(f_11, x_1);
fint_2 = int(f_21, x_1);
</pre><pre class="language-matlab">x_1=1;
upper_1=subs(fint_1);
upper_2=subs(fint_2);
clear x_1;
x_1=0;
lower_1=subs(fint_1);
lower_2=subs(fint_2);
clear x_1;
integral_result_1old=upper_1-lower_1;
integral_result_2old=upper_2-lower_2;
</pre><pre class="language-matlab">h0 = kappa *b*(1-b);
theta0 = kappa*(1-2*b);
</pre><pre class="language-matlab">integral_result_1 = subs(integral_result_1old, {h, theta}, {x(1), x(2)});
integral_result_2 = subs(integral_result_2old, {h, theta}, {x(1), x(2)});
%
% expression1 = double(x(1) - integral_result_1*T^2 -h0);
% expression2 = double(x(2) - integral_result_2*T^2 - theta0);
</pre><pre class="language-matlab">F = [x(1) - integral_result_1*T^2 -h0;
x(2) - integral_result_2*T^2 - theta0];
</pre><pre class="language-matlab">% F = [double(x(1) - integral_result_1*T^2 -h0);
% double(x(2) - integral_result_2*T^2 - theta0)];
</pre><p>The errors are two types:</p><p>If I use F with double inputs inside torder1.m, when I run the script I get</p><p><b>DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.</b></p><p>If I use F without double arguments inside torder1.m, I get :</p><p><b>CAT arguments dimensions are not consistent.</b> error.</p><p>You might would like to see earlier question related to this problem</p><p><a href = "http://uk.mathworks.com/matlabcentral/answers/300450-matlab-limitation-in-fsolve-using-function-input#answer_232497">http://uk.mathworks.com/matlabcentral/answers/300450-matlab-limitation-in-fsolve-using-function-input#answer_232497</a></p><p>Looking forward to hearing any help.. Thanks.</p>Mevahttp://de.mathworks.com/matlabcentral/profile/authors/4934134-mevatag:de.mathworks.com,2005:Question/3008892016-08-25T15:22:11Z2016-08-25T15:22:11ZIs there a function in Matlab that is similar to "cumtrapz" but uses a more accurate method of array integration (such as Simpson's rule)?<p>Is there a function in Matlab that is similar to "cumtrapz" but uses a more accurate method of array integration (such as Simpson's rule)? (i.e., to integrate a nonanalytic function (represented by an array))</p>Neil Gelmanhttp://de.mathworks.com/matlabcentral/profile/authors/1763392-neil-gelmantag:de.mathworks.com,2005:Question/3008042016-08-24T22:44:07Z2016-08-25T15:21:34ZI wrote my own code to find correlation coefficient, but the results are wrong. Why?<p>Hi guys,</p><p>I wrote a code to calculate correlation coefficient among my 76x4000 matrix. Basically I want to test for the correlation coefficient within the 76 rows. My end result should be a 76x76 matrix with 1s on the diagonal line and it being symmetric. My codes managed all this, but my result seem wrong, can someone please check it for me please. Thank you.</p><pre class="language-matlab">function T = colerrationcoefficient(P)
</pre><pre class="language-matlab">for i = 1:76
</pre><pre> for j = 1:76</pre><pre> w = 0;</pre><pre> if i~=j</pre><pre> s = cov(P(i,:),P(j,:));</pre><pre> t = s(:,2);</pre><pre> u = std(P(i,:));</pre><pre> v = std(P(j,:));</pre><pre> w = t/(u*v);</pre><pre> end</pre><pre> T = [T;w];</pre><pre> end</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">end
</pre><p>Thank you!</p>Lakynhttp://de.mathworks.com/matlabcentral/profile/authors/4891608-lakyntag:de.mathworks.com,2005:Question/3008882016-08-25T15:20:02Z2016-08-25T15:20:02ZHow can i plot 3D Time domain signal in simulink?<p>I wish to see the time domain signal in 3D in simulink
Appreciate your time
Thanks</p>Sivaprakash Jayacandranhttp://de.mathworks.com/matlabcentral/profile/authors/8545862-sivaprakash-jayacandrantag:de.mathworks.com,2005:Question/3008862016-08-25T15:18:06Z2016-08-25T15:18:46ZI want to smooth the edges of the mammogram and remove the line. <img src = "/matlabcentral/answers/uploaded_files/58337/Untitled.png">vidhttp://de.mathworks.com/matlabcentral/profile/authors/8142423-vidtag:de.mathworks.com,2005:Question/823572013-07-17T14:35:11Z2016-08-25T15:17:23Zwhere to get a activation key?<p>where to get a activation key?</p>yinxia zhuhttp://de.mathworks.com/matlabcentral/profile/authors/4433524-yinxia-zhutag:de.mathworks.com,2005:Question/3008782016-08-25T14:23:49Z2016-08-25T15:14:37Zbvp with constant vector in function definition<p>My problem seems simple:
U''(r)=-4*pi*r*n(r)
where n(r) is a constant 1d-vector
In addition I have the boundary conditions:
U(0)=0 and U(r_max)=c, where c is a constant.</p><p>I've tried the following:</p><pre> f = @(r,U) [ U(2); -4*pi.*r.*n];
g = @(ya,yb) [ya(1); yb(1)-c];</pre><pre> solinit=bvpinit(linspace(0,r_max,10),[0 0]);
sol = bvp4c(f,g,solinit);</pre><p>In case n is just a number it works...
For n being a vector it doesn't and i get the error:</p><pre class="language-matlab">Error using vertcat Dimensions of matrices being concatenated are not consistent.
</pre><p>Is there any way to include vectors in my function definition?</p><p>Thanks in advance.</p>jsmith999http://de.mathworks.com/matlabcentral/profile/authors/8592391-jsmith999tag:de.mathworks.com,2005:Question/3007932016-08-24T20:35:10Z2016-08-25T15:14:01ZHow do I find the index of a datapointon a MATLAB plot?<p>With a very large dataset - assume 1 million [x,y] pairs or more - how do I find the <b>index of an individual datapoint</b> on a MATLAB plot?</p><p>Example: I use plot(x,y) and the plot appears. The plot is complicated but there are artifacts I can locate by eye much easier than writing a detection script. I zoom into the plot and locate the desired data artifact. I need to know the exact location (index) of the artifact. I zoom that individual datapoints are apparent, place a cursor on the datapoint of interest, but the cursor does not report the exact x(index) of the datapoint. Other than manually scrubbing through the data to find the index, how do I find the index by using the plot?</p>S. Moorehttp://de.mathworks.com/matlabcentral/profile/authors/2672377-s-mooretag:de.mathworks.com,2005:Question/3008062016-08-24T23:18:52Z2016-08-25T15:00:35ZSetting number of clusters on clustergram object<p>Hi,
I'm using the clustergram tool to group some data. I know a priori how many groups I want to classify the data into. Is there a way to set the number of clusters that the clustergram object makes? I know it is possible to set the number of nodes with the dendrogram setting, but this is not working very well for me.</p><p>Thanks,</p><p>Avi</p>Avigdorhttp://de.mathworks.com/matlabcentral/profile/authors/3660154-avigdortag:de.mathworks.com,2005:Question/3001912016-08-19T16:12:13Z2016-08-25T14:55:51ZCompute goodness of fit (gof) out of sfit-object and fitting data<p>Hi,</p><p>I used the Curve Fitting Toolbox to find the parameters of a parametric 3D-surface that matches measured data. After computing a possible solution for the parameters, I only saved the sfit-object, but forgot to also save the gof-struct. What I would like to do is to compute the gof-struct out of the sfit-object and the data used for fitting. Is there any MATLAB function that already does that?</p>Rodrigohttp://de.mathworks.com/matlabcentral/profile/authors/3780681-rodrigo