MATLAB

2011-04-16 14 views
5

के भीतर वक्र के साथ चलने वाले अंक मैंने वक्र के साथ चलने वाले बिंदु को दिखाने के लिए मुझे दिए गए कोड का एक टुकड़ा संपादित करने में कामयाब रहा है।MATLAB

मैं इस वक्र के साथ आगे बढ़ने वाले दो स्वतंत्र बिंदु बनाने के लिए या एक ग्राफ के साथ आगे बढ़ने वाला एक दूसरा बिंदु बनाने के लिए इसे संपादित करने का एक तरीका खोजने का प्रयास कर रहा हूं। मुख्य बिंदु यह है कि अंक एक-दूसरे से स्वतंत्र होने की आवश्यकता है ताकि उन्हें एल्गोरिदम लागू किया जा सके।

मैं वर्तमान में निम्नलिखित कोड है जो एक बिंदु की अवस्था के साथ आगे बढ़ देता है:

%# control animation speed 
DELAY = 0.01; 
numPoints = 600; 

%# create data 
x = linspace(0,1,numPoints); 
f = 5; 
C = 1-exp(-f); 
y = C*(1-(exp(-f*x))); 

%# plot graph 
figure('DoubleBuffer','on')     %# no flickering 
plot(x,y, 'LineWidth',2), grid on 
xlabel('x'), ylabel('y'), title('') 

%# create moving point + coords text 
hLine = line('XData',x(1), 'YData',y(1), 'Color','r', ... 
     'Marker','o', 'MarkerSize',6, 'LineWidth',2); 
hTxt = text(x(1), y(1), sprintf('(%.3f,%.3f)',x(1),y(1)), ... 
    'Color',[0.2 0.2 0.2], 'FontSize',8, ... 
    'HorizontalAlignment','left', 'VerticalAlignment','top'); 



%# infinite loop 
i = 1;          %# index 
while true   
    %# update point & text 
    set(hLine, 'XData',x(i), 'YData',y(i))  
    set(hTxt, 'Position',[x(i) y(i)], ... 
     'String',sprintf('(%.3f,%.3f)',[x(i) y(i)]))   
    drawnow         %# force refresh 
    %#pause(DELAY)       %# slow down animation 

    i = rem(i+1,numPoints)+1;    %# circular increment 
    if ~ishandle(hLine), break; end   %# in case you close the figure 
end 

उत्तर

2

यहाँ कैसे आप एक और मुद्दा यह है कि अंत पहला बिंदु के स्वतंत्र से फिसलने शुरू होता है जोड़ सकते हैं।

अपने कोड में, लाइन %#Infinite loop से पहले, जोड़ने निम्नलिखित:

set(hLine2, 'XData',x(end-i), 'YData',y(end-i))  
    set(hTxt2, 'Position',[x(end-i) y(end-i)], ... 
     'String',sprintf('(%.3f,%.3f)',[x(end-i) y(end-i)])) 

तो अपने दूसरी बात स्लाइड:

hLine2 = line('XData',x(end), 'YData',y(end), 'Color','g', ... 
     'Marker','o', 'MarkerSize',6, 'LineWidth',2); 
hTxt2 = text(x(end), y(end), sprintf('(%.3f,%.3f)',x(1),y(1)), ... 
    'Color',[0.2 0.2 0.2], 'FontSize',8, ... 
    'HorizontalAlignment','left', 'VerticalAlignment','top'); 

और पाश अंदर, drawnow आदेश से पहले, निम्नलिखित जोड़ें नीचे और पहली स्लाइड ऊपर। hLine2 और hTxt2 enter image description here

की परिभाषा में आप बिंदु के लिए प्रक्षेपवक्र को परिभाषित कर सकते हैं