Code covered by the BSD License  

Highlights from
MATLAB Earthquake

5.0

5.0 | 4 ratings Rate this file 10 Downloads (last 30 days) File Size: 2.33 KB File ID: #22816

MATLAB Earthquake

by Husam Aldahiyat

 

29 Jan 2009 (Updated 31 Jan 2009)

Randomly Vibrates Graphical Objects

| Watch this File

File Information
Description

mquake(h,int,dur,op1,op2) Randomly vibrates graphical objects, where:
  
  h: Handle of required object(s) (scalar or vector)
  
  int: Intensity of vibration (scalar)
  
  dur: Duration of vibration in seconds (estimate, scalar)
  
  op1: 1 -> Object returns to starting position at the end
              0 -> Object ends up where earthquake lands it
 
  op2: 1 -> Confine object to screen limits
              0 -> Vibrate freely
 
Setting OP2 to 1 will confine the vibrating object to its container's limits. It confines a figure to the screen limits, and confines axes and uicontrols to the limits of the figures containing them.
  
+ Example:
 % Vibrate figure
  
  t=0:.1:4;
  y=cos(t);
  plot(t,y)
  mquake(gcf,2,5,0,1)

Acknowledgements
This submission has inspired the following:
Mth Order Piecewise Spline Interpolation
MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
29 Jan 2009 John D'Errico

Ok, I cannot for the life of me imagine why anyone would want to use this. Perhaps someone might get some ideas for it in some other application though.

Having said that, it does what it says it does, and it seems to work reasonably well. The help seems reasonably clear. It includes two examples that show how to use it.

I had two minor issues:

There is no H1 line. In fact, the first line of comment is completely blank. This means that lookfor is not enabled, so when you want to find this code next year, will you remember the name? Make the VERY first line of your functions a descriptive line, with keywords that lookfor can search over.

Next, there is no error checking. The best code will tell you what it expects to see for arguments. Is the parameter a vector? How long? What type? Are there limits on the values it can take on? Then that well written code will test its inputs to verify the requirements are met. If not, then return a clearly written error message. When you get used to writing this automatically, it takes very little time to write friendly code, that helps the user when they make a mistake.

If not for these issues, I'd have given this a 5 rating, despite my inability to see any use for the code. I'm sure someone else out there will find a use for it though.

29 Jan 2009 Husam Aldahiyat

I've sent an update with the following changes:

- Added H1 Line with the word 'earthquake' in it.
- Added support for vibrating multiple objects at the same time
- Added extensive input parameters check

Please download the updated version and adjust your rating.

By the way this tool can be used in a lot of ways, of which are:

- Vibrating a button or uicontrol as a form of error (like the example)
- Vibrating a line to emphasise it. You can make a listbox and vibrate a selected line from many.
- Endless possibilities in game design.

29 Jan 2009 Kenneth Eaton

Looks interesting... I'll give it a try when I get a chance. I've had the idea for a while to make something similar, not for uicontrols, but for the camera or the axes to shake the rendered camera view. I eventually want to add it to my game whenever an explosion goes off.

30 Jan 2009 John D'Errico

To me, the help seems to be slightly flawed. All i get is this:

>> help mquake
  MQUAKE Matlab earthquake
 {

>>

I'll increase the rating when it improves.

31 Jan 2009 Husam Aldahiyat

Anotherupdate has been sent. Improvements are:

- New option of confining vibration to current screen/figure
- Fixed help flaw
- Improved code efficiency
- Added more examples

02 Feb 2009 John D'Errico

Much better now. Thanks for fixing it.

07 Feb 2010 Amelia

Yes, this is quite interesting!

Please login to add a comment or rating.
Updates
29 Jan 2009

Added improvements to the code, as well as support for handles of multiple object.

31 Jan 2009

Added additional option.

Tag Activity for this File
Tag Applied By Date/Time
random Cristina McIntire 29 Jan 2009 16:58:45
earthquake Husam Aldahiyat 29 Jan 2009 16:58:50
vibrate Husam Aldahiyat 29 Jan 2009 16:58:50
random Husam Aldahiyat 29 Jan 2009 16:58:50
vibration Husam Aldahiyat 29 Jan 2009 16:58:50
explosion Husam Aldahiyat 02 Feb 2009 12:52:10
earthquake AHMET ANIL DINDAR 25 Feb 2009 13:45:45

Contact us at files@mathworks.com