matlab中怎么做出不同颜色的曲线,代码如下

2025-03-12 13:55:16
推荐回答(3个)
回答1:

clear;

clc;

str=[];

x=[10 20 30];

y=[1 4 8];

t=0:0.5:10;

colorstring={'y','m','c','r','g','b','k','r.','bo','cx'};


for i=1:3

    for j=1:3

        figure(1);

        a=sin(t*x(i)*y(j));

        plot(t,a,colorstring{(i-1)*3+j});

        hold on;

        figure(2);

        b=cos(t*x(i)*y(j));

        plot(t,b,colorstring{(i-1)*3+j});

        hold on;

        str=[str;['i=',num2str(x(i)),',j=',num2str(y(j))]];

    end

end


figure(1);

legend(str);

figure(2);

legend(str);


回答2:

clear;
clc;
str=[];
x=[10 20 30];
y=[1 4 8];
t=0:0.5:10;

for i=1:3
for j=1:3
figure(1);
a=sin(t*x(i)*y(j));
plot(t,a,'g');
hold on;
figure(2);
b=cos(t*x(i)*y(j));
plot(t,b,'r');
hold on;
str=[str;['i=',num2str(x(i)),',j=',num2str(y(j))]];
end
end

figure(1);
legend(str);
figure(2);
legend(str);

回答3:

你的col是一个cell数组,应该用花括号,即col{2}