Search Comments and Ratings

go

Comments and Ratings

   
Date File Comment by Comment Rating
18 Aug 2009 play_sound play_sound loads and plays the specified sound file. Author: Phillip M. Feldman Tim

Missing function substr

16 Aug 2009 save_to_base.m copies variables from the workspace of the calling function to the base workspace Author: Phillip M. Feldman Donald

I found trouble when I had a stray "ans" variable floating around. I got this message:

??? The variable "ans" is undefined.

To avoid trying to copy "ans", I modified save_to_base.m so that the for loop now reads:

for i= 1 : length(variables)
    if ~strcmp(variables{i},'ans')
        tmp= evalin('caller',variables{i});
        assignin('base',variables{i},tmp);
    end
end

Very nice little function.

03 Aug 2009 Figure Slideshow Generator The function showfigs() generates a slideshow of all open figures. Author: Phillip M. Feldman Paul

I've been looking for something like this for a while! thanks!!!

10 Jul 2009 meow.m For cat lovers everywhere. Author: Phillip M. Feldman Komarov, Oleg

I hid my lap behind a wall and put on at max volume this code:
a = 1; b = 11;
while i=1
    paws = floor(a + (b-a).*(rand(1)));
    meow(2,paws)
end

after a while some people started to gather, guessing what was going on...somebody almost called firemen!
I'm sure if i think a little more i'll find a way to become billionare with meow.m!

10 Jul 2009 meow.m For cat lovers everywhere. Author: Phillip M. Feldman Raghavan, Manu

Meows quite adequately.

07 Jul 2009 meow.m For cat lovers everywhere. Author: Phillip M. Feldman Hull, Doug

LOL Does indeed meow as documented.

18 Jun 2009 Figure Slideshow Generator The function showfigs() generates a slideshow of all open figures. Author: Phillip M. Feldman Ryan

Awesome. Quite awesome. I often have a lot of figures open for comparison and it's great to cycle through them easily. Thank you for a great submission.

18 Jun 2009 Figure Slideshow Generator The function showfigs() generates a slideshow of all open figures. Author: Phillip M. Feldman cagatay

very helpful. thank you.

one suggestion: right now when you press right arrow for example, it says "don't know how to handle" and terminates the slide show. It would be great if the function just ignores unassigned keys and terminates the slide show only for Escape or q.

20 May 2009 choose.m compute number of ways of choosing m objects from n distinct objects Author: Phillip M. Feldman Jos (10584)

If it is all about speed, remove the error checks! For larger numbers the following formula is more appropriate:
exp(gammaln(N+1) - gammaln(K+1) - gammaln(N-K+1)) ;

19 May 2009 choose.m compute number of ways of choosing m objects from n distinct objects Author: Phillip M. Feldman Feldman, Phillip M.

Darren and John-

Most of what I do with Matlab is simulation. From the standpoint of a simulationist, nchoosek is probably more suitable in the development/debugging stage of a simulation, but once the development and debugging has been done, one wants the code to run as fast as possible. Below are the results of a simple timing comparison of nchoosek and choose:

>> mytime(0); for i=1:1e6; nchoosek(52,13); end; mytime;
19-May-2009 10:45:26 Timer initialized.
19-May-2009 10:46:01 Last step took 35.56 sec.; total elapsed= 35.56 sec.

>> mytime(0); for i=1:1e6; choose(52,13); end; mytime;
19-May-2009 10:46:11 Timer initialized.
19-May-2009 10:46:20 Last step took 8.70 sec.; total elapsed= 8.70 sec.

Note that my function runs over four times as fast as Matlab's builtin function. For the user who invokes nchoosek small numbers of times from the command line, the difference in speed is unimportant. But, when nchoosek or choose is being called millions or tens of milions of times from within a program, the difference becomes important. Please let me know if further explanation is required.

18 May 2009 choose.m compute number of ways of choosing m objects from n distinct objects Author: Phillip M. Feldman D'Errico, John

Why submit functions that do the same thing that existing utilities in MATLB do better?

nchoosek does the same computation, but does it better, since nchoosek offers more functionality, and already exists in every copy of matlab for as far back as I can recall.

This has little in the way of error checking. No H1 line.

Admittedly, if you are trying to compute large binomial coefficients, you will be far better off using a variety of other tools. But this one fails when it needs not do so.

>> nchoosek(1000,800)
Warning: Result may not be exact. Coefficient is greater than 1.000000e+15
 and is only accurate to 15 digits.
> In nchoosek at 66
ans =
     6.61715556065931e+215

