我在 matlab 未定义变量“txt”或类“txt”中收到此错误。我知道我应该定义 txt 来解决问题。最大的问题是我不知道txt是什么。我试过txt = 1,但这不起作用。我现在有这个代码
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 有两次。首先 txt{n}= ..... 然后在图例函数中使用。我应该怎么称呼 txt 或者我应该怎么做才能解决这个问题