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 6182571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:13:13+00:00 2026-05-24T01:13:13+00:00

I am trying to store a set of object handles in an array. The

  • 0

I am trying to store a set of object handles in an array. The objects are a series of lines generated by imline(.). I want to store the handles in order to be able to change the property of a desired line (in this case, position).

I know how to do this – however, when I try to fill a matrix with the handles of lines, an error occurs – MATLAB states that conversion from IMLINE to DOUBLE is not possible. This does not happen with other types of objects. Is there a way to circumvent this?

Here is some pseudocode to clarify:

lines=zeros(1,x);    % defining empty storage matrix
for idx=1:x
    line=imline(ax_handl,[x_1 y_1; x_2 y_2])
    set(line,'UserData',idx) % in order to identify independent lines with the number
    lines(idx)=line; % here I try to store a line handle as it's made
end

% now in the function responsible for motion of objects, I assign new position to line

line_num=get(gco,'UserData'); % this relates other objects associated with line number
setPosition(lines(line_num),[a b; c d]);
  • 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-05-24T01:13:13+00:00Added an answer on May 24, 2026 at 1:13 am

    You may need to fill your matrix with default valued lines in order to create it. The typical approach to preallocating a matrix of objects of size N would be to simply assign an object to the last element in the matrix.

    M(N,N)=imline(gca,[NaN NaN],[NaN NaN]); %# set non-displayable vals for x and y
    

    NOTE, the line above will not work with imline as it will call the default constructor for each of the other N*N-1 imline objects in the matrix and a call of imline with no arguments forces user interaction with the current axis.

    My advice (if you are pre-allocating) is to define all the default lines explicitly in the matrix:

    for k=1:N*N
        M(k)=imline(gca,[NaN NaN],[NaN NaN]);
    end
    
    %# Reshape (if necessary)
    M = reshape(M,[N N]);
    

    Alternatively, you could let Matlab fill the array for you. If you find that you will need this code often, derive a new class from imline. The following example shows the very least that would need to happen. It merely defines a constructor. This example allows you to pass optional arguments to imline as well. If no arguments are specified, the imline object is created with position values as above.

    classdef myimline<imline
        methods
    
            function obj = myimline(varargin)
                if isempty(varargin)
                    varargin = {gca,[NaN NaN],[NaN NaN]};
                end
                obj = obj@imline(varargin{:});
            end
        end
    end
    

    Example usage:

    %# Generate a 100 element array of `imline` objects, 
    %# but define the last one explicitly
    mat(100)=myimline(gca,[0 1],[0 1]);
    

    The last myimline object in the array has points specified as in the assignment, but the rest of the elements have the default position values [NaN NaN] as above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to store a set of values in delphi, but i want
I'm trying to store a set inside the object property (and read it) of
i'm trying to set a cookie to store a selected department in. The cookie
I'm new to cookies, and im trying to set a cookie where to store
I'm trying to store an xml serialized object in a cookie, but i get
I'm trying to store a user ID (key) and an array of GPS coordinates
I'm trying to store a list of generic objects in a generic list, but
I have a class that contains two arraylists which I'm trying to store objects
I'm trying to set up ehcache with JRuby Rails. Storing a Java object in
I'm trying to store object of Employee in Session (DB Based), When i do

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.