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.
% Vibrate figure
Husam Aldahiyat (2021). MATLAB Earthquake (https://www.mathworks.com/matlabcentral/fileexchange/22816-matlab-earthquake), MATLAB Central File Exchange. Retrieved .
Yes, this is quite interesting!
Much better now. Thanks for fixing it.
Anotherupdate has been sent. Improvements are:
- New option of confining vibration to current screen/figure
- Fixed help flaw
- Improved code efficiency
- Added more examples
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.
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.
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.
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.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!