## What is the difference between ( ) and [ ] format in matlab? how can i change the one format to another one?

on 11 Sep 2012

### Andreas Goser (view profile)

What is the difference between ( ) and [ ] format in matlab? how can i change the one format to another one?

```            [rangr]=split(rangr(x,:),gsize1);
[rangg]=split(rangg(x,:),gsize1);
[rangb]=split(rangb(x,:),gsize1); this is function```

I want get the result format for only this ( ) format, not this [] format.. so how can i convert it.. please any one help to me.

Edit [11 Sep 2012, 12:04 BST - OK] Merged from duplicate

Dear Sir/MAdam, Please read out my following codes . I got a rang, meanran and varran values for ( ) this format. But I got the result for rang ,meansrang,varsrang values for [ ] format. THis method is correct or not..?

for i1=1:gsize:nr

`    for j1=1:gsize:nc`
`        l=1;`
`        for x=i1:1:i1+(gsize-1)`
`            for y=j1:1:j1+(gsize-1)`
```               rang1(k,l)=c(x,y);
l=l+1;    ```
`            end   `
`        end `
`        dr=double(rang1(k,:));`
`        meanran(k)=mean(dr);`
`        varran(k,:)=var(dr);`
`        k=k+1;`
```    end
end
###################################```

[rang]=qtsplit(rang1(i1,:),gsize1);

` for x=1:1:4`
` dr=double(rang(x,:));`
` meansrang(x)=mean(dr(1,:)); `
` varsran(x)=var(dr(1,:));`

So I got the Result in different formate and Error image also. how can i rectify that formate?

(rang2)=[rang] possible or not? how can i change the type[] to ( ). Any one pleas help to my question.

Thank you.

Oleg Komarov

### Oleg Komarov (view profile)

on 11 Sep 2012

Really sorry Walter.

When I opened it there was no answer and I usually refresh before doing such operations and I forgot this time.

Walter Roberson

### Walter Roberson (view profile)

on 11 Sep 2012

Thanks, but don't bother Oleg. I don't think they can retrieve deleted messages anyhow, and it was probably too new to have been backed up.

Oleg Komarov

### Oleg Komarov (view profile)

on 11 Sep 2012

I sent an email, we'll see. I recall that in one of the updates to ANSWERS they said they don't delete posts from the DB but flag them.

## Products

### Andreas Goser (view profile)

on 11 Sep 2012

If SPLIT is a function, then () is needed. This is the syntax function(parameter1, parameter2).

[] concatenates. Simply try

```[1, 2, 3]
```

in the command window and you will see.

From this question, I do not see a format that can be changed. () and [] are used for different purposes.

PRIYANGA

### PRIYANGA (view profile)

on 12 Sep 2012

ok sir thank you, But above my coding I got the result for both [] and (). but the men image of that () result is ok. But the mean image of [] that result is too bad. So how can I change the format of [] to ().

### Walter Roberson (view profile)

on 11 Sep 2012

You cannot use () to surround output variables in MATLAB; it just isn't allowed. You need to use [] instead. [] hints at building a list.

```[variable] = function_call()  %allowed
(variable) = function_call()  %not allowed
```

In expressions, [] is used for building matrices.

```[1 2; 3 4]  %builds a two by two array
```

In expressions, () is used for array subscripting, such as a(3), and is also used to control the order of operations, such as ((1+3)*2)

Walter Roberson

### Walter Roberson (view profile)

on 18 Sep 2012

Please write out the code line difference, one showing [] and the other showing () . I am still trying to solve your original question.

Walter Roberson

### Walter Roberson (view profile)

on 20 Sep 2012

In the syntax

```[rangr]=qtsplit(rang1r(i1,:),gsize1);
```

you can leave out the [] and the result will be exactly the same:

```rangr=qtsplit(rang1r(i1,:),gsize1);
```

It appears to me that your difficulty has nothing to do with () compared to [].

Code of the form

```variable(index) = expression;
```

sets the index'th element of "variable" to contain the value of the expression.

Code of the form

```[variable] = expression;
```

is exactly the same as

```variable = expression;
```

and replaces "variable" entirely, so that afterwards "variable" has only the value of the expression.

There is also code of the form

```[variable1, variable2] = expression;
```

In that case, "expression" would normally be a function call that returns multiple outputs, with the first output being assigned to "variable1" and the second assigned to "variable2". (There are also some cases where the expression might involve cell arrays or structures instead of a function call.)

I am not familiar with the algorithms involved in your code, and it appears that for me to understand and debug it would be more work than I would be willing to do as a volunteer.

PRIYANGA

### PRIYANGA (view profile)

on 21 Sep 2012

Good Morning Sir,

I have to change my code in some places, no error but i got Error image.

Ok sir I will try for correct it. Thank you for your help. If u identify that error, Please update your answer sir. Thank you

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi