Search Comments and Ratings

go

   
Date File Comment by Comment Rating
05 Nov 2013 COMBINATOR -combinations AND permutations Returns 1 of 4 different samplings on the set 1:N, taken K at a time. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Alesya,

That is a memory limitation on your computer. You are asking MATLAB to build a matrix that is (5^13)-by-13. This is a matrix with nearly 16 billion entries. In double precision this would require over 100 GB of RAM!

You probably need to do something different for your particular application.

Comment only
05 Feb 2013 gaussleg Calculates the integral of function f from a to b using ngp Gauss points. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Giuseppe, what are you talking about??

>> f=inline('sin(x)/x');
>> gaussleg(f,-1,1,8)

ans =

1.8922

>> f=@(x) sin(x)./x;
>> gaussleg(f,-1,1,8)

ans =

1.8922

>> version

ans =

7.14.0.739 (R2012a)

Comment only
15 Jan 2012 MATLABTETRIS Another MATLAB version of the classic game, Tetris. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Thanks for your comment Mingjing! I am surprised that the game is sluggish on your laptop, as I tested it on 3 laptops out of concern over its graphics-intensive nature. I guess my sample was too small!

One of the goals in making the game was to be able to have everything in one file, which is why I didn't use an image (or any of the other approaches I could have). Now I wonder if I could created the image from repmatting a hard-coded matrix inside the file? I will look into this in the coming weeks when I get time, and see if it speeds things up at all. Thanks for the idea!

Comment only
13 Jan 2012 Band matrix generation Generates a band matrix Author: Catalin Serban

Catalin Serban

Matt Fig

Matt Fig

Caitlin, why did you submit two identical files? Did you do this by mistake, perhaps?

Also, you really should at least familiarize yourself with the ONES function in MATLAB, it would be most useful in your function...

Comment only
01 Jul 2011 Choosse randomly number of elements from a vector Choosse randomly a number of elements from a vector. Randomly change the position of the vector Author: Dave Correa

Dave Correa

Matt Fig

Matt Fig

Jan, you are absolutely correct. I made a mistake in understanding what this was supposed to do. Thanks for the catch.

Good thing I didn't provide a rating!

Comment only
30 Jun 2011 Choosse randomly number of elements from a vector Choosse randomly a number of elements from a vector. Randomly change the position of the vector Author: Dave Correa

Dave Correa

Matt Fig

Matt Fig

Why not use the simpler:

out = ini + ceil((fin-ini)*rand(1,num));

Comment only
30 Jun 2011 sahil_tar sahil_tar Author: sahil

sahil

Matt Fig

Matt Fig

Please delete this and ask your question on MATLAB Answers. The FEX is not a place to ask questions like this...

1
21 Jun 2011 How fast is your graphics card? Creates a challenging 3-d benchmark for graphics processing speed measurement. Author: Michael Kleder

Michael Kleder

Matt Fig

Matt Fig

That should say:

i7-2920xm processor

I don't know where I got that other number?

Comment only
21 Jun 2011 How fast is your graphics card? Creates a challenging 3-d benchmark for graphics processing speed measurement. Author: Michael Kleder

Michael Kleder

Matt Fig

Matt Fig

7.14 RPM
Windows 7 64-bit, 8 GB RAM
r2007b
Thinkpad w520
i7-940XM processor
Invidia Quadro 2000M

Blow my old Dell (see above) away!

Comment only
16 May 2011 showcontextmenu Simple way to show contextmenu on left click in a nice drop-down way. Author: Igor

Igor

Matt Fig

Matt Fig

This function will error on versions of MATLAB which do not have ASSERT. For example 2006a.
Also, if the handle of the object does not have a 'units' property, the function errors. A line, for example, may have a uicontextmenu, but does not have a 'units' property.

Comment only
13 May 2011 axescenter Puts axes in the center of a plot. Zooming, panning and some command line manipulations allowed. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Hello Robert,

There is no guarantee the axes go through the origin with any plot. This will depend on the data. But if the data is so centered, axescenter will go through the origin. Also, I cannot reproduce your claim about the xlabel. For example:

subplot(1,2,1)
plot(-10:10) % Origin-centered data
axescenter
xlabel('X Label') % Correctly placed!
subplot(1,2,2)
plot(-pi:.1:pi,cos(-pi:.1:pi))
axescenter
xlabel('X Label2') % Correctly placed.

Please email me if with some code to reproduce what you are seeing...

Comment only
13 Apr 2011 LINECMENU Utility for creating a standard uicontextmenu for line objects. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Great idea Oleg, thanks! I have submitted an update.

Comment only
24 Mar 2011 BPSK BER simulation correlative detector for BPSK signal Author: Bogdan Mikhailets

