[Scilab-users] basic question ?

Tim Wescott tim at wescottdesign.com
Sun Apr 23 22:59:20 CEST 2017


This is horrible, but should do what you intend:

B(i,1) = A(j + size(A, 1) * (k - 1));

It works because you can address a 2D matrix as a 1D matrix, with A(1)
== A(1, 1), A(2) = A(2, 1), A(size(A, 1) + 1) = A(1, 2), etc.

On Sun, 2017-04-23 at 22:25 +0200, paul.carrico at free.fr wrote:
> Hi All
> 
> I'm sorry if my question is "basic", but I've not understood why the
> following code does not work ... size of i,j,k seems correct
>  
> Do I miss something?
>  
> Thanks for your time
>  
> Paul
> 
> ##############################
> mode(0)
> 
> n = 10;
> 
> A = rand(n,6);
> B = zeros((2*n),2); C = B;
> 
> // goal is to get the value of the 1rst and 4th column in 2 lines
> i = [1 : (2*n)]';
> j = [1 : n]'.*.ones(2,1); // gives [1 1 2 2 3 3 .... n n]'
> k = ones(n,1).*.[1 4]';  // gives [1 4 1 4 1 4 .... 1 4]'
> 
>  tmp = [i j k] // to visualize the indexes
> 
> //B(i,1) = A(j,k); // does not work??
> C(1,1) = A(1,1);
> C(2,1) = A(1,4);
> C
> A
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432






More information about the users mailing list