>> choose(1000,800)
ans =
   NaN

18 May 2009 cell2num.m convert a cell array to a double precision array Author: Phillip M. Feldman us

why do you submit another author's (unaltered?) code - just
because it's a missing part of one of your own contributions...

http://www.mathworks.com/matlabcentral/fileexchange/24109

it would be more prudent to ask the author to submit it him/herself and then add it to the above...

us

18 May 2009 cell2num.m convert a cell array to a double precision array Author: Phillip M. Feldman Jos (10584)

See CELL2FLOAT
http://www.mathworks.com/matlabcentral/fileexchange/19730

for a more flexible implementation.

And who is the author of this submission? Vasi or Feldman?

17 May 2009 choose.m compute number of ways of choosing m objects from n distinct objects Author: Phillip M. Feldman Rowland, Darren

This is a poor submission to the FEX. It provides nothing that nchoosek does not, and computes the result in a way which is more susceptible to roundoff error. The input checks are inadequate and no warnings are given for large output values. Here is the file contents

function k= choose(n, m)
%
% choose(n,m) is the number of ways of choosing m objects from n
% distinct objects.

% Check input arguments:

if (nargin ~= 2)
   error('choose requires 2 arguments.');
end

if (m < 0 | m > n)
   error('m (second argument) must be between 0 and n, inclusive.');
end

% The simplest definition of choose(n,m) is n! / (m! * (n-m)!), but the
% following algorithm is somewhat less susceptible to overflow.

if (m >= n-m)
   k= prod(m+1:n) / prod(2:n-m);

else
   k= prod(n-m+1:n) / prod(2:m);
end

17 May 2009 show_colors.m generates a labeled plot showing all colors recognized by RGB.m Author: Phillip M. Feldman D'Errico, John

Perhaps fig may be available on the internet, but where? Give a link. Is it really that difficult to be friendly to those who might try to download your work? Is it really necessary for others to be forced to do these searches to find out how to use your code?

IF your code uses something that will not be available in MATLAB proper, then tell people about it. If it uses a toolbox function, then show that toolbox as a dependency. If it uses another FEX submission, then tell people about it. Put a link in your code that shows where to find it. Do NOT post code that has dependencies without that information, as this then is non-working code. Non-working code is by definition poor.

17 May 2009 Figure Slideshow Generator The function showfigs() generates a slideshow of all open figures. Author: Phillip M. Feldman Nisky, Ilana

helpful

17 May 2009 show_colors.m generates a labeled plot showing all colors recognized by RGB.m Author: Phillip M. Feldman Nisky, Ilana

After writing the comment I browesed the file exchange for a while and I ran into the fig function... Liked the fig function as well :) Any way, I find the colors.m helpful - it is always annoying to choose the colors by guessing...

17 May 2009 show_colors.m generates a labeled plot showing all colors recognized by RGB.m Author: Phillip M. Feldman Feldman, Phillip M.

Actually, fig is available (separate download). cell2num was missing, but I've submitted it now.

16 May 2009 show_colors.m generates a labeled plot showing all colors recognized by RGB.m Author: Phillip M. Feldman Nisky, Ilana

Cute idea.
The code does not run unless:
 the cell2num command is changed to cell2mat
and
the fig commant is changed to figure, for example by the following 2 lines:
handle= figure(1);
set(handle,'Position',[100,100, 1000, 900])

14 May 2009 hostname.m Report the name of computer on which Matlab is currently running. Author: Phillip M. Feldman us

use of java system calls is (likely) a more os independent way to retrieve such information, eg,

http://www.mathworks.com/matlabcentral/fileexchange/20321

us

14 May 2009 show_colors.m generates a labeled plot showing all colors recognized by RGB.m Author: Phillip M. Feldman us

unfortunately, this script does not run due to missing functions

- cell2num
- fig

us

14 May 2009 hostname.m Report the name of computer on which Matlab is currently running. Author: Phillip M. Feldman D'Errico, John

Macs will return either of MACI or MAC, depending upon whether the system is an older or new inter Mac system. The help for computer.m states this fact.

So hostname still fails to work on older MAC systems, although it will probably now run on intel based macs.

Also, this submission too has the flaw that it has a blank comment line BEFORE what serves as an H1 line. Since that disables lookfor, it is a flaw, and a silly one. I'm not at all sure why the author insists on doing this. It is unfriendly to disable a very useful feature of MATLAB for absolutely no good reason.

14 May 2009 logarithmic rounding does logarithmic rounding using any of 7 modes Author: Phillip M. Feldman D'Errico, John