Bogdan Mikhailets

Matt Fig

Matt Fig

There is no mention that the communications toolbox is required. The files will not run as-is, for MATLAB doesn't recognize filenames which begin with a number. Rename the files! Also, why use scripts? Finally, please pre-allocate your variables instead of growing them in a FOR loop. This makes your code unbearably slow.

2
01 Mar 2011 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

To fremond,

What do you mean, "open" the file? For editing? Just type:

>> edit GUI_1

If you have other problems, please email me instead of using the ratings area.

Comment only
03 Jan 2011 ChooseK All pairs intersecting on k-1 tuples from all possible k-tuples of n objects Author: Bruno Luong

Bruno Luong

Matt Fig

Matt Fig

There is no mention of the need for MERGESA other than the error message I see when trying to run the file.

Other than that, this is a nice recursive solution to the combinations without replacement problem.

Comment only
04 Dec 2010 TRIGDEMO Allows user to see how parameters affect plots of trigonometric functions. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Good idea Oleg. I seem to remember thinking I should do this when I wrote it, but rejecting the idea for some reason. I will think about it some more and update the file if I can't remember my initial reason for rejecting this idea.

Comment only
28 Sep 2010 Golden Ratio Computes the golden ratio. Author: Kurt

Kurt

Matt Fig

Matt Fig

While I see and acknowledge Mark's point, I do think this could be useful. For example, one could also use 2*asin(1) for pi and yet it is still useful to have a PI function. One may forget the formula, for instance, and looking it up is slower than just using the function.
However, this advantage is taken away somewhat by the function name. I think I am about as likely to remember to call GoldenRatio exactly (two capital letters, no underscore, etc.), as I am to remember the formula. Why not just call the function phi?
Also, I think that using PERSISTENT makes the function slower than it needs to be. Storing, retrieving, and checking for the existence is likely to be slower than just doing a simple calculation every time. In fact:

>> tic,for ii = 1:5000,T = GoldenRatio;end,toc % original
Elapsed time is 0.107390 seconds.
>> tic,for ii = 1:5000,T = GoldenRatio;end,toc % One-line
Elapsed time is 0.052342 seconds.

Comment only
09 Sep 2010 rotation rotation of two dimensional shapes Author: aasim Azooz

aasim Azooz

Matt Fig

Matt Fig

Did you know about the MATLAB function ROTATE?

Comment only
10 Aug 2010 COMBINATOR -combinations AND permutations Returns 1 of 4 different samplings on the set 1:N, taken K at a time. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Oops, that was an error of omission on my part. I will post an update. Thanks Jan.

Comment only
16 Jun 2010 cell2char Function to convert a cell array of strings into a character array. Author: Tonatiuh Pena Centeno

Tonatiuh Pena Centeno

Matt Fig

Matt Fig

I see, your code handles cells like this:

C = {'poss';'pess';'asdf';NaN;44;pi;'cookie'}

So it is the description you give that needs fixing. It does more than convert the contents of a cell array of strings. It converts the contents of a cell array of strings and/or numbers. However, couldn't your entire algorithm be replaced with this?

S = char(cellfun(@(x) num2str(x),C,'Un',0))

Comment only
16 Jun 2010 cell2char Function to convert a cell array of strings into a character array. Author: Tonatiuh Pena Centeno

Tonatiuh Pena Centeno

Matt Fig

Matt Fig

Maybe I missed it, but what does CELL2CHAR(C) do that CHAR(C) does not do? And CHAR is a built-in!

Comment only
10 Jun 2010 CHECKVARS Checks for function masking by variables in an M-File. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

It was brought to my attention that there are a few short-comings in the file. The file will be updated shortly.

Comment only
21 May 2010 Anti-diagonal matrix traversal This function allows you to traverse a square matrix along the anti-diagonal. Author: Loïc

Loïc

Matt Fig

Matt Fig

As it is, you have some deficiencies. There is no H1 line. The help is non-standard in its location. There is no input checking: if the function is for square matrices then you should check to see if the input is square. Your algorithm works well, except you cripple the speed by not pre-allocating your return arrays before the loops. Look at the difference:

>> M = round(rand(400)*300);
>> tic,[P,Q]=diagtrav(M);toc % No pre-allocation
Elapsed time is 134.937511 seconds.
>> tic,[P,Q]=diagtrav(M);toc % With pre-allocation
Elapsed time is 0.014006 seconds.

You should pre-allocate the return arrays!

Comment only
19 May 2010 A more short code forgenerating a random matrix A of (1,-1); A more short code for generating a random matrix A of (1,-1),no loop Author: Binbin Qi

