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

  • Home
  • SEARCH
  • 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 8905463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:24:01+00:00 2026-06-15T02:24:01+00:00

Beginner with MATLAB here. I’m trying to write a class that will load in

  • 0

Beginner with MATLAB here. I’m trying to write a class that will load in images from a folder, and here’s what I have:

classdef ImageLoader
    %IMAGELOADER Summary of this class goes here
    %   Detailed explanation goes here

    properties
        currentImage = 0;
        filenames={};
        filenamesSorted={};
    end

    methods
        function imageLoader = ImageLoader(FolderDir)
            path = dir(FolderDir);
            imageLoader.filenames = {path.name};
            imageLoader.filenames = sort(imageLoader.filenames);
        end

        function image = CurrentImage(this)
            image = imread(this.filenames{this.currentImage});
        end

        function image = NextImage(this)
            this.currentImage = this.currentImage + 1;
            image = imread(this.filenames{this.currentImage});
        end
    end    
end

This is how I’m calling it:

i = ImageLoader('football//Frame*');
image=i.NextImage;

imshow(image);

The files are named Frame0000.jpg, Frame0001.jpg … etc.
I want the constructor to load in all the file names so that I can then retrieve the next file simply by calling i.NextImage, but I can’t get it working.


Got it working.

class:

classdef ImageLoader
    %IMAGELOADER Summary of this class goes here
    %   Detailed explanation goes here

    properties(SetAccess = private)
        currentImage
        filenames
        path
        filenamesSorted;
    end

    methods
        function imageLoader = ImageLoader(Path,FileName)
            imageLoader.path = Path;
            temp = dir(strcat(Path,FileName));
            imageLoader.filenames = {temp.name};
            imageLoader.filenames = sort(imageLoader.filenames);
            imageLoader.currentImage = 0;
        end

        function image = CurrentImage(this)
            image = imread(this.filenames{this.currentImage});
        end

        function [this image] = NextImage(this)
            this.currentImage = this.currentImage + 1;
            image = imread(strcat(this.path,this.filenames{this.currentImage}));
        end
    end    
end

call:

i = ImageLoader('football//','Frame*');
[i image]=i.NextImage;

imshow(image);
  • 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-15T02:24:02+00:00Added an answer on June 15, 2026 at 2:24 am

    AFAIK you can’t change the state of an object (as you do when incrementing the currentimage pointer) without explicitly updating the value of the object itself at the end. AFAIK every function call passes objects byval, that means that NextImage just modifies a local copy of this (which is not a pointer/reference to the current object, rather a copy).

    Thus, what you can do is writing your method as

      function [this image] = NextImage(this)
            this.currentImage = this.currentImage + 1;
            image = imread(this.filenames{this.currentImage});
      end
    

    and call it as

     [i image]=i.NextImage;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner programmer here....hope it makes sense :) I have created a console app that
beginner to python here. I have 2 nested lists that I want to merge:
Beginner iOS dev here. I have a problem in my array. Im making an
Beginner here trying to get a pipeline working in bash. If somebody can see
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Python beginner here, I have a list of lists and want to refer to
I'm a super beginner to MatLab, and I'm trying to debug a simple script
Beginner question here. I'm going to make a Jquery function that is used to
I'm a MATLAB beginner. Here's the problem: >> a = floor(7/2.5) a = 2.00
I'am a beginner for using MATLAB. I have a question. The function f(x; y)

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.