help-octave
[Top][All Lists]
Advanced

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

Re: Excluding elements of a matrix


From: antonio palestrini
Subject: Re: Excluding elements of a matrix
Date: Wed, 20 Dec 2006 00:47:13 +0100

2006/12/19, Joseph Wakeling <address@hidden>:
Thanks to all for useful replies.

How feasible would it be to implement a simple syntax for something like
this in a future version of Octave, along the lines of,

a(\6)   [i.e. a excluding element 6]

A(:,\[5 7])    [matrix A excluding columns 5 and 7]

... inspired by set notation?

If you have to work with this kind of data manipulations the best
thing to do, in my opinion, is to write a function like the following
for the matrix example (the vector one may be constructed analogously)

function B = del_columns(A,q)
# use: function B = del_columns(A,q)
#
# The function deletes the A columns specified in the vector q
  B = A;
  B(:,q) = [];
endfunction

example:
[oct 3] A=rand(6,4)
A =

 0.95370  0.53598  0.85039  0.25881
 0.63536  0.41243  0.13631  0.54626
 0.25284  0.09450  0.43455  0.19440
 0.97259  0.45803  0.66549  0.42452
 0.57042  0.45608  0.69860  0.59288
 0.95337  0.11660  0.39163  0.34055

[oct 4] q = [2 4]
q =

       2        4

[oct 5]  B = del_columns (A,q)
B =

 0.95370  0.85039
 0.63536  0.13631
 0.25284  0.43455
 0.97259  0.66549
 0.57042  0.69860
 0.95337  0.39163


ciao
antonio

--
Prof. Antonio Palestrini
DSGSS - University of Teramo, Italy
e-mail: address@hidden


reply via email to

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