필터 지우기
필터 지우기

Plot Circle In For Loop

조회 수: 4 (최근 30일)
Kelly McGuire
Kelly McGuire 2018년 4월 27일
댓글: Kelly McGuire 2018년 4월 30일
I have this code that is set up to animate a circle plot based on the circle's diameter. I am struggling with how to plot the circle based on the diameter in the for loop. I have one column vector of 1,667 columns. In each of those columns is the diameter (i.e. 1,667 diameters from data). I want to animate the circle changing based on those diameters. So, I need the plot in the for loop to go through, iterate through the columns, and update the plot, and but show that as an animation. I've attached my code. Please help with the plot portion of the code, thanks!
  댓글 수: 5
Kelly McGuire
Kelly McGuire 2018년 4월 27일
Ok, I tried the code in that link for a circle, and that code works. Now, the trouble I'm having is with my matrix dimensions. I'm not too good with the iteration coding yet, but here is my updated code. I'm getting the error: Matrix dimensions must agree Error in circle lin 12 Error in AnimatedCirclePlot line 11. I've attached both .m files.
Kelly McGuire
Kelly McGuire 2018년 4월 27일
Looks like I forgot all of the (i,j) in the xunit and yunit functions. That fixed the matrix dimensions problem. Now, a new error, one that really don't know how to solve. Index in position 2 exceeds array bounds (must not exceed 1). I know this is talking about the cos(th(i,j)) and sin(th(i,j)) in circle.m, but I'm not sure what the problem is really saying...

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 27일
편집: Ameer Hamza 2018년 4월 27일
@Kelly, As I answered on your previous question, that you need to fill the plot for circle yourself. If you are still not able to make that work then here is the complete code.
B = 10:10:1000; % test B vector. You will use your own B
animationWriter = VideoWriter('HSPtoHSPCircle');
open(animationWriter);
l = line();
l.XData = [];
l.YData = [];
xlim([-max(B) max(B)]);
ylim([-max(B) max(B)]);
theta = 0:pi/50:2*pi;
for i = 1:length(B)
% create data for circle plot or any other
% processing you want to do
xData = B(i)*cos(theta);
yData = B(i)*sin(theta);
l.XData = xData;
l.YData = yData;
frame = getframe(gcf);
writeVideo(animationWriter, frame);
end
close(animationWriter);
I created this animation using given code.
  댓글 수: 6
Ameer Hamza
Ameer Hamza 2018년 4월 30일
As far as changing the labels on X-axis is concerned, the following code can do it,
ax.XLim = [1 4]
ax.XTick = 1:4
ax.XTickLabel = {'residue 1', 'residue 2', 'residue 3', 'residue 4'}
As far as making an animation with moving line is concerned. It is quite different to this question. Here is an outline of how can you do it.
  • Make a linear interpolation of edges between two rows of your data matrix.
  • Instead of just drawing the rows of your matrix, also plot all the interpolated points. This way, the animation will look smooth.
If you still face a problem, you might want to start a new question, because the new problem is quite out of the scope for this question.
Kelly McGuire
Kelly McGuire 2018년 4월 30일
Sounds good, I'll post a new question. Was hoping the same code you gave me for the circle plot could do this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by