Thread Subject: sorting of array of object

Subject: sorting of array of object

From: Syed

Date: 2 Nov, 2009 11:59:03

Message: 1 of 1

Hi!
Here is my code. I need to sort array of objects. So, I created an array of dimension
n x 2. In first column I store the object and in second column I store the value on which I need to sort the 2nd column. Kindly suggest me anything.

classdef square
    properties
        x
        y
        area
    end
    methods
        function this= square()
            this.x=1+floor(10*rand*.999999);
            this.y=1+floor(10*rand*.999999);
            this.area = this.x * this.y;
        end
        function this =makeArray(this)
            for i = 1 : 10;
% array{i,1}= this.y;
% array{i,2}= this.x;
            array{i,1}= square();
            array{i,2}=array{i,1}.x;
            end
            array
            e= sortrows(array,2); %%%%%%%%%%%% Problem Here
        end
    end
end

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
oop per isakson 2 Nov, 2009 13:37:44
array of objects Hasan Yousuf 2 Nov, 2009 07:04:04
object oriented Hasan Yousuf 2 Nov, 2009 07:04:04
rssFeed for this Thread

Contact us at files@mathworks.com