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