Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem: gline() returns immediately. Anyone else have this prob?

Subject: Problem: gline() returns immediately. Anyone else have this prob?

From: Pat Finder

Date: 3 Aug, 2012 17:08:15

Message: 1 of 2

I am writing an application where I want to graph some points, and have the user draw a line in the data. Then I want to use the information about where the user drew the line.

I am trying to use gline(), but it returns immediately. In other words, it seems to spawn a thread that handles the user input for the line. However, the main thread returns control to the function immediately.

So, the main function cannot use the results of the drawing, because it hasn't finished yet.

I am using gline() instead of ginput(2) because I want the rubberband line to be drawn while the user is putting in the line.

I have a work-around, but having to use a pause() statement, and have the user hit return is a kludge.

Has anyone else seen this behavior? Anyone know a secret mode to put the figure in so that gline() doesn't return immediately? Is there a secret handshake I don't know?

I am using a Mac, and 2011b.

% SAMPLE CODE:--------------------------------------------------------------------------

function TEST_3D_input_v03b_for_MatlabNewsgroup()
% Demonstrate the problem that gline() is not a blocking call.
% gline() returns control immediately to the user,
% which creates a problem because the user wants to
% use the results of the call.

rand('seed', 1234 );
    n_pts = 32;
    cls1 = (rand( n_pts, 3 )-0.5)* 4 + repmat( 3*[1 1 1], n_pts, 1 );
    cls2 = (rand( n_pts, 3 )-0.5)* 4 + repmat( 6*[1 1 1], n_pts, 1 );

    projMat = [ -0.4924 0.8704 0 0 ; ...
                  0.5358 0.3032 0.7880 0 ; ...
                  0.6858 0.3880 -0.6157 0 ; ...
                       0 0 0 1.0000 ] ;
    xyz1H = [ cls1' ; ones(1,n_pts) ];
    qrst1 = projMat * xyz1H;
    
    xyz2H = [ cls2' ; ones(1,n_pts) ];
    qrst2 = projMat * xyz2H;
    
    fig2 = figure();
    plot( qrst1(1,:), qrst1(2,:), 'ks' );
    hold on;
    plot( qrst2(1,:), qrst2(2,:), 'bo' );
    axis equal;
    cAxis = axis(); % Current axes.
    
    % Get points in the new qrst space:
    disp('INPUT TWO POINTS ON THE DIVIDING LINE, and hit return when done:');
    hLine = gline(fig2);
    
    % Wait for gline input:
    beep;
    
    disp('Should not terminate before gline() returns.\n');
end

Subject: Problem: gline() returns immediately. Anyone else have this prob?

From: Pat Finder

Date: 7 Aug, 2012 12:52:10

Message: 2 of 2

In other words -- gline( ) is non-modal.
I want a way to make the figure modal until gline( ) returns.

Tags for this Thread

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.

Contact us