我正在尝试绘制其中有一点的图形。我想在每个10
步骤(或任何恒定速率)的图形上添加一个新点,例如,如果我有50
步骤,则应该有50
图形。从1
到的图10
将有一个点,从11
到的图20
将有两个点,从21
到的图30
将有三个点,依此类推。我在下面的代码中做到了这一点,但不幸的是,所有数字只给了我一点。
clc;
clear;
Current_Path=pwd;
cd (Current_Path)
mkdir('Photos','part1')
pridir = 'Photos\part';
R=rand(1,50);
Y=rand(1,50);
for i=1:50
figure
for jj = 1:floor((i-1)/10)+1
if jj<=1
plot (R(i),Y(i),'*r');
printto = sprintf('%s%d\\Motion%03d',pridir,1,i);
print('-djpeg90',printto)
close(gcf);
hold on
else
R(i)=R(i-((jj-1)*10));
Y(i)=Y(i-((jj-1)*10));
plot (R(i),Y(i),'*r');
printto = sprintf('%s%d\\Motion%03d',pridir,1,i);
print('-djpeg90',printto)
close(gcf);
hold on
end
end
hold off
end
您的代码有两个主要问题:
close(clf)
移到您hold off
当前所在的位置,以避免在每个绘制点之后关闭图形。pridir
呼叫的中缺少a 1
,part1
由于没有目录,导致MATLAB无法保存图形part
。为了漂亮起见,您可以进行一些其他更改。hold on
持有一个数字直到您打电话hold off
。在您的情况下,您可以hold off
完全省略,因为在循环后关闭图形。另外,请考虑将其ii
用作变量(与您一样jj
),因为i
它是虚数单位。
更新的代码
Current_Path=pwd;
cd (Current_Path)
mkdir('Photos','part1')
pridir = 'Photos\part1'; % change to 'part1'
R=rand(1,50);
Y=rand(1,50);
for ii=1:50 % change to ii
figure
hold on % move hold on here
for jj = 1:floor((ii-1)/10)+1
if jj<=1
plot (R(ii),Y(ii),'*r'); % remove close(gcf) and print calls
else
R(ii)=R(ii-((jj-1)*10));
Y(ii)=Y(ii-((jj-1)*10));
plot (R(ii),Y(ii),'*r'); % remove close and print
end
end
printto = sprintf('%s%d\\Motion%03d',pridir,1,ii);
print('-djpeg90',printto) % move print outside the inner loop
close(gcf); % finally close the figure after saving
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句