Binbin Qi

Matt Fig

Matt Fig

A general, ND version could look like:

function A = randmatrix(varargin)
A = floor(rand(varargin{:})*2)*2-1;

The 2D limitation, in addition to the need for usable help, a more descriptive name (something like RANDSIGNONES at least describes more closely what the code produces), and an H1 line prevent the file from being that useful as it now stands.

Comment only
12 Apr 2010 Sort Matrix Elements with Positions A function to sort values of the matrix elements, providing their positions in original matrix. Author: Kadir

Kadir

Matt Fig

Matt Fig

There is no help, and no real H1 line in this file. Why not use the faster engine:

[As,Y] = sort(A(:));
[Y,c] = ind2sub(size(A),Y);
Y = [As,Y,c];

Comment only
29 Mar 2010 NFACTORK Find all factorings of N which have K elements. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Thanks for the ideas, I will submit an update on the bug.

Comment only
29 Mar 2010 NFACTORK Find all factorings of N which have K elements. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

John,
Thanks for your comments. It is true that the code is slow for numbers with many factors, as is mentioned in the help. At present I see no way around this with the current algorithm, but I will keep looking for ways to improve this. Any suggestions are welcome!

Comment only
04 Mar 2010 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Lorenzo and Jie,
There are many ways to do the same thing in MATLAB! The approach I would have taken in solving the S.E. for GUI_2 involves adding only one line of code, and no call to PAUSE. Feel free to email me if you have more questions.

Comment only
09 Feb 2010 Password GUI It is a gui, with a dialogbox to input a password Author: Tomasz

Tomasz

Matt Fig

Matt Fig

The GUI errors if the incorrect password is entered. Is this the expected behavior?

Comment only
26 Jan 2010 Kronecker Delta Given 2 subscripts, j & k, KronD will return 1 if j == k and 0 if j != k. Author: Richard Rieber

Richard Rieber

Matt Fig

Matt Fig

eq(j,k) does the same thing. If you are looking for a function which takes arguments, as opposed to an operator (i==j), why not use the built-in?

Comment only
08 Jan 2010 COMBINATOR -combinations AND permutations Returns 1 of 4 different samplings on the set 1:N, taken K at a time. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Thanks, Jan. I will look into your suggestions and, if my findings match yours, will offer an update. I appreciate the speedup!

Comment only
17 Dec 2009 N_PERMUTE_K All possible permutations of the elements of set N, taken K at a time, with repetition. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Jan,
With the single class we are ok up to 16,000,000 elements. Even finding the number taken two at a time would lead to an array of size 5.12e+014 elements. I think this is beyond the reasonable, even with 64-bit computing! The other problem is that cumsum isn't supported for the integer classes, at least in 2007b. If you look at my COMBINATOR file, you will see that I have included a MEX which performs cumsum on integer classes.
Thanks.

Comment only
23 Nov 2009 Unique Rows for a cell array Find unique rows of a cell array containing columns with strings or scalars, or N-D matrices Author: Jim Hokanson

Jim Hokanson

Matt Fig

Matt Fig

This is much faster, and has no requirement as to types or ordering:

ii = 1;
while ii<size(A,1)
tf = true(size(A,1),1);
for jj = ii:size(A,1)
if isequal(A(ii,:),A(jj,:)) && ii~=jj
tf(jj) = 0;
end
end
A = A(tf,:);
ii = ii + 1;
end

For example, try it with:
A = {1,'red',magic(3);'blue',magic(4),'green';1,'red',magic(3)}

Comment only
31 Oct 2009 COMBINATOR -combinations AND permutations Returns 1 of 4 different samplings on the set 1:N, taken K at a time. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Michele,
You didn't give very much information. If you put a number greater than 170 WHERE? And what other parameters? Why don't you just email me? I put my email in the help for that purpose. If you email me, show me EXACTLY what you did, don't be vague.

Comment only
07 Sep 2009 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Cyberfrog,
GUI_34 has a custom menubar. None of the GUIs in this collection are programmed with GUIDE. Please email me if you have more questions.

Comment only
06 Sep 2009 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Hello CyberFrog,
I am not sure what you mean by a "menu title" in GUI_25. There isn't supposed to be a menubar, if that is what you mean. I am using 2007b, and everything looks like it should here.

No *.fig file is generated because these are M-file GUIs. GUIDE works by generating two files, an M-File which has the code, and a figure file which has the graphics. These are simply two different ways of doing GUIs in MATLAB. I much prefer to write my GUIs without GUIDE for many reasons, only one of which is that I need to keep track of only one file!

This collection, as is stated in the description, is meant to help people write GUIs without using GUIDE.

