Thread Subject: modify surf default behavior

Subject: modify surf default behavior

From: Alan B

Date: 3 Jun, 2009 17:38:02

Message: 1 of 8

I would like axis('vis3d') to be run automatically when surf is called, is this possible? I can think of two things to try:
1. create a new wrapper m-file, also called surf.m, that simply passes the arguments around, and calls axis('vis3d') when done. I don't know how to do this because surf is not a built-in command, so builtin() doesn't work - how can I run a specific shadowed m-file, instead of whichever MATLAB chooses as the default?
2. set some default axes properties. I don't know how to do this because I was unable to understand what axis('vis3d') actually does, in terms of axes aspect ratio properties. Also, is it possible to specify different default properties for 2D vs 3D plots?

Any help is appreciated.

Subject: modify surf default behavior

From: Aurelien Queffurust

Date: 4 Jun, 2009 10:55:04

Message: 2 of 8

"Alan B" <monguin61@yahoo.com> wrote in message <h06cdq$b1h$1@fred.mathworks.com>...
> I would like axis('vis3d') to be run automatically when surf is called, is this possible? I can think of two things to try:
> 1. create a new wrapper m-file, also called surf.m, that simply passes the arguments around, and calls axis('vis3d') when done. I don't know how to do this because surf is not a built-in command, so builtin() doesn't work - how can I run a specific shadowed m-file, instead of whichever MATLAB chooses as the default?
> 2. set some default axes properties. I don't know how to do this because I was unable to understand what axis('vis3d') actually does, in terms of axes aspect ratio properties. Also, is it possible to specify different default properties for 2D vs 3D plots?
>
> Any help is appreciated.


1. Concerning shadowing a builtin

You can create your own surf.m function. Then by using addpath or pathtool, make the path of your own function to be the top of the path.
The command:
>>which -all surf
will show you that your own surf.m is shadowing the path $matlabroot\toolbox\matlab\graph3d\surf.msurf

2. Concerning axis3d algorithm

2.1 Read Section "Specifying Aspect Ratio";
http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/f4-24991.html#f4-25109


2.2 You can also edit axis.m and read the lines:
% handle VIS3D:
            elseif(strcmp(cur_arg,'vis3d'))
                set(ax(j),...
                    'CameraViewAngle', get(ax(j),'CameraViewAngle'),...
                    'DataAspectRatio', get(ax(j),'DataAspectRatio'),...
                    'PlotBoxAspectRatio',get(ax(j),'PlotBoxAspectRatio'));
      

Hope it helps,

Aur?lien

Subject: modify surf default behavior

From: Steven Lord

Date: 4 Jun, 2009 14:37:29

Message: 3 of 8


"Aurelien Queffurust" <tug83@yahoo.fr> wrote in message
news:h08968$qu$1@fred.mathworks.com...
> "Alan B" <monguin61@yahoo.com> wrote in message
> <h06cdq$b1h$1@fred.mathworks.com>...
>> I would like axis('vis3d') to be run automatically when surf is called,
>> is this possible? I can think of two things to try:
>> 1. create a new wrapper m-file, also called surf.m, that simply passes
>> the arguments around, and calls axis('vis3d') when done. I don't know how
>> to do this because surf is not a built-in command, so builtin() doesn't
>> work - how can I run a specific shadowed m-file, instead of whichever
>> MATLAB chooses as the default?
>> 2. set some default axes properties. I don't know how to do this because
>> I was unable to understand what axis('vis3d') actually does, in terms of
>> axes aspect ratio properties. Also, is it possible to specify different
>> default properties for 2D vs 3D plots?
>>
>> Any help is appreciated.
>
>
> 1. Concerning shadowing a builtin
>
> You can create your own surf.m function. Then by using addpath or
> pathtool, make the path of your own function to be the top of the path.
> The command:
>>>which -all surf
> will show you that your own surf.m is shadowing the path
> $matlabroot\toolbox\matlab\graph3d\surf.msurf

