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: strings transformation sequence optimization
Replies: 6   Last Post: May 15, 2014 9:58 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Michal Kvasnicka

Posts: 14
Registered: 5/6/14
strings transformation sequence optimization
Posted: May 14, 2014 2:20 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I have the following problem:

I need to transform encoded integer sequences c to string messages m by following association:
numpos = 4
c = [1 3 2 2, 3 2 2 1], 2*numpos integer parameters, where first numpos parameters encoded position of types = {'a' 'b@x' 'c@y'} and second numpos parameters are applied only if type conmtains character '@' like this:
m = 'a c:2@y b:2@x b:1@x'

My code is very ineffective, because more than 80% of time spent on lines:
if ismember('@',fan)
and
fansplit = strsplit(fan,'@');

for number of lines about 1000 and more is very cpu time consuming.

So, my question is: How to optimize (vectorize) this code to significantly gain computation speed? Target values are: numpos = 30, numlines = 4000
===================================================
% input data
numpos = 7;
numlines = 10;
c = repmat([3 4 1 1 4 2 5,1 1 1 1 2 2 2],numlines,1);
types = {'a' 'b@2' 'c@6' 'd@10' 'e@11'};

% number of lines
nl = size(c,1);
% message vectors declaration
m = cell(nl,1);
% loop over lines of c
for i = 1:nl
% loop over items of types
for j = 1:numpos
% current j-th type name in i-th line
fan = types{c(i,j)};
if ismember('@',fan)
% @ character type case
fansplit = strsplit(fan,'@');
m{i} = [m{i} ' ' fansplit{1} ':' num2str(c(i,numpos+j)) '@' fansplit{2}];
else
% non-@ character type case
m{i} = [m{i} ' ' fan];
end
end
end



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.