Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Length of strings?
Replies: 3   Last Post: Nov 22, 2005 4:43 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Duane Bozarth

Posts: 298
Registered: 1/25/05
Re: Length of strings?
Posted: Nov 22, 2005 2:12 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"M.L." wrote:
>
> Hi NG,
>
> I have a matrix containing a number of strings:
>
> 'name_1'
> 'name2'
> 'name3'
> 'name4'
>
> In a loop, I assign a variable (currentName) to contain string number
> (i) from the array.
>
> How do I, in the loop, get the length of the current string contained
> in "currentName"? I have tried everything, but I can only get ans = 1
> ?!


What, specifically does "everything" include? :)

However, Matlab matrices have to be conformable so that each string in
the array will be blank-padded to the length of the longest string.

Something like

str_ary = str2mat('name_1', 'name2');
for i = 1:2
str_len = length(str_ary(i,:))
end

will show 6 for both strings.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.