Note that this will force ALL functions that call SURF to use your modified
SURF. For the specified change you want to make, that's _probably_ okay
(assuming none of the other functions that call SURF expect the axis to be
configured a certain way and error if it isn't) but be careful if you shadow
other functions like this. For instance, if you were to shadow QUIT and
EXIT and make them not call the builtins, you're going to have an
interesting time trying to shut down MATLAB.

Instead of doing this, I'd write my own wrapper and use it instead of SURF.
Call it something like surfWith3dAxis:


function h = surfWith3dAxis(varargin)
h = surf(varargin{:});
axis('vis3d');


This way, those functions that expect SURF to behave a certain way will
still work, but you've got a very simple way to get the behavior you want.

--
Steve Lord
slord@mathworks.com

Subject: modify surf default behavior

From: Alan B

Date: 4 Jun, 2009 14:40:18

Message: 4 of 8

> 1. Concerning shadowing a builtin
>
> You can create your own surf.m function. Then by using addpath or pathtool, make the path of your own function to be the top of the path.
> The command:
> >>which -all surf
> will show you that your own surf.m is shadowing the path $matlabroot\toolbox\matlab\graph3d\surf.msurf
>

This is how my path is set now, and my surf.m needs to call the real surf function, but currently calls itself, causing a recursion error. What can I do to force 'surf' at the command line or in a function refer to my surf function, but allow my surf function to call a different version of surf?

> 2. Concerning axis3d algorithm
>
> 2.1 Read Section "Specifying Aspect Ratio";
> http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/f4-24991.html#f4-25109
>
>
> 2.2 You can also edit axis.m and read the lines:
> % handle VIS3D:
> elseif(strcmp(cur_arg,'vis3d'))
> set(ax(j),...
> 'CameraViewAngle', get(ax(j),'CameraViewAngle'),...
> 'DataAspectRatio', get(ax(j),'DataAspectRatio'),...
> 'PlotBoxAspectRatio',get(ax(j),'PlotBoxAspectRatio'));
>
>
> Hope it helps,
>
> Aur?lien

I've read some on the aspect ratios in the past... As I recall, that set() command makes no visible changes to the axes properties, but accessing the properties triggers some other sort of change. If there is a way to make that happen with a default axes property, I don't see it -

set('defaultAxesCameraViewAngle',get(something))

What would I do here?

Thanks for your help.

Subject: modify surf default behavior

From: John D'Errico

Date: 4 Jun, 2009 15:05:19

Message: 5 of 8

"Alan B" <monguin61@yahoo.com> wrote in message <h06cdq$b1h$1@fred.mathworks.com>...
> I would like axis('vis3d') to be run automatically when surf is called, is this possible? I can think of two things to try:
> 1. create a new wrapper m-file, also called surf.m, that simply passes the arguments around, and calls axis('vis3d') when done. I don't know how to do this because surf is not a built-in command, so builtin() doesn't work - how can I run a specific shadowed m-file, instead of whichever MATLAB chooses as the default?
> 2. set some default axes properties. I don't know how to do this because I was unable to understand what axis('vis3d') actually does, in terms of axes aspect ratio properties. Also, is it possible to specify different default properties for 2D vs 3D plots?
>
> Any help is appreciated.

Why not just write your own wrapper function? Call it
mysurf, or something like that. This way surf will work
as it is designed for others, or for the case in the future
when you don't want that. (It will happen too.)

John

(I'm going to write my own wrapper for surf. I'll call
it smurf. Of course, it will always use a pure blue
colormap.)

Subject: modify surf default behavior

From: Alan B

Date: 4 Jun, 2009 15:28:02

Message: 6 of 8

> Why not just write your own wrapper function? Call it
> mysurf, or something like that. This way surf will work
> as it is designed for others, or for the case in the future
> when you don't want that. (It will happen too.)
>
> John
>
> (I'm going to write my own wrapper for surf. I'll call
> it smurf. Of course, it will always use a pure blue
> colormap.)

Of course you're correct here, if I modify the default behavior, SOMETHING will eventually break. Its more a question of curiosity. Incidentally, I have never wanted to use surf without axis vis3d, as far as I can remember. Do you have an example where that would be desired?

There are a few other functions with behavior that bothers me. For example, 'open nonexistentFunction' errors, and since I have 'dbstop if error' enabled, every time I make a typo using 'open' at the command line, I get open.m needlessly opening up in my editor. My personal preference would be a warning or message instead of an error, and I would like to continue using 'open' instead of 'myopen' simply because I'm lazy. I have a hard time imagining how making that change might break anything. (I also wouldn't mind being able to enable 'dbstop if error' on a by-function basis)

If this can't be done, its not a big deal. Just thought I'd ask.

Thanks

Subject: modify surf default behavior

From: John D'Errico

Date: 4 Jun, 2009 16:11:01

Message: 7 of 8

