comp.soft-sys.matlab
[Top] [All Lists]

Re: vectorize cell array

Subject: Re: vectorize cell array
From: "Titus Edelhofer"
Date: Fri, 30 Sep 2005 18:10:13 +0200
Newsgroups: comp.soft-sys.matlab
Hi ysjung,

for some functions (including length), you can use cellfun:

num = cellfun('length',strvec)

Titus

"ysjung" <yusjungcu@xxxxxxxxx> schrieb im Newsbeitrag 
news:ef16bda.-1@xxxxxxxxxxxxxxxxxxx
> Is there way I can vectoize for loop below? I noticed in cell array
> you are limited when it comes to characters.
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> strvec = {'Set' 'ASCIIIIIIII' 'textas' 'yuioop'};
>
> for i = 1:length(strvec),
>  num(i) = length(char(strvec(i)))
> end
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> I am kinda looking for length of each character on this array, strvec
> = [3 11 6 6];
>
> the above code does the job, but just want to find out if there is
> simpler way. 



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy