help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strjust


From: Leo Butler
Subject: Re: strjust
Date: Fri, 15 Oct 2010 08:14:49 +0100 (BST)
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)


On Thu, 14 Oct 2010, Ozzy Lash wrote:

< On Thu, Oct 14, 2010 at 4:42 PM, Ben Abbott <address@hidden> wrote:
< > On Oct 14, 2010, at 1:58 PM, Ozzy Lash wrote:
< >
< >> On Thu, Oct 14, 2010 at 3:06 PM, Ben Abbott <address@hidden> wrote:
< >>>
< >>> On Oct 14, 2010, at 12:20 PM, Ozzy Lash wrote:
< >>>
< >>>> On Thu, Oct 14, 2010 at 10:36 AM, Ben Abbott <address@hidden> wrote:
< >>>>> On Oct 14, 2010, at 7:03 AM, Leo Butler <address@hidden> wrote:
< >>>>>
< >>>>>> On Wed, 13 Oct 2010, Ben Abbott wrote:
< >>>>>>
< >>>>>> < On Oct 13, 2010, at 12:16 AM, Leo Butler <address@hidden> wrote:
< >>>>>> <
< >>>>>> < > In 3.3.52+, I find the following behaviour of strjust,
< >>>>>> < > which appears to conflict with its description.
< >>>>>> < >
< >>>>>> < > octave> s=sprintf("\tstring");
< >>>>>> < > octave> s=strjust(s,"left")
< >>>>>> < > s =     string
< >>>>>> < > octave> s=sprintf("        string");
< >>>>>> < > octave> s=strjust(s,"left")
< >>>>>> < > s = string
< >>>>>> < >
< >>>>>> < > You can see that it is not removing leading tabs.
< >>>>>> < >
< >>>>>> < > Leo
< >>>>>> <
< >>>>>> < Does the description below clarify how strjust functions?
< >>>>>> <
< >>>>>> < strjust (S)
< >>>>>> < strjust (S, "right")
< >>>>>> < Returns the text, S, justified to the right.
< >>>>>> < strjust (S, "left")
< >>>>>> < Returns left justified text.
< >>>>>> < strjust (S, "center")
< >>>>>> < Returns center justified text.
< >>>>>> < Null characters are replaced by spaces.
< >>>>>>
< >>>>>> Here is the info description:
< >>>>>>
< >>>>>>  -- Function File:  strjust (S, ["left"|"right"|"center"])
< >>>>>>       Shift the non-blank text of S to the left, right or center of the
< >>>>>>       string.  If S is a string array, justify each string in the 
array.
< >>>>>>        Null characters are replaced by blanks.  If no
< >>>>>>        justification is
< >>>>>>      specified, then all rows are right-justified.
< >>>>>>
< >>>>>> By comparison:
< >>>>>> -- Function File:  strtrim (S)
< >>>>>>      Remove leading and trailing blanks and nulls from S.
< >>>>>>
< >>>>>> And here is how each works:
< >>>>>>
< >>>>>> octave> s=sprintf("\tstring");
< >>>>>> octave> strjust(s,"left")
< >>>>>> ans =   string
< >>>>>> octave> strtrim(s)
< >>>>>> ans = string
< >>>>>>
< >>>>>> You see that the definition of 'blank' is inconsistent.
< >>>>>>
< >>>>>> Leo
< >>>>>
< >>>>> I've pushed the change below.
< >>>>>
< >>>>> http://hg.savannah.gnu.org/hgweb/octave/rev/04c3aacbbc46
< >>>>>
< >>>>> Thanks
< >>>>> Ben
< >>>>>
< >>>>
< >>>> I think I agree with Leo, and that tabs should be treated as
< >>>> whitespace (or blanks) and should be stripped for justification,  If
< >>>> not, I think that there is an issue for right justification as well.
< >>>>
< >>>
< >>> Ok. I hadn't realized Leo was asking that the way strjust() works should 
be changed.
< >>>
< >>> How might strjust() be modified and remain compatible with Matlab?
< >>>
< >>> Ben

Ben, thanks for looking into this.

To clarify: my original email was a genuine inquiry, not a request
for change. However, would it not be possible to modify strjust so that
the definition of whitespace can be input by the user, e.g.

strjust(string,"left",[9,32])
strjust(string,"right",[" ","\t"])

The default behaviour need not change.

Leo




< >>>
< >>>
< >>
< >> Not having access to Matlab, I'm not sure what it does in these cases.
< >> It would be interesting to see what matlab does with the above, and
< >> also with strings that have embedded or trailing tabs.  Here is a stab
< >> at a test case:
< >>
< >> a=["test 1";"\ttest 2";"test\t3";"test 4\t"]
< >> strjust(a,"left")
< >> strjust(a,"right")
< >> strjust(a,"center")
< >>
< >> I can see that handling the tab case may be difficult, since it would
< >> normally be translated to a different number of spaces depending where
< >> it is being printed, and possibly Matlab will give the same results as
< >> octave, it just seems a little counter intuitive.
< >>
< >> Bill
< >
< > To work properly with Matlab, I modified the script as ...
< >
< > str1 = sprintf('test 1 ');
< > str2 = sprintf('\ttest 2');
< > str3 = sprintf('test\t3 ');
< > str4 = sprintf('test 4\t');
< > a = [str1; str2; str3; str4];
< > for n = 1:size(a,1)
< >  fprintf ('"%s"\n', strjust(a(n,:),'left'))
< >  fprintf ('"%s"\n', strjust(a(n,:),'right'))
< >  fprintf ('"%s"\n', strjust(a(n,:),'center'))
< > end
< >
< > The result is
< >
< > "test 1 "
< > " test 1"
< > "test 1 "
< > "       test 2"
< > "       test 2"
< > "       test 2"
< > "test   3 "
< > " test  3"
< > "test   3 "
< > "test 4 "
< > "test 4 "
< > "test 4 "
< >
< > The tabs are treated the same as the alpha-numerics.
< >
< > The MathWorks site is down (for me) at the moment ... but please try to 
look at how they've defined strjust() to work. An old, but mirrored version, is 
at the link below.
< 
< >        
http://amath.colorado.edu/computing/Matlab/OldTechDocs/ref/strjust.html
< >
< > Ben
< >
< >
< 
< It looks like the Octave behavior,  is consistent with Matlab then.
< So your clarification in the documentation should clear up any
< confusion.
< 
< The Matlab documentation isn't very descriptive.
< 
< Bill
< 
< _______________________________________________
< Help-octave mailing list
< address@hidden
< https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
< 
< 
-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]