From: roya olyazadeh on 3 May 2010 23:13 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
From: dpb on 4 May 2010 00:09 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... -- --
|
Pages: 1 Prev: copy cell array to matrix (w/conversion) Next: simple thresholding |