- Re: instead of For loop
Hi, Sorry, my actual target equation is too complicated to ask.. So, I wanted to simplify.... How about below ? The point is , I want to sum up by "k", "m", "n". Σ(k:1->999)Σ(n:1->999)Σ(m:1->9 99) (n-m)/k Cheers, K - little question
Hi, I've a little question. After typing this in the Command Window: >> list= line(1, 3, 4, 5) How can I let the outcome exactly become like: list = 1 3 4 5 in stead of a = 1 b = 3 c = 4 d = 5 ?? Thanks in advance. - Re: Gamma Function & Imaginary argument
Thanks Sadik, I think this will work with a little bit of editing. Cheers, Eric - Re: periodogram function
Hi Tideman, I'm pretty sure it does it that way, but you're definitely making me think, which is always good :) Anyway, here's what I think it's doing with an example reset(RandStream.getDefaultStr eam); x = randn(10,1); nfft = 5; win = hamming(10); y = x.*win; %Periodogram with nfft less than segment length - Re: Problems with plotting lines and curves
Hi Andrew, Why not collect the line and the curve in two separate vectors? You should also collect the corresponding depth info so that you will say: plot(hLine,linePoints) hold on plot(hCurve,curvePoints,'r') or something like that. Best. - Re: function
Hi, You should start an m file [that is, a file with extension .m] with the keyword function, then you should have no problems at all. The reason you are getting this error could be because: 1) You are typing this in the command window. To avoid this, please type edit newFunction or some other name. This will open the Editor, where you will see a blank page to write whatever code you would like. - Re: Gamma Function & Imaginary argument
Hi Eric, 1) I am sorry, I don't know. 2) mcgama.m on page [link] should work for you. Best. - Structure help
G'day, I have the following code... A = [1,2,3,4,]; %%%% DATA %%%% lon = [-123.412482300000, -123.349197000000, -123.387645500000,-123.4991961 00000]; lat = [48.1177411000000,48.117043800 0000,48.1850616000000,48.26613 00000000]; N = length(A); [test2(1:N).Geometry] = deal('Point'); %%%%% Create Structure %%%%% - function
Hi, I recently downloaded Matlab and have the following problem If I code a simple code on function, e.g. "function y=poly(x,a)" Matlab gives me an error message "Error: Function definitions are not permitted at the prompt or in scripts." Can anyone please let me know as to what is happening?? Any help is deeply appreciated. - Gamma Function & Imaginary argument
Dear Matlab community, I would like to use an imaginary input argument in the provided gamma function to test out a theory from literature. However, when I put the my argument in, gamma(1/2+i*omega), I received the following error. ??? Undefined function or method 'gamma' for input arguments of type - Re: making local variable global
============== Are you sure you need to do this? No matter how huge your data is, as long as you never make any changes to it, you can pass it around freely to functions and MATLAB will not make any deep copies of it. Make sure you are familiar with the material here [link] - Re: How to achieve ultimate summing speed?
Yes, I am aware of that technique but hadn't thought of it for this application. Thanks for pointing it out. I don't know how much difference it will make, however, but I will try to run some tests later. I have made previous attempts at speed improvement tests like this using mxMalloc (I was attempting to create a fast C mex preallocation routine that didn't zero out the memory) but have noticed that mxMalloc (or a previous mxFree) *always* zeroes out the memory. I made this conclusion after allocating very large blocks, setting all the elements to non-zero, freeing the memory with mxFree, and then immediately using mxMalloc again to grab the exact same block of memory and noting that all the memory is suddenly zeroed out. Don't know if it is mxMalloc or mxFree that is doing it. Bottom line is using mxCreateDoubleMatrix with 1 x n vs creating 0 x 0 and then mxMalloc for the memory may *still* drag the memory through the cache once to get the memory set to zero and you may not have any control over this. This may be a security design in the MATLAB memory manager, or something else. I will - Re: instead of For loop
You appear to be missing a character or expression inside the exp(), between the - and the * . If it is a simple expression such as the constant 2, then you are not going to be able to calculate that sum except symbolically, as it would involve adding numbers that range from exp(-1996002) to exp(1996002) . - matlab multiprocessing
Hi, I have a simulation scheme in Simulink which periodically calls m-file (block MATLAB Fcn). In the m-file an image is loaded from IP camera and processed. The result is send back to simulink scheme and used for controlling a model. My problem is that loading from IP cam takes a lot of time. It is quicker to read it from HDD. I would like to have a parallel loop where an image would be loaded from IP cam repeatedly and saved to HDD as a jpg file. Nothing more. - Re: Vectorization
Check out MTIMESX by James Tursa, it's even better than NDFUN for multiple-matrix product. [link] Bruno - Re: please help : ??? Index exceeds matrix dimensions.
Dear Leclerc! No problem! It's me who's obviously unsuccessful with pleasing the debugger. Jan - Re: Vectorization
How did you get ndfun to work in 64 bits? I tried pointing mex to the blas and lapack libraries included in $MATLABROOT/bin/glnxa64 (I am using the 64bit linux version) and after fixing one or two of the comments it compiles. However, it segfaults whenever I run it. - Re: please help : ??? Index exceeds matrix dimensions.
Musste eben lachen, als ich das gelesen hatte. You can please the debugger kam etwas unklar bei mir an - du kannst dem Debugger eine Freude machen... mag er lieber Rosen oder Schokolade? Grüsse - Re: How to achieve ultimate summing speed?
For this simple iteration over each column, with no dependencies between each one, the easiest way (IMHO) to parallelize this is with an OpenMP pragma before the first (outer) for loop. And it's completely platform independent. Oliver - Re: making local variable global
I know I can. What I'm worried about is that the message says this ability to turn local variable into global will be discontinued in the future. So I'm looking for an alternative way doing it. - Re: how to avoid a double for loop
You might try this. It uses only one call to 'unique'. The result is placed in B. T = A.'; p = T(:,1)==1; T(p,:) = 1-T(p,:); % Complement T rows that have 1 in first col. [t,m,t] = unique(T,'rows'); % Reduce to unique T rows ('last') B = A(:,sort(m)); % Reduce to corresponding cols. in A Roger Stafford - Re: instead of For loop
Are you sure the sum isn't supposed to range over positive n-m? Otherwise, you're inevitably going to get inf as the result (as Oleg did in his version of the calculation). - Re: How to achieve ultimate summing speed?
James, I'm surprised a speed demon like you is using mxCreateDoubleMatrix like that. Since it sets the matrix to zero first it drags the whole matrix through the cache once, before you even write to it. Since you then set every entry later you don't need to do that. See a discussion on the subject, and solution, here: - displaying "half" of a 3d plot
Hi guys, I would like to display only half of a 3d plot to show some details of the functions. More specificly, I want to make a diagonal cut through the 3d plot, and only display one half. I could get it to work using plot3, but I really would need to represent a surface. That's what I came up with so far: - Re: periodogram function
Wayne Are you sure about this? I thought it transferred all the segments to the freq domain (using FFT), squared (to get PSD), then took the mean. If you do this in the time domain, as you suggest, you could conceivably cancel the signal before it gets transformed. - Re: please help : ??? Index exceeds matrix dimensions.
Hi, I do apologise, I didn't want to offend anybody, I just tried to make a (obviously unsuccessful) joke of entering discussion in the language I don't speak. cheers, Gordan - Re: Logging number of computations and memory ussage
That depends on how you define "effective". If you have a machine with very little memory, but you can start the program running when you leave for the night and get the results when you return in the morning, "effective" would mean "memory efficient". On the other hand, if you need results RIGHT NOW - Re: instead of For loop
You *will* have to use a for loop. You might hide that fact behind the voodoo of 'vectorization', but the for-loop will be there, nonetheless. Apart from that, depending on the details that are missing (the '-*' somebody already commented on) you might be able to simplify the expression a bit, possibly being able to exploit symmetries etc. - Re: instead of For loop
That is why I requested the actual code. If the OP *doesn't* get inf, then what was posted above in non-MATLAB notation is incorrect or something else is wrong. The OP claimed that the FOR loops were taking a long time, which seems to imply that there was some value being produced which was not inf. I guess we shall see ;-) - Re: instead of For loop
Well, one of the terms look like exp(-(0-999)*999) = exp(999*999) = inf. So here is how to calculate the entire sum without any for loops: inf What are you doing? James Tursa - Re: instead of For loop
I interpret it as -1*(n-m). I implemente it as: Out = sum(exp(reshape(-bsxfun(@times ,bsxfun(@minus, (0:999).',0:999),0:999),[],1)) ); which gives inf... I'm sure it's some form of note matrix...but I'm not a matematician. Oleg - Re: periodogram function
Hi, what it means is that it divides the data into nonoverlapping segments of length NFFT, possibly padding the last one with zeros if a case like you describe holds. Then it stacks those segments and adds them together to form a length NFFT segment. So for example: X=1:20; NFFT=10; Y = buffer(X,NFFT); - Re: instead of For loop
Why don't you post the actual FOR loops instead of the above? What does this mean: -*(n-m) - remove space between tiles in plottools
I am looking for a way to collapse subplot tiles in plottools so that the axes touch. - Re: contour plot?
Hi Carl, if you read the section in the MATLAB User's Guide called "The Contouring Algorithm", it explains exactly what it's doing. Look under User's Guide -> Graphics -> Creating Specialized Plots -> Contour Plots Hope that helps, Wayne - Re: Image analysis: point regrouping
Oops, sorry for the format. 0 x 0 0 y 0 0 z 0 -> 0 1 0 0 1 0 0 z 0 -> 0 1 0 0 2 0 0 2 0 - Re: Sorting a Cell Array
"Chmical" sort by first col (trsnforming num2str). sortrows(cellfun(@num2str, test(2:end,:),'un',0),1) If you have the statistics tb use the dataset object. Oleg - Re: Image analysis: point regrouping
Hey and thanks for your tips! 1) Here's my code for building a rectangle size r around each nonzero point in matrix. [row,col]=find(matrix); rect_matrix = zeros(size(matrix)); disp(' Connecting sinks ...'); for k=1:length(row) for i=(row(k)-r):(row(k)+r) rect_matrix(i,col(k)-r:col(k)+ r)=1; - instead of For loop
Hi, Please advise how to program following equation without For loop Σ(k:0->999)Σ(n:0->999)Σ(m:0->9 99) exp(-*(n-m)*k) If I use For loop, it takes forever... Cheers, K - Problems with plotting lines and curves
Hi, I'm fairly new to Matlab and am having some problems with plotting functions. I've got two functions that I want to plot. One is a line, the other is a negative exponential curve. Both functions are calculated with depth simultaneously, but I only want to display one of the functions at each given depth (i.e. when the line function has a value less than that of the curve, I want it to plot the line, but when the curve becomes less than the line, I want to only plot the curve). - Sorting a Cell Array
I have a cell array with a header row and column made up of both numbers and letters. I would like to do a normal sort (like you would do with Excel). Is there a way to accomplish this? I have tried the normal (in the help) sort functions with no luck. Example array test = {'PC','S','PO';84938,'O','Q34e f3';84548,'P','Q34g53';84248,' O','Q37h93';}; - R2010a stable?
Anyone else having stability issues with 2010a? I've crashed it 7 or 8 times in the first 2 days, versus once a week or so with 2009b. - Re: Logging number of computations and memory ussage
Hi Thank you very much for the deep explanation. I can see now that it is not as easy as i thought. But how would you then examine which code is the most effective? Because measuring the time of execution will also depend on other operations of the CPU, and not just my piece of code? Is there a general way to determine the quality of some code then? - Re: Changing class of object
I came upon this post by searching on the "object class must be preserved" message. It's not a particularly clear message, and had me chasing my tail for a while. After a lot of thought and reading of the docs (and previous posts), it started to make sense. You can't pass a subclass object to a parent class constructor from within the subclass constructor. For instance if you have a Person class and a Man subclass, you can't pass the "in construction" Man object to the Person constructor. The Man object is not fully instantiated until it exits its constructor. This especially makes sense for value classes. - contour plot?
In the help file it says: "contour(Z) draws a contour plot of matrix Z, where Z is interpreted as heights with respect to the x-y plane" I have tried this: Z = [2 3 3; 1 2 0]; [C,h] = contour(Z) clabel(C,h); which give me this: [link] But how does those line corresponds to elements in Z? From the help file its - Re: Combining/Overwriting structs
============== Careful. Since catstruct() will always consolidate the fields, it means that it will be susceptible to typos and spelling mistakes. For example, if default.color='k', but someone inputs an option accidentally using a British spelling like options.colour='g', then default.color will not be overwritten. - Re: Combining/Overwriting structs
Yup, there is catstruct.m to be found on the file exchange: [link] HTH. Bjoern - Displaying SimEvents (Simulink) simulation time
Hello, Just getting started with SimEvents (and hence Simulink). For some debugging purposes, how can I display the current simulation time to the regular Matlab workspace from inside an Embedded Matlab function? Right now I can show the value of some variables during run-time by making "disp" extrinsic. After doing that I can write "disp(variable)" in my Embedded Matlab code and the value of 'variable' will show up in my regular workspace each time the Embedded function is triggered. To make that info really useful I'd like to write out the current simulation time to my Matlab workspace each time the Embedded Code executes. I guess I can use disp, but I don't know what the current simulation time is called programmatically. - periodogram function
When using the periodogram function matlab states in its help file that "periodogram uses an nfft-point FFT of the windowed data (x.*window) to compute the periodogram. If the value you specify for nfft is less than the length of x, then x.*window is wrapped modulo nfft. If the value you specify for nfft is greater than the length of x, then x.*window is zero-padded to compute the FFT." - Re: spectral analysis dosent like NaNs
It sounds to me as if you are _not_ attempting to do a fourier analysis, but rather that you are attempting to do a discrete fourier transform (DFT) of regularly sampled data that has NaN's in place of some of the data. If you search through the back postings, there are some references on how to perform a dft on irregularly spaced data... it isn't the easiest of tasks, but |