Rabu, 24 September 2008

Add Cancel Button to a Waitbar

We can add property that indicated a cancel button and a function that be executed if cancel button be select/click.
The source and output gave in above:


Jumat, 27 Juni 2008

Make a Wait Bar with Matlab

In one case, we need a wait bar to know how much process that run. We can make a wait bar to indicate process. In Matlab we use WAITBAR instruction that have syntax above:
H = WAITBAR(X,'title', property, value, property, value, ...)
creates and displays a waitbar of fractional length X. The handle to the waitbar figure is returned in H. X should be between 0 and 1. Optional arguments property and value allow to set corresponding waitbar figure properties. Property can also be an action keyword 'CreateCancelBtn', in which case a cancel button will be added to the figure, and the passed value string will be executed upon clicking on the cancel button or the close figure button (taken from MATLAB HELP)
Example :

Rabu, 14 Mei 2008

How to read text file in Matlab?

Some times we use a matrix that have a big size to testing program that we write. If we must to input it from keyboard...hmmmm....how long time spend for it? So..we can write it to a text file.
For example:
Make a file text(for example data1.txt), that contains above:
25 26 67 68 89 79 28
27 24 16 28 29 16 29
23 35 27 28 29 11 12
87 23 56 79 25 67 25
Each data separated by space.

And for read this file please to type this code in command window:
>> x=load('data1.txt')
x =
25 26 67 68 89 79 28

27 24 16 28 29 16 29
23 35 27 28 29 11 12
87 23 56 79 25 67 25

If our file contain a string don't use LOAD instruction, but we can use TEXTREAD instruction.
For example:
Make a text file('data2.txt') with this sentences:
This is an example text file with string data, that will be read with Matlab.

And for read this file please to type this code in command window:
>> n=textread('data2.txt','%s')
n =
'This'

'is'
'an'
'example'
'text'
'file'
'with'
'string'
'data,'
'that'
'will'
'be'
'read'
'with'
'Matlab.'