MATLAB: Error using text()

bugtext;

I want to put a text on a plot using the following code:
x_pos=0.0031;
y_pos=0.0507
str_=['R^2 (%) = ' num2str(R_squared)];
text(x_pos,y_pos , str_)
it used to work but now it refuses to work and gave me the following error:
??? Error using ==> text
Not enough input arguments.
However, if I use the following code, it will work:
text(0.0031, 0.0507 , str_)
I don't know what the problem is. Could you please help me about that?

Best Answer

  • Works here:
    clear all,close all,clc
    R_squared = .5;
    x_pos=0.0031;
    y_pos=0.0507;
    str_=['R^2 (%) = ' num2str(R_squared)];
    text(x_pos,y_pos , str_)
    I see some text on an axes...
    %
    %
    %
    EDIT
    I see what you mean now. I get the same error when y is single. If x is single, I get a different error. As I don't see this documented anywhere, I wonder if it is a bug. For now, doing this will make sure you get your text:
    text(double(x_pos),double(y_pos),str_)
    %
    %
    %
    %
    EDIT#2
    I think this is buggy. This works with singles, but the other calling format, see above, doesn't:
    R_squared = .5;
    x_pos=single(0.0031);
    y_pos=single(0.0507);
    str_=['R^2 (%) = ' num2str(R_squared)];
    text('position',[x_pos,y_pos] ,'string',str_)