Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8087023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:38:20+00:00 2026-06-05T18:38:20+00:00

i’m writing my first MATLAB O-O application and i’m confused about the implementation of

  • 0

i’m writing my first MATLAB O-O application and i’m confused about the implementation of compositions, aggregations and relationships in general.

My question is: how to implement an aggregation or an association one-to-many in matlab? Where i can take some examples?

Moreover, i’m using ArgoUml to design my application, is there any plugin to automatic code generation in matlab?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:38:22+00:00Added an answer on June 5, 2026 at 6:38 pm

    Here is a quick example of class association. The scenario consists of a course that can have many students enrolled:

    Student.m

    classdef Student < handle
        properties
            name
        end
        methods
            function obj = Student(name)
                if nargin > 0
                    obj.name = name;
                end
            end
            function delete(obj)
                fprintf('-- Student Destructor: %s\n',obj.name);
            end
        end
    end
    

    Course.m

    classdef Course < handle
        properties
            name        %# course name
            std         %# cell array of students
        end
        properties(Access = private)
            lastIdx = 1;
        end
        methods
            function obj = Course(name, capacity)
                obj.name = name;
                obj.std = cell(capacity,1);
            end
            function addStudent(obj, std)
                if obj.lastIdx > numel(obj.std)
                    fprintf(2, 'Sorry, class is full\n');
                    return
                end
                obj.std{obj.lastIdx} = std;
                obj.lastIdx = obj.lastIdx + 1;
            end
            function printClassRoster(obj)
                fprintf('Course Name = %s\n', obj.name);
                fprintf('Enrolled = %d, Capacity = %d\n', ...
                    obj.lastIdx-1, length(obj.std));
                for i=1:obj.lastIdx-1
                    fprintf('ID = %d, Name = %s\n', i, obj.std{i}.name);
                end
            end
        end
    
    end
    

    And here is a code to test the above classes:

    c = Course('CS101', 3);
    for i=1:4
        name = sprintf('amro%d',i);
        fprintf('Adding student: %s\n', name)
        c.addStudent( Student(name) )
    end
    
    fprintf('\nClass Roster:\n=============\n')
    c.printClassRoster()
    
    fprintf('\nCleaning up:\n')
    clear c
    

    The output:

    Adding student: amro1
    Adding student: amro2
    Adding student: amro3
    Adding student: amro4
    Sorry, class is full
    -- Student Destructor: amro4
    
    Class Roster:
    =============
    Course Name = CS101
    Enrolled = 3, Capacity = 3
    ID = 1, Name = amro1
    ID = 2, Name = amro2
    ID = 3, Name = amro3
    
    Cleaning up:
    -- Student Destructor: amro1
    -- Student Destructor: amro2
    -- Student Destructor: amro3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I'm making a simple page using Google Maps API 3. My first. One marker
Thanks in advance for your help. I have a need within an application to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.