Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

need shrter code

Asked by huda nawaf on 6 May 2012

hi,

can anybody make these code shorter and faster?

Nofusers=17856;
k1 = 1;
f1 = fopen('d:\matlab11\bin\flixster_time\ratings_tf\len_flix1.txt');
c = fscanf(f1,'%d');
fclose(f1)
ini = 1;
f   = fopen('d:\matlab11\bin\flixster_time\ratings_tf\flix_fin.txt');
cod = fscanf(f,'%d');
for i = 1:17856
  k = 1;
  for j = ini:c(i)+ini-1
    celcod{i}(k) = cod(j);
    k = k+1;
  end;
  ini = ini + c(i);
end

thanks

1 Comment

Jan Simon on 6 May 2012

This is your 109'th question in this forum. I expect that you know how to format the code.
Do you have a good reason not to care about the readability of your question?

huda nawaf

Tags

Products

No products are associated with this question.

1 Answer

Answer by Jan Simon on 6 May 2012
Accepted answer
...
celcod = cell(1, 17856);  % Pre-allocate!
ini = 1;
for i = 1:17856
  celcod{i} = cod(ini:c(i)+ini-1);
  ini = ini + c(i);
end

1 Comment

huda nawaf on 7 May 2012

thanks

Jan Simon

Contact us