Prev: Suppressing Scientific Notation when exporting data as asciifile tia sal22
Next: Segment length and overlap points for tfestimate
From: Nathan on 9 Sep 2009 02:13 On Sep 8, 11:03 pm, "Vinod Karanth" <vinodkara...(a)gmail.com> wrote: > > Well, if you're making the whole thing a string anyways, why not use > > sprintf? > > Req_mat = sprintf(%s %s,num2str(num_mat),str_vect); > > > -Nathan > > Hi Nathan, > > I checked with your above suggestion, but it just puts all the elements one next to another.... > > >> Req_mat = sprintf('%s %s',num2str(num_mat),str_vect) > > Req_mat = > 111111111122222123456789012345678901234 > Please note that my num_mat has different values from what I showed in my first example. But the end result is not what I am after....Any other inputs please? > > Thanks. How about assigning a space to str_vect before the string you put in it? % Matrix of numbers. num_mat=[1,2,10;25,2,1;10,9,21]; % Coulmn vector of string, X. for i = 1:size(num_mat,1) str_vect(i,1)=' X'; end % Required matrix. Req_mat=[num2str(num_mat),str_vect] %%%%%%%%%%%%%%%%%%%%% Req_mat = 1 2 10 X 25 2 1 X 10 9 21 X -Nathan
From: Vinod Karanth on 9 Sep 2009 02:59 > How about assigning a space to str_vect before the string you put in > it? > > % Matrix of numbers. > num_mat=[1,2,10;25,2,1;10,9,21]; > > % Coulmn vector of string, X. > for i = 1:size(num_mat,1) > str_vect(i,1)=' X'; > end > > % Required matrix. > Req_mat=[num2str(num_mat),str_vect] > %%%%%%%%%%%%%%%%%%%%% > Req_mat = > > 1 2 10 X > 25 2 1 X > 10 9 21 X > > > -Nathan Hi Nathan, I did try to assign a space to the string, but I get this error....(i guess this is what you meant me to do?) for i=1:size(num_mat,1) str_vect(i,1)=' X'; %Space given before X. end ??? Subscripted assignment dimension mismatch.
From: Oleg Komarov on 9 Sep 2009 03:35 > for i=1:size(num_mat,1) > str_vect(i,1)=' X'; %Space given before X. > end > ??? Subscripted assignment dimension mismatch. If "str_vect" already exists before the loop, you might get the mentioned error (if size and anture of the variable aren't coherent with the assignment).
From: Vinod Karanth on 9 Sep 2009 03:58
"Oleg Komarov" <oleg.komarov(a)hotmail.it> wrote in message <h87lrn$87g$1(a)fred.mathworks.com>... > > for i=1:size(num_mat,1) > > str_vect(i,1)=' X'; %Space given before X. > > end > > ??? Subscripted assignment dimension mismatch. > > If "str_vect" already exists before the loop, you might get the mentioned error (if size and anture of the variable aren't coherent with the assignment). Hi Oleg, Thanks for giving me the hint :-) I realised now that when I give a space before the string, the no. of columns in the matrix is no longer 1! But it is actually 2 :-) Such a silly one, but I had just overlooked it. Thanks for this. for i=1:size(num_mat,1) str_vect(i,1:2)=' X'; %Space given before X. end Many thanks to Nathan as well for all the inputs. Thanks, Vinod Karanth |