[Scilab-users] surf and %nan

Rafael Guerra jrafaelbguerra at hotmail.com
Tue Nov 21 21:34:31 CET 2017


Thanks Samuel for highlighting this non trivial point.
I take it back as the better test here below indicates that the two syntaxes are not equivalent:

x=1:100; y=1:200;
M= x.*.y';
M(10,11:99)=-999;
M(13,13)=-999;
M2 = M;

[a,b]=find(M==-999);
M(a,b) = %nan;

M2(M2==-999)= %nan;

M(isnan(M))=%pi;
M2(isnan(M2))=%pi;

-->max(M2-M)
ans  =
    1283.8584

-->min(M2-M)
ans  =
    0.

Regards,
Rafael





-----Original Message-----
From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of sgougeon at free.fr<mailto:sgougeon at free.fr>
Sent: Tuesday, November 21, 2017 8:41 PM
To: Users mailing list for Scilab <users at lists.scilab.org<mailto:users at lists.scilab.org>>
Subject: Re: [Scilab-users] surf and %nan



>It is not the most compact form but I think there is no issue with original syntax proposed:

>[a,b]=find(M==-999);

>M(a,b) = %nan;



In the M(a,b) syntax, a stands for the indices of selected ROWS, and b for the vector of selected COLUMNS, no matter about the fact that a and b have here the same length and then could be -- erroneously -- considered as respective elementwise indices.

This is why linearized indices must be used, as returned by i = find(..).



--> m = int8(grand(5,5,"uin",0,9))

m  =

  2  1  5  0  9

  2  9  5  9  9

  4  5  0  4  3

  5  8  6  7  9

  4  3  9  6  6



--> m([2 3 5],[1 2 4])

ans  =

  2  9  9

  4  5  4

  4  3  6



--> m([2 3 5]',[1 2 4]')

ans  =

  2  9  9

  4  5  4

  4  3  6



BR


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20171121/6c630fb9/attachment.htm>


More information about the users mailing list