我想创建一个动画来演示基于Sum-Product Algorithm
的LDPC编码到目前为止,我已经创建了一个图表,显示符号节点(左)和奇偶校验节点(右)alt text http://img29.imageshack.us/img29/9780/ldpc.jpg之间的连接,并希望设置从符号到奇偶校验节点并返回的点的动画。
通过执行以下方法绘制图:
function drawVertices(H)
hold on;
nodesCount = size(H);
parityNodesCount = nodesCount(1);
symbolNodesCount = nodesCount(2);
symbolPoints = zeros(symbolNodesCount, 2);
symbolPoints(:, 1) = 0;
for i = 0 : symbolNodesCount - 1
ji = symbolNodesCount - i;
scatter(0, ji)
symbolPoints(i + 1, 2) = ji;
end;
parityPoints = zeros(parityNodesCount, 2);
parityPoints(:, 1) = 10;
for i = 0 : parityNodesCount - 1
ji = parityNodesCount - i;
y0 = symbolNodesCount/2 - parityNodesCount/2;
scatter(10, y0 + ji)
parityPoints(i + 1, 2) = y0 + ji;
end;
axis([-1 11 -1 symbolNodesCount + 2]);
axis off
%connect vertices
d = size(H);
for i = 1 : d(1)
for j = 1 : d(2)
if(H(i, j) == 1)
plot([parityPoints(i, 1) symbolPoints(j, 1)], [parityPoints(i, 2) symbolPoints(j, 2)]);
end;
end;
end;
所以我想在这里做的是添加另一个方法,它将起点(x和y)和终点作为参数,并从开始到结束并沿着显示的行返回动画一个行进的圆(点)。 / p>
如果有人能够展示解决方案或建议任何有关matlab仿真的有用教程,我将不胜感激。
谢谢!
答案 0 :(得分:2)
我相信最好的学习方式就是举例。所以我建议你看一下MATLAB附带的演示lorenz
:
edit lorenz
对于其他酷动画,请查看Cleve Moler的书中的orbits.m
和swinger.m
演示:Experiments with MATLAB
我在这里展示了一个沿着圆形路径移动的点的简单动画。保留的想法归结为使用EraseMode
设置为xor
,并为每次迭代更新点的XData
和YData
:
%# coordinates
t = (0:.01:2*pi)'; %# 'fix SO syntax highlight
D = [cos(t) -sin(t)];
%# setup a figure and axis
hFig = figure('Backingstore','off', 'DoubleBuffer','on');
hAx = axes('Parent',hFig, 'XLim',[-1 1], 'YLim',[-1 1], ...
'Drawmode','fast', 'NextPlot','add');
axis(hAx, 'off','square')
%# draw circular path
line(D(:,1), D(:,2), 'Color',[.3 .3 .3], 'LineWidth',1);
%# initialize point
h = line('XData',D(1,1), 'YData',D(1,2), 'EraseMode','xor', ...
'Color','r', 'marker','.', 'MarkerSize',50);
%# init text
hTxt = text(0, 0, num2str(t(1)), 'FontSize',12, 'EraseMode','xor');
i=0;
while true
i = rem(i+1,numel(t)) + 1; %# circular increment
set(h,'XData',D(i,1), 'YData',D(i,2)) %# update X/Y data
set(hTxt,'String',num2str(t(i))) %# update angle text
drawnow %# force refresh
if ~ishandle(h), return; end %# in case you close the figure
end
有关所用参数的详细说明(EraseMode
,Backingstore
,DoubleBuffer
,..),请参阅此animation guide
答案 1 :(得分:0)
t = 0:.01:2*pi;
x = cos(2*t).*(cos(t).^2);
y = sin(2*t).*(sin(t).^2);
comet(x,y);