Prev: Parallel Computing Toolbox 4.2 support for lsqcurvefit
Next: numbers in variable editor to text file
From: Chiemera on 31 Jul 2010 14:03 Hi, I have a matrix, labelsTR <1x1458 double>. I want to convert this matrix as string. So, I used mat2str command: d=mat2str(labelsTR); But its size is <1x2917>. I guess that it includes the square brackets, spaces. But I don't want any square brackets, spaces. Second, I used num2str command: d=num2str(labelsTR); But its size is >1x4372> not >1x1458>. I mean I want to convert my labelsTR matrix <1x1458 double> into <1x1458 string> (or may be char) matrix. How can I do? Regards.
From: Matt Fig on 31 Jul 2010 14:26 The problem is that each element of a row vector may contain any number of digits, but each element of a numerical character array is ONE digit (or space). Look: A = [10 20 30 40 5000]; B = num2str(A); whos B A % Notice the lengths Now you could turn to cell arrays to get what you want: B = cellfun(@(x) sprintf('%d',x),num2cell(A),'Un',0); % See help for sprintf Now each element of the cell array B is a string. For example, ischar(B{1}) % YES. and whos A B % But look at the class!
From: Matt J on 31 Jul 2010 14:30
Chiemera <muratgok(a)gmail.com> wrote in message <6c4b535b-c239-4be8-8aa0-7e74a933ae08(a)u26g2000yqu.googlegroups.com>... > Second, I used num2str command: > d=num2str(labelsTR); > But its size is >1x4372> not >1x1458>. > I mean I want to convert my labelsTR matrix <1x1458 double> into > <1x1458 string> (or may be char) matrix. ========== What makes you think that this is possible? Is every element of labelsTR a single-digit integer? otherwise, your string needs to have multiple elements per number. In any case, maybe the following is what you want: >> a=[10.3 5] a = 10.3000 5.0000 >> s=num2str(a) s = 10.3 5 >> s(s==' ')=[] s = 10.35 |