COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How can I add string to an integer matrix ??

• Follow

``` Can you tell me how can I add string to a matrix.
For this example I have this matrix :

from=[1 ;2 ;4; 6; 7; 8 ]
Now I want to add x to them so I have
from=[x1;x2;x4;x6;x7;x8]
when I add them, Matlab gave me answers in numbers not in string like this
from=[x1;x2;x4;x6;x7;x8]

I dont want to use this :  from=num2str(from,'x%d') It changes my matrix dimension
so after conversion I have from(1,1)=x from(1,2)=1  I need this : from(1,1)=x1
```
 0

```roya olyazadeh wrote:
> Can you tell me how can I add string to a matrix. For this example I
> have this matrix :
>
> from=[1 ;2 ;4; 6; 7; 8 ]
> Now I want to add x to them so I have from=[x1;x2;x4;x6;x7;x8]
> when I add them, Matlab gave me answers in numbers not in string like
> this from=[x1;x2;x4;x6;x7;x8]
>
> tnx againt for your help.
>
>
> I dont want to use this :  from=num2str(from,'x%d') It changes my matrix
> dimension
> so after conversion I have from(1,1)=x from(1,2)=1  I need this :
> from(1,1)=x1

The question is what are you proposing to do with the result?

Whether you use a string array or a cell array containing strings, it
_WILL_ be a string/character variable, _NOT_ numeric and it _WILL_ have
different dimensions.  Character variables and numeric are two different
things.

What would be most useful representation would depend on the intended
result.  If you're intending to make variable names this way, as the FAQ
says, that's not the way to progress in almost all circumstances in
Matlab.  If you have something else in mind, it's crystal ball time
unless you're willing to share...

--

--
```
 0

1 Replies
324 Views

Similiar Articles:

7/26/2012 11:58:56 PM