2

I have vectors m, x, y & I want m1, x1, y1 as commented below:

% given
m = [-4 -3 -2 2 3 4];
x = [2 5 6 7 9 1];
y = [10 23 34 54 27 32];

% required
% m1 = [2 3 4];    % only +ve value from m
% x1 = [13 14 3];  % adding numbers(in x) corres. to -ve & +ve value in m & putting below 2, 3, 4  respectively
% y1 = [88 50 42]; % adding numbers(in y) corres. to -ve & +ve value in m & putting below 2, 3, 4  respectively

m1 = m(m > 0)      % this gives me m1 as required

Any hint for x1, y1 will be very helpful.

4

2 回答 2

1

Assuming m is built as [vectorNegativeReversed, vectorPositiveOriginal] the solution can be quite straightforward:

p = numel(m)/2;
m1 = m(p+1:end)
x1 = x(p+1:end) + x(p:-1:1)
y1 = y(p+1:end) + y(p:-1:1)
于 2013-11-13T12:37:40.923 回答
0

What about some flippy action:

m = [-4 -3 -2 2 3 4];
x = [2 5 6 7 9 1];
y = [10 23 34 54 27 32];

idx = find(  (m > 0) );
xdi = find( ~(m > 0) );

m1 = m(idx)
x1 = fliplr( x(xdi) ) + x(idx)
y1 = fliplr( y(xdi) ) + y(idx)

returning:

m1 =

     2     3     4


x1 =

    13    14     3


y1 =

    88    50    42
于 2013-11-13T11:49:23.510 回答