print string and numbers

  • Follow


I am new to Matlabs printing tools (e.g. sprintf) and I am unable in due time to perform a very simple task. I have 2 vectors of equal length (6):
1)  Labels:  'X_003'    'X_029'    'X_046'    'X_047'    'X_056'    'const'
2)  Numbers:   -0.6467   -0.9923    0.2168    0.7864    0.3730    0.2953,
and I want to produce a nice and neat columnwise output, like
   X_003      -0.6467
   X_029      -0.9923
   ............   ..........
   const        0.2953
I have used strcat(Labels',num2str(Numbers)), but the output is awful and I have tried sprintf & fprintf, but onestly I got stuck. Please help me, thx in advance, Guido.
0
Reply jay_of_may (22) 2/8/2010 6:34:03 AM

"Guido" <jay_of_may@yahoo.com> wrote in message <hkob8r$3hf$1@fred.mathworks.com>...
> I am new to Matlabs printing tools (e.g. sprintf) and I am unable in due time to perform a very simple task. I have 2 vectors of equal length (6):
> 1)  Labels:  'X_003'    'X_029'    'X_046'    'X_047'    'X_056'    'const'
> 2)  Numbers:   -0.6467   -0.9923    0.2168    0.7864    0.3730    0.2953,
> and I want to produce a nice and neat columnwise output, like
>    X_003      -0.6467
>    X_029      -0.9923
>    ............   ..........
>    const        0.2953
> I have used strcat(Labels',num2str(Numbers)), but the output is awful and I have tried sprintf & fprintf, but onestly I got stuck. Please help me, thx in advance, Guido.

this FEX submission might be helpful

http://www.mathworks.com/matlabcentral/fileexchange/23840

us
0
Reply us1 (8054) 2/8/2010 6:57:04 AM


Many thanx us!

"us " <us@neurol.unizh.ch> wrote in message <hkocjv$nlk$1@fred.mathworks.com>...
> "Guido" <jay_of_may@yahoo.com> wrote in message <hkob8r$3hf$1@fred.mathworks.com>...
> > I am new to Matlabs printing tools (e.g. sprintf) and I am unable in due time to perform a very simple task. I have 2 vectors of equal length (6):
> > 1)  Labels:  'X_003'    'X_029'    'X_046'    'X_047'    'X_056'    'const'
> > 2)  Numbers:   -0.6467   -0.9923    0.2168    0.7864    0.3730    0.2953,
> > and I want to produce a nice and neat columnwise output, like
> >    X_003      -0.6467
> >    X_029      -0.9923
> >    ............   ..........
> >    const        0.2953
> > I have used strcat(Labels',num2str(Numbers)), but the output is awful and I have tried sprintf & fprintf, but onestly I got stuck. Please help me, thx in advance, Guido.
> 
> this FEX submission might be helpful
> 
> http://www.mathworks.com/matlabcentral/fileexchange/23840
> 
> us
0
Reply jay_of_may (22) 2/8/2010 9:44:04 AM

"Guido" <jay_of_may@yahoo.com> wrote in message <hkob8r$3hf$1@fred.mathworks.com>...
> I am new to Matlabs printing tools (e.g. sprintf) and I am unable in due time to perform a very simple task. I have 2 vectors of equal length (6):
> 1)  Labels:  'X_003'    'X_029'    'X_046'    'X_047'    'X_056'    'const'
> 2)  Numbers:   -0.6467   -0.9923    0.2168    0.7864    0.3730    0.2953,
> and I want to produce a nice and neat columnwise output, like
>    X_003      -0.6467
>    X_029      -0.9923
>    ............   ..........
>    const        0.2953
> I have used strcat(Labels',num2str(Numbers)), but the output is awful and I have tried sprintf & fprintf, but onestly I got stuck. Please help me, thx in advance, Guido.

Just be crude

for ii = 1:length(labels)
      fprintf(1, '% 7s    %3.6f\n', Labels{ii}, Numbers(ii)
end

you might need to play about a bit with the numbers in the format string to get exactly what you want. The space says to space pad, the 7 is the string field width. The flating point format takes width and precision. You might want to space pad it as well.
0
Reply malcolm.mclean5 (725) 2/8/2010 10:36:03 AM

3 Replies
22 Views

(page loaded in 0.067 seconds)


Reply: