Demo entry 6354583

11

   

Submitted by anonymous on Apr 09, 2017 at 10:43
Language: Matlab. Code size: 1.4 kB.

%%%%%%%%%%%%%%%%%%%%%%%´úÂë6£ºÊä³öº¯Êý%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%Êä³öDZÁ÷½»»»ÌØÕ÷²ÎÊý%%%%%%%%%%%%%%%%%%%%%
function f = particle_output()

%ÒýÈëÈ«¾Ö±äÁ¿
global workplace
global boundry
global timestep

%´ÓÈ«¾Ö±äÁ¿¶ÁÈ¡¼ÆËãÊý¾Ý
boundry_x = sort(boundry(1,:));
boundry_y = sort(boundry(2,:));
max_step = timestep(2);

%¶¨ÒåDZÁ÷½»»»ÌØÕ÷²ÎÊý±äÁ¿
particle_distance = []; %DZÁ÷½»»»¾àÀë
particle_depth = []; %DZÁ÷½»»»Éî¶È
particle_time = []; %DZÁ÷½»»»Ê±¼ä

%´ò¿ª¼Ç¼Á£×ÓÔ˶¯¹ì¼£µÄÎļþÒÔ¶ÁÈ¡Êý¾Ý
fid = fopen([workplace,'\particle.txt'],'r');
%Ñ­»·¶ÁÈ¡Á£×ӹ켣
while ~feof(fid)    
    x = str2num(fgetl(fid));
    y = str2num(fgetl(fid));
    t = str2num(fgetl(fid));
    %¼ÆËãDZÁ÷½»»»ÌØÕ÷²ÎÊý
    if length(t) < max_step && y(end)>boundry_y(2) && x(end)>boundry_x(1) && x(end)< boundry_x(end)
        dx = [x,0]-[0,x];
        dx = dx(2:end-1);
        dy = [y,0]-[0,y];
        dy = dy(2:end-1);
        particle_distance(end+1) = sum((dx.^2+dy.^2).^0.5);
        particle_depth(end+1) = abs(max(y) - min(y));
        particle_time(end+1) = max(t);
    end    
end

%Êä³öDZÁ÷½»»»ÌØÕ÷²ÎÊý
fprintf('DZÁ÷½»»»Æ½¾ùÍ£Áôʱ¼ä£º%s Ãë\n',num2str(mean(particle_time)));
fprintf('DZÁ÷½»»»Æ½¾ùǨÒƾàÀ룺%s Ã×\n',num2str(mean(particle_distance)));
fprintf('DZÁ÷½»»»×î´ó½»»»Éî¶È£º%s Ã×\n',num2str(max(particle_depth)));
fclose(fid);

%·µ»Øº¯Êý
return

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).