Showing posts with label bracket. Show all posts
Showing posts with label bracket. Show all posts

Friday, June 19, 2009

Brackets for structure arrays in MATLAB

Structure array is a common type of data used in MATLAB. To deal with it, brackets are used extensively. However, when to use the correct brackets- ( ) and [ ]? Sometimes this can be confusing. Here is a summary about them.

Suppose we have structure arrays
a.b =[1 2; 3 4]
and
c(1).b =[1 2], c(2).b =[3 4].

>> a.b= [1 2; 3 4]
a =
b: [2x2 double]
>> c(1).b =[1 2]
c =
b: [1 2]
>> c(2).b =[3 4]
c =
1x2 struct array with fields:
b
Now, let's try ( ) on both of them.
>> (a.b)
ans =
1 2
3 4
>> (c.b)
ans =
1 2
ans =
3 4

and [ ]
>> [a.b]
ans =
1 2
3 4
>> [c.b]
ans =
1 2 3 4

Through the example, it is easy to see the difference. If we also have d ='more', what will happen if we type c(1).(d) =1?
>> c(1).(d) =1
c =
1x2 struct array with fields:
b
more
Thus ( ) can be used to create dynamic field names. So far, { } haven't been mentioned because this pair of curly braces are mostly for cells.

Saturday, February 17, 2007

Insert a pair of brackets automatically in Latex editor

Brackets, '{}' are frequently used in Latex, and it is possible to miss one when editing a complex math equation. In LEd, you can insert a pair of brackets automatically, which may help you receive less errors from Latex. And, the exciting thing is that your cursor is locating just between them.

1. Go to View\Toolbars\Adjust menu, or right click on the toolbar, and select Adjust;
2. switch to Commands tab;
3. select User commands branch and click on + button, a popup command window will appear;
4. In the popup window, set hotkey to Shift+[ (copy as is), and in Text tab type: {_} (copy as is); if you didn't add any user command before, the ident should be CMD1. If the ident looks strange, modify it. The name field can be changed as you wish.
5. done.


Reference: http://forum.latexeditor.org/viewtopic.php?t=17