how to decrease the time consumption of the code
显示 更早的评论
Hello I've already got a lot of help in developring the encryption technique from matlab answers. Now i have another problem. I need to reduce the time consumption of the folowing part of the code.Here i generate two chaotic sequences using Chen's hyperchaotic system. I've defined a function called Chen1.m and i've given both the codes below.This part of the code is taking almost 15 minutes.Please help.Thanks in advance.
%the values of a, b, c, d, k here
a = 36;
b = 3;
c = 28;
d = 16;
k = 0.2;
%vector v0, which is a 4x1 vector of initial conditions
v0 = [0.3 -0.4 1.2 1];
fun = @(t,v) chen1(t,v,a,b,c,d,k);
[t, v] = ode45(fun, [0 1.54], v0);
x = v(:,1);
x(257)=[];
y = v(:,2);
y(257)=[];
[lx,fx]=sort(x);
[ly,fy]=sort(y);
S=fx;
T=(fy)';
%%matrix generated for scrambling
[Tgrid, Sgrid] = meshgrid( T, S );
Z = arrayfun( @(S,T) [S T], Sgrid, Tgrid, 'UniformOutput', false );
%%scrambled matrix
F=cellfun(@(x) B{x(1),x(2)},Z,'un',0);
G=cellfun(@(x) E{x(1),x(2)},Z,'un',0);
The function is defined as follows
function vdot = chen(t, v, a, b, c, d, k)
x = v(1); y = v(2); z = v(3); q = v(4);
xdot = a*(y-x);
ydot = -(x*z)+(d*x)+(c*y)-q;
zdot = (x*y)-(b*z);
qdot = x+k;
vdot = [xdot; ydot; zdot; qdot];
end
1 个评论
Adam
2014-9-4
First thing you should do is run the profiler on it:
profile on
functionCall(...)
profile off
profile viewer
That will tell you where the bottlenecks are. One of the worst things you can do when trying to speed up code is to start focusing on really speeding up a piece of code that only takes 1% of the total running time anyway.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!