[Scilab-users] basic question ?

paul.carrico at free.fr paul.carrico at free.fr
Sun Apr 23 23:15:38 CEST 2017


Thanks for your answer 

I found another way ... not necessarily better than your one and
probably more costly :-( 

Paul 
###################################################" 

n = 10;

A = rand(n,6);
B = zeros((2*n),2); 

// goal is to get the value of the 1rst and 4th column
i = [1 : n]';
j = [1 : 2 : 2*n]';
k = [2 : 2 : 2*n]';

// tmp = [i j k]

i = [1 : n]';
j = [1 : 2 : 2*n]';
k = [2 : 2 : 2*n]';

B(j,1) = A(i,1);
B(k,1) = A(i,4);

Le 2017-04-23 22:59, Tim Wescott a écrit : 

> 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 [1]
> Control & Communications systems, circuit & software design.
> Phone: 503.631.7815
> Cell:  503.349.8432
> 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
 

Links:
------
[1] http://www.wescottdesign.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170423/a76e523e/attachment.htm>


More information about the users mailing list