help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference of columns


From: Bård Skaflestad
Subject: Re: Difference of columns
Date: Thu, 29 Aug 2013 15:19:57 +0200

On Thu, 2013-08-29 at 14:58 +0200, george brida wrote:
> Dear Bard and Ismael, thank you very much
> to explicit my question, suppose a matrix A having 4
> columns:C_1,C_2,C_3 and C_4,
> I would like a code giving me a matrix B having three
> columns:C_1-C_2,C_1_C_3 and C_2-C_3

Don't you mean six columns for the case of N=4, i.e.,

        1-2, 1-3, 1-4, 2-3, 2-4, 3-4

?

I really hope this isn't homework, because it sounds very much like an
exercise in indexing...

Anyway, here's one (rather memory intensive) option:

        [i, j] = meshgrid(1 : size(C,2));
        B = C(:, i(tril(i, -1) > 0)) - C(:, j(tril(j, -1) > 0))


Regards,
-- 
Bård Skaflestad <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]