I see that the code has been updated to provide vectorized operation. As always, I should consider raising my rating.

First, I looked for an H1 line. No. Still a blank line as the very first line of the help. This is utterly silly, since the second line of the help is a perfectly serviceable H1 line. This disables lookfor. Interestingly, the help facility that automatically builds a contents file for directories using the first lines of the help blocks finds roundl. But lookfor is itself disabled here. So this problem has not been repaired.

How bout the vectorized question?

x = rand(1,5)*100
x =
    74.555 73.627 56.186 18.419 59.721

roundl(x)
ans =
   100 100 50 20 50

By default, roundl uses a rounding strategy, i.e., a rounding mode of 'n'. But it can round up or down, more like a ceiling or floor operation then. All of these operations work nicely, and a default appears to be supplied for the rounding mode if necessary. Or is it?

roundl(x,'n')
ans =
   100 100 50 20 50

roundl(x,'u')
ans =
   100 100 100 20 100

roundl(x,'d')
ans =
    50 50 50 10 50

Now try the code by adding the third argument. The third argument to roundl allows you to control the levels rounded to.

roundl(x,'n',7)
ans =
    80 80 60 20 60

No problem so far. But what happens if you don't wish to change the default for the rounding mode, only the default for n? The paradigm in MATLAB when you have variables that will take on a default is if the variable is left empty ([]), then use the default. Does this work? No. This fails. I tried these things:

roundl(x,[],7)
??? Error using ==> roundl at 120
Invalid rounding mode:

roundl(x,'',7)
??? Error using ==> roundl at 120
Invalid rounding mode:

I even tried this:

roundl(x,7)
??? Error using ==> roundl at 120
Invalid rounding mode: 

As I said, this fails to follow the standard MATLAB paradigm for default arguments, which makes the code not very friendly. If you wish to change the rounding level, you must also provide a default for the other parameter. It is a truly silly flaw, because is it really that difficult to write your code as:

if (nargin < 2) || isempty(n), mode= 'n'; end

versus the line as it was written?

if nargin < 2, mode= 'n'; end

Sorry, but it is easy to write friendly code, and it is easy to make the code compatible with lookfor. Given this newly found problem, a 3 rating still applies here.

14 May 2009 hostname.m Report the name of computer on which Matlab is currently running. Author: Phillip M. Feldman Dalon, Thierry

(For windows only?)
Be aware: the call to unix('hostname') or system('hostname') gives you an empty sign a the end. You need to DEBLANK it!

See example:
[status,name]= unix('hostname')

status =

     0

name =

RBGD0SGC

>> length(name)

ans =

     9

That is to my opinion the only benefit for such an easy wrapper function else.

13 May 2009 hostname.m Report the name of computer on which Matlab is currently running. Author: Phillip M. Feldman D'Errico, John

Despite the claim, this fails to run on all operating systems. Try it on a PPC Mac. No go.

unix('hostname') works fairly well if you are on a PPC mac. I've not verified it is correct for an intel mac.

13 May 2009 find_cross.m, version 2.1 Find and/or estimate level crossings using a combination of search and interpolation. Author: Phillip M. Feldman CanĂ³s, Antoni J.

Phillip, please have a look at findX.m (File ID: #23860).
http://www.mathworks.com/matlabcentral/fileexchange/23860

It is based on find_cross.m but with an optimized code, completely vectorized, without the restriction of column vectors and with some new features.

08 May 2009 logarithmic rounding does logarithmic rounding using any of 7 modes Author: Phillip M. Feldman D'Errico, John

I quite liked the basic idea when I saw it. However, there are a couple of flaws I found. The first was a surprise to me. It is not vectorized?

roundl(rand(20,1)*100)
??? Error using ==> mpower
Matrix must be square.

Error in ==> roundl at 91
   if (10^log10x_frac <= sqrt( multiplier(n,i-1)*multiplier(n,i) ) )

So this takes only scalar input? You are kidding me, right? A silly thing, IMHO. Since this is absolutely trivial to vectorize, why not do so?

The help was quite reasonable in general. It was missing an H1 line. Well, actually, it HAS an H1 line, but in the wrong place. There is a blank comment line as the very first line of the help. This causes problems for the lookfor function, since it looks at the very first comment line in the help block. Why do you want lookfor to work? Lookfor is the tool that your user will use next month or next year when they forget the name of your function. But by leaving that first line blank, you just disabled lookfor.

I did find error checks that seemed reasonable. Mlint points out a couple of minor items, like the use of | instead of || in conditionals. Read the help for relop to learn the difference.

 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com