help-octave
[Top][All Lists]
Advanced

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

Re: Deleting equal rows/columns in matrix


From: AlbFrigerio
Subject: Re: Deleting equal rows/columns in matrix
Date: Wed, 20 Oct 2010 07:36:21 -0700 (PDT)

I forgot a thing : in the case of the previous matrix I could transform every
row in an integer number my making

A * 10.^[size(A,2)-1:-1:0]' ,

in this case if in two rows I get the same value it means that the same rows
in the matrix are equal. Similar procedure using A' for the columns?

Three problems for the general case :
1) What should I do if a matrix entry is greater than 9 ?
2) What should I do if the matrix has real entries ?
3) What should I do if the matrix has both positive and negative entries ?

   Alberto



AlbFrigerio wrote:
> 
> Thank you Ben and Fotios, you gave me correct answers, but I believe I
> have not explained well my problem. I don't want to delete "una tantum" a
> row or a column, I want that my program, given the following matrix as
> input
> 
> A = [1 0 1 0 9 0 1 ; 1 0 1 0 1 9 1 ; 0 1 9 1 0 1 9 ;  1 1 1 1 1 0 9 ; 1 0
> 1 0 1 9 1; 1 1 1 1 0 1 9] 
> 
> deletes the 5th row because it is the same of the 2nd one, or the 4th
> column (equal to the 2nd one). Obviosly it is "easy" to look manually for
> the duplicates in a small matrix like the previous one, but imagine your
> matrix to have more rows and colums.
> 
> Thanks again,
>   Alberto
> 
> 
> 
> Fotios Kasolis wrote:
>> 
>> 
>> On Oct 20, 2010, at 3:27 PM, AlbFrigerio wrote:
>> 
>>>
>>> Hello world, I got a problem I'm trying to solve on my own, but I  
>>> really
>>> don't know if I would solve it, hence I'm asking "in advance" your  
>>> help.
>>>
>>> The question is quite simple : is there a (simple) way to delete in  
>>> a matrix
>>> the already existing rows or columns?
>>>
>>> I might use for loops asking isequal(A(i,:),A(j,:) \forall i,j , but  
>>> I hope
>>> there is a nicer way. I tried to use the outer product with function
>>> @isequal , but I reach results I don't understand :(
>>> Just as an information, I don't have a real matrix, but an integer  
>>> one whose
>>> lines are combination of {0,1,9} . If I got only {0,1} values I  
>>> would have
>>> used binary transformation, but I got three elements and, by the  
>>> way, I'm
>>> looking for the solution of the general problem.
>>>
>>> Thank you so much, in the rest of the day I'll try to solve it, if I  
>>> don't
>>> reach any solution ... I hope someone of yours do !!
>>>
>>>   Alberto
>>> -- 
>>> View this message in context:
>>> http://octave.1599824.n4.nabble.com/Deleting-equal-rows-columns-in-matrix-tp3003845p3003845.html
>>> Sent from the Octave - General mailing list archive at Nabble.com.
>>> _______________________________________________
>>> Help-octave mailing list
>>> address@hidden
>>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>> 
>> a) If you want to remove entire rows/cols use an assignment to the  
>> empty matrix like
>>  > A = repmat (1:5,5,1)
>>  > A(:,1) = [] # this line removes the first column
>> 
>> b) Just for your information if you want to conditionally modify  
>> elements use the function find
>>  >  A = repmat (1:5,5,1)
>>  > A(find (A>3)) = 1
>> 
>> the same could be done (without using find) as follows
>>  >  A = repmat (1:5,5,1)
>>  > A(A>3) = 1
>> 
>> To relate the above to your problem you can set for instance a special  
>> value to the elements you want to remove
>>  >  A = repmat (1:5,5,1)
>>  > A(A>3) = nan
>> 
>> and then extract a matrix without those nans by using
>> 
>>  > B = A(! isnan(A))
>> 
>> Enjoy!
>> 
>> /Fotios
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>> 
>> 
> 
> 

-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/Deleting-equal-rows-columns-in-matrix-tp3003845p3004003.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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