[Scilab-users] Vectorfind with accuracy
Stéphane Mottelet
stephane.mottelet at utc.fr
Mon Nov 12 17:52:05 CET 2018
Le 12/11/2018 à 16:15, Izabela Wójcik-Grząba a écrit :
> Hello,
>
> I am wondering if it is possible to use "vectorfind" function with a
> given accuracy so it could find equal vectors even when there is a
> slight difference between their elements.
>
> Thank you in advance.
> Kind regards,
> Iza
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
>
Hello,
Please find attached a tweaked version of vectorfind with a fourth
argument "tol". It can output the following stuff
alr=[1,2,2;
1.0001,2,1;
1,1,2;
1,1,1;
1,2,1];
ind = vectorfindtol(alr,[1,2,1],'r',1e-4)
ind =
2. 5.
S.
--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
-------------- next part --------------
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) 2010 - DIGITEO - Vincent COUVERT
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.
function ind=vectorfindtol(m,v,job,tol)
rhs = argn(2);
// Check number of inputs, at least 2 needed
if rhs < 2 then
error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"), "vectorfind", 2, 3));
end
// Set default value for job if not given
if rhs < 3 then
job = "r";
end
if rhs < 4 then
tol=0
end
// Check that m and v have the same type
if typeof(m) <> typeof(v) then
error(msprintf(gettext("%s: Incompatible input arguments #%d and #%d: Same type expected.\n"), "vectorfind", 1, 2));
end
if min(size(v))<>1 then
error(msprintf(gettext("%s: Wrong size for input argument #%d: Vector expected.\n"),"vectorfind",2));
end
if convstr(part(job,1))=="r" then
if size(v,"*")<>size(m,2) then
error(msprintf(gettext("%s: Wrong size for input arguments: Incompatible sizes.\n"),"vectorfind"));
end
ind=1:size(m,1)
for k=1:size(m,2)
ind=ind(find(abs(m(ind,k)-v(k))<=tol));
if ind==[] then
break
end
end
elseif convstr(part(job,1))=="c" then
if size(v,"*")<>size(m,1) then
error(msprintf(gettext("%s: Wrong size for input arguments: Incompatible sizes.\n"),"vectorfind"));
end
ind=1:size(m,2)
for k=1:size(m,1)
ind=ind(find(abs(m(k,ind)-v(k))<=tol))
if ind==[] then
break
end
end
else
error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"vectorfind",3,"r[ow]","c[olumn]"));
end
endfunction
More information about the users
mailing list