"Alan B" <monguin61@yahoo.com> wrote in message <h08p62$lt7$1@fred.mathworks.com>...
> > Why not just write your own wrapper function? Call it
> > mysurf, or something like that. This way surf will work
> > as it is designed for others, or for the case in the future
> > when you don't want that. (It will happen too.)
> >
> > John
> >
> > (I'm going to write my own wrapper for surf. I'll call
> > it smurf. Of course, it will always use a pure blue
> > colormap.)
>
> Of course you're correct here, if I modify the default behavior, SOMETHING will eventually break. Its more a question of curiosity. Incidentally, I have never wanted to use surf without axis vis3d, as far as I can remember. Do you have an example where that would be desired?
>

UNLESS I intend to rotate a 3-d figure, I prefer surfs
in their default shape. axis vis3d changes that shape,
leaving a lot of gray space in the figure that is unused.


> There are a few other functions with behavior that bothers me. For example, 'open nonexistentFunction' errors, and since I have 'dbstop if error' enabled, every time I make a typo using 'open' at the command line, I get open.m needlessly opening up in my editor. My personal preference would be a warning or message instead of an error, and I would like to continue using 'open' instead of 'myopen' simply because I'm lazy. I have a hard time imagining how making that change might break anything. (I also wouldn't mind being able to enable 'dbstop if error' on a by-function basis)
>
> If this can't be done, its not a big deal. Just thought I'd ask.

Many of these things can be controlled with preferences
that you can set, and that list is growing with every
release.

I'll admit that my solution is usually to customize things
for my preferences. I mentioned the other day that I always
seem to type "close all" with no space in the middle. So
I wrote a closeall function for my own use.

I rarely leave "dbstop if error" enabled permanently for
just these reasons though. It is convenient when I need it,
but the rest of the time it slows me down.

John

Subject: modify surf default behavior

From: Steven Lord

Date: 4 Jun, 2009 17:28:14

Message: 8 of 8


"Alan B" <monguin61@yahoo.com> wrote in message
news:h08p62$lt7$1@fred.mathworks.com...
>> Why not just write your own wrapper function? Call it
>> mysurf, or something like that. This way surf will work
>> as it is designed for others, or for the case in the future
>> when you don't want that. (It will happen too.)
>>
>> John
>>
>> (I'm going to write my own wrapper for surf. I'll call
>> it smurf. Of course, it will always use a pure blue
>> colormap.)
>
> Of course you're correct here, if I modify the default behavior, SOMETHING
> will eventually break. Its more a question of curiosity. Incidentally, I
> have never wanted to use surf without axis vis3d, as far as I can
> remember. Do you have an example where that would be desired?

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/pcolor.html

"A pseudocolor plot is a flat surface plot viewed from above. pcolor(X,Y,C)
is the same as viewing surf(X,Y,zeros(size(X)),C) using view([0 90])."

If you were building your own tweaked version of PCOLOR, you might want to
call SURF as part of the process of creating the plot.

> There are a few other functions with behavior that bothers me. For
> example, 'open nonexistentFunction' errors, and since I have 'dbstop if
> error' enabled, every time I make a typo using 'open' at the command line,
> I get open.m needlessly opening up in my editor.

That's why I use EDIT -- if the file you're trying to edit doesn't exist, it
instead asks if I want to create it.

> My personal preference would be a warning or message instead of an error,
> and I would like to continue using 'open' instead of 'myopen' simply
> because I'm lazy. I have a hard time imagining how making that change
> might break anything. (I also wouldn't mind being able to enable 'dbstop
> if error' on a by-function basis)

Okay, so you make OPEN warn and complete its execution instead of erroring.
Now functions that call OPEN inside TRY/CATCH and check the error that OPEN
threw (if there was a problem, like a nonexistent file) may assume that
since OPEN didn't error, it was able to successfully open the file. A key
point to remember is that OPEN doesn't just open M-files, it can open lots
of different types of files, including FIG-files. Because they assume they
were able to successfully open the file, they continue running only to fall
over tens or hundreds of lines later when they try to use the (non-existent)
figure or model or file.

> If this can't be done, its not a big deal. Just thought I'd ask.

It _can_ be done; you can shadow built-in functions. You should just be
VERY careful when you do so, and often creating your own wrapper is a safer
idea. You will need to type two additional characters each time you call
the function, but after a short while you probably won't even notice.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
path Aurelien Queffurust 4 Jun, 2009 06:59:07
vis3d Aurelien Queffurust 4 Jun, 2009 06:59:07
defaults Alan B 3 Jun, 2009 13:39:03
surf Alan B 3 Jun, 2009 13:39:03
rssFeed for this Thread
 

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