[Scilab-users] Problem with Matrix operation

CRETE Denis denis.crete at thalesgroup.com
Tue Apr 25 16:46:34 CEST 2017


Hello,
This should do the job if values different for a matrix containing only 0's and 1's:

inx=[1 2 3];
iny=[1 2 3];
A=sparse([inx;iny]',ones(inx'),[5,3]);
full(A)

If non-indexed values are not known (and A already exists) then
A(inx+size(A,'r')*(iny-1))=1;

HTH
Denis

[@@ THALES GROUP INTERNAL @@]

Unité Mixte de Physique CNRS / THALES
1 Avenue Augustin Fresnel
91767 Palaiseau CEDEx - France
Tel : +33 (0)1 69 41 58 52 Fax : +33 (0)1 69 41 58 78 
e-mail : 
 denis.crete at thalesgroup.com <mailto:%20denis.crete at thalesgroup.com>
 http://www.trt.thalesgroup.com/ump-cnrs-thales
 http://www.research.thalesgroup.com

-----Message d'origine-----
De : users [mailto:users-bounces at lists.scilab.org] De la part de SCHULZ Wolfgang
Envoyé : mardi 25 avril 2017 15:30
À : Users mailing list for Scilab
Objet : [Scilab-users] Problem with Matrix operation

Hello,
I want to set certain elements of a matrix to 1. Interestingly the following code fills 9 elements with 1. I expected to have only 3 elements (with index 1,1; 2,2 and 3,3) filled with 1.

A=zeros(5,3)
inx=[1 2 3];
iny=[1 2 3];
A(inx,iny)=1

Is there any way to fill a matrix with 1 where I have the indexes in 2 vectors?

Thanks for your help
Wolfgang
_______________________________________________
users mailing list
users at lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users



More information about the users mailing list