matlab field range now has more flexibility

pull/1/head
Thorsten Liebig 2011-09-14 16:38:59 +02:00
parent a85917e058
commit 6a8b6dadae
1 changed files with 20 additions and 10 deletions

View File

@ -5,9 +5,9 @@ function [field_i mesh_i] = GetField_Range(field, mesh, range)
%
% example:
% % specify a mesh range
% range{1} = [0 150] * 1e-3;
% range{2} = [0 0];
% range{3} = [-850 -400] * 1e-3;
% range{1} = [0 150] * 1e-3; % x in range 0..150mm
% range{2} = [0]; % only one line close to y==0
% range{3} = []; % no range restriction
%
% % read hdf data
% [field mesh] = ReadHDF5Dump('Et.h5');
@ -25,13 +25,23 @@ function [field_i mesh_i] = GetField_Range(field, mesh, range)
mesh_i = mesh;
for n=1:3
ind_range{n} = find( mesh.lines{n}>=range{n}(1) & mesh.lines{n}<=range{n}(2));
if (isempty(ind_range{n}))
ind_range{n} = find( mesh.lines{n}>=range{n}(1) , 1, 'first');
end
if (isempty(ind_range{n}))
ind_range{n} = find( mesh.lines{n}<=range{n}(2) , 1, 'last');
if (numel(range{n})==0)
ind_range{n} = [];
ind_range{n} = 1:numel( mesh.lines{n});
elseif (numel(range{n})==1)
ind_range{n} = find( mesh.lines{n}>=range{n}(1) , 1);
if (isempty(ind_range{n}))
ind_range{n} = find( mesh.lines{n}>=range{n}(1) , 1, 'first');
end
if (isempty(ind_range{n}))
ind_range{n} = find( mesh.lines{n}<=range{n}(2) , 1, 'last');
end
else
ind_range{n} = find( mesh.lines{n}>=range{n}(1) & mesh.lines{n}<=range{n}(2));
end
mesh_i.lines{n} = mesh.lines{n}(ind_range{n});