a=[0 1 2 3 4 5];
j=1,k=1,l=1;
for i=0:5
switch mod(i,3)
case 1
b(j)=a(i);
j=j+1;
case 2
c(k)=a(i);
k=k+1;
otherwise
d(l)=a(i);
l=l+1;
end
end
b
c
d
subplot(2,1,1),plot(b,c)
subplot(2,1,2),plot(b,d)
%我基本的意思是这样的,数组a中的数对3取余数,余数为0的放到数组b中,余数为1的放到数组c中,余数为2的放到d中,
%本人没有学过matlab ,因为毕业设计要用,但也不太难,就差这个了,麻烦各位好心人了!!!!!!
clc%clear command window
clear%clear variables
clf%clear figures
close all%close all figures
format compact%set compact format for command display
a=[0 1 2 3 4 5 12 13 14 15 17 23 5 8 4 3];
looptimes = length(a)%figure times to loop
j = 1;k = 1;l = 1;
for i = 1:looptimes
switch mod(a(i),3)
case 1
b(j) = a(i);
j = j + 1;
case 2
c(k) = a(i);
k = k + 1;
otherwise
d(l) = a(i);
l = l + 1;
end
end
b
c
d
subplot(3,1,1),plot(b,'^');
ylabel('b');
subplot(3,1,2),plot(c,'*');
ylabel('c');
subplot(3,1,3),plot(d,'x');
ylabel('d');
详情回复
发表于 2010-6-5 09:45
%我基本的意思是这样的,数组a中的数对3取余数,余数为0的放到数组b中,余数为1的放到数组c中,余数为2的放到d中,
%本人没有学过matlab ,因为毕业设计要用,但也不太难,就差这个了,麻烦各位好心人了!!!!!!
clc%clear command window
clear%clear variables
clf%clear figures
close all%close all figures
format compact%set compact format for command display
a=[0 1 2 3 4 5 12 13 14 15 17 23 5 8 4 3];
looptimes = length(a)%figure times to loop
j = 1;k = 1;l = 1;
for i = 1:looptimes
switch mod(a(i),3)
case 1
b(j) = a(i);
j = j + 1;
case 2
c(k) = a(i);
k = k + 1;
otherwise
d(l) = a(i);
l = l + 1;
end
end
b
c
d
subplot(3,1,1),plot(b,'^');
ylabel('b');
subplot(3,1,2),plot(c,'*');
ylabel('c');
subplot(3,1,3),plot(d,'x');
ylabel('d');