Comment only
04 Sep 2009 ATAN2_SAFE To perform the same function as Matlab built-in function atan2 but safely guarded against erroneous Author: Zhigang Xu

Zhigang Xu

Matt Fig

Matt Fig

Actually atan2 is fine. The source of the error in your example is this line:

[x2 y2 z2] = sph2cart(t2, p2, r2); % step 5b

The value of y2 should equal zero but there are round-off errors occurring. If you simply assign y2 = 0 after this line in your example, you will see that t1 is back at zero as expected. This has nothing to do with atan2.

Comment only
04 Sep 2009 NUMUNIQUE Returns unique elements in an array and all the indices for the repetitious values. Author: Zhigang Xu

Zhigang Xu

Matt Fig

Matt Fig

Well done. About the only thing I would change would be to replace these lines:

n = 1:N;
d = diff([nan; x]);
d = d~=0;
n = n(d);

with

n = find(diff([nan; x]));

On my machines this can make a significant difference in speed. Other than that, great code!

5
13 Aug 2009 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Tanguy,
You are correct. I didn't mention resizable GUIs because I make all of my own GUIs non-resizable. Is there something you have in mind in particular? If so email me with your suggestion, and I may include it in the next update. Thanks.

Comment only
09 Aug 2009 ds group contribution Author: naser rezakhani

naser rezakhani

Matt Fig

Matt Fig

A script. Not one single comment, let alone explanation.

1
09 Aug 2009 AutoWarnDlg Self-terminating modal warning dialog with flashing icon Author: Jan Simon

Jan Simon

Matt Fig

Matt Fig

Works well. One thing I would like to see added is an optional second output which stores whether the dialog terminated due to timeout or user acknowledgment. That way if this was called from a code which was running automatically, the user could be notified that a warning was thrown earlier. This could be useful for debugging.

5
01 Aug 2009 Fractions Toolbox create and manipulate fractions (K+N/D) using exact arithmetic Author: Ben Petschel

Ben Petschel

Matt Fig

Matt Fig

Great work!

5
28 Jul 2009 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Thanks someone,
BUG! I should be using listboxtop, not value. Thanks, I will update that too.
Also, the suggestions for added exercises are coming into my email. Keep them coming! Any other GUI suggestions are welcome, simple or complex.

Comment only
28 Jul 2009 41 Complete GUI Examples 41 working GUIs to read and learn. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

I like the contents.m idea, and I might as well since a typo has already been found.

In the pdf I refer to a comment in GUI_30. I should have put GUI_32. File will be updated.

Comment only
13 Jul 2009 N_PERMUTE_K All possible permutations of the elements of set N, taken K at a time, with repetition. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Juliette,

You cannot index the output of npermutek(1:5,5) into an array (nuc) of length 4! The index exceeds dimensions because the output of the above call to NPERMUTEK will have many '5's in it. You will get the same error by doing this:

nuc = 'ABCD'
R = nuc(5) % or nuc(6) or nuc(7), etc. nuc only has 4 elements!

This is not an NPERMUTEK problem, it a user misunderstanding the output problem.

Comment only
07 Jul 2009 reshape2cube Reshape a vector into a cubic array Author: david s

david s

Matt Fig

Matt Fig

I am with Darren. Maybe a generalization would be more useful:

A = 1:5^2;
reshape2pow(A,2)
A = 1:5^3;
reshape2pow(A,3)
A = 1:5^4;
reshape2pow(A,4)
....

Comment only
29 Jun 2009 Longest Common Subsequence Gives the longest common substring between two stings. Author: David Cumin

David Cumin

Matt Fig

Matt Fig

Something is still wrong.

[D,G,S] = LCS('fbce','abcde');S
S =
bce

Comment only
25 Jun 2009 kronecker Kronecker tensor product Author: Bruno Luong

Bruno Luong

Matt Fig

Matt Fig

Fast, slick, well done.
Thanks for answering my question. I was waiting on that in order to give a rating, now I know it is my old (!, 2007b) version of MATLAB which is out of alignment.

5
24 Jun 2009 EXPAND Replicate and tile each element of an array. Author: Matt Fig

Matt Fig

Matt Fig

Matt Fig

Another reason I bypassed kron is illustrated here:

http://i217.photobucket.com/albums/cc229/spamanon/tester_output-2.png

Urs, I think you are correct about mentioning kron in the see also.

Comment only
24 Jun 2009 kronecker Kronecker tensor product Author: Bruno Luong

Bruno Luong

Matt Fig

Matt Fig

My only question is why the function errors out for non- 2D inputs? The stock MATLAB function does not error, and if I take the offending lines of code out of kronecker, the results match.

Comment only

Contact us