[Scilab-users] Problem with Matrix operation
Samuel Gougeon
sgougeon at free.fr
Wed Apr 26 01:33:50 CEST 2017
Le 25/04/2017 à 15:29, SCHULZ Wolfgang a écrit :
> 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?
A = zeros(5,3)
inx= [1 2 3];
iny= [1 2 3];
A(sub2ind(size(A),inx,iny))= 1 --> A(sub2ind(size(A),inx,iny)) = 1A = 1.
0. 0.0. 1. 0.0. 0. 1.0. 0. 0.0. 0. 0.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170426/58e6a067/attachment.htm>
More information about the users
mailing list