-2

I got this error in matlab Undefined variable "txt" or class "txt". I know that i should define txt to solve the problem. The biggest problem is that i dont know what txt is. I have tried txt=1, but this didn't work. I have this code right now

    clr     =   [0 0 0 ; 1 0 0 ; 0 1 0 ; 0 0 1 ; 1 1 0 ; 1 0 1 ; 0 1 1];
    style   =   [{'-'} {':'} {'--'} {'-.'}];
    nc      =   1;
    ns      =   1;
    n       =   1;
    l(n)    =   1;

    close all
    p       =   plot(XX,YY,'ro','MarkerFaceColor','b','MarkerSize',20);
    axis equal
    V       =   axis;
    r_x     =   (V(2) - V(1))/ 20;
    r_y     =   (V(4) - V(3))/ 20;
    axis([V(1)-r_x V(2)+r_x V(3)-r_y V(4)+r_y]);
    hold on
    for i=1:airports
        t(i)    =   text(XX(i),YY(i),['\bfA'num2str(i)],'HorizontalAlignment','Center','VerticalAlignment','Middle','Color','w');
       for j= 1:airports
            j=1;
            if Pax(i,j) >= cplex.Param.mip.tolerances.integrality.Cur
                l(n)    =   line([XX(i) XX(j)],[YY(i) YY(j)],'Color',clr(nc,:),'LineStyle',style{ns},'LineWidth',Flights(i,j));
                nc      =   nc + 1;
                if nc > size(clr,1)
                    ns      =   ns + 1;
                    nc      =   1;
                end
                txt{n}  =   ['A' num2str(i) '\leftrightarrow' 'A' num2str(j) ', ' num2str(Pax(i,j)) ' Pax, ' num2str(Flights(i,j)) ' Flight(s)'];
                n       =   n + 1;
            end

    end
    n       =   (n - 1);
    legend(l(1:n),txt{1:n},'Location','EastOutside');
    uistack(p,'top');
    uistack(t,'top');
    set(gcf,'Units','Centimeters');
    set(gcf,'Position',[10 2 25 16]);

txt is there twice. first txt{n}= ..... and then it is used in the legend function. What should i call txt or what should i do to solve this

1 Answer 1

0

I'm guessing your condition if Pax(i,j) >= cplex.Param.mip.tolerances.integrality.Cur is never true, so txt never gets defined and when you try to use it as an argument to your legend function call, it quite rightly errors out, as it doesn't exist.

Put a break point before/after your inequality test and check your variables are what you expect them to be. Also check whether the inequality holds true.

1
  • yes you are right the pax(i,j) is a matrix with zeros. So this will indeed never be true!
    – Marlon--
    Oct 4, 2013 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.