I'm having a problem using plot function in a for loop. The plot figure is empty

1 次查看(过去 30 天)
clear
clc
disp('Welcome to calculation program')
n=input('Please enter the number of iterations=');
x=input('Please enter the value of vector x=');
for i=1:1:n
x(i+1)=x(i)-((2*x(i)*tan(x(i))-1)/(2*tan(x(i))+2*x(i)*(sec(x(i))^2)));
fprintf('The value of iteration no.%1.0f of vector x is=%2.4f\n',i,x(i+1))
plot(i,x,'*r')
if x(i)==x(i+1)
break
end
end
for i=1:1:n
if x(i)~=x(i+1)
disp('The maximum number of iterations have been reached')
y=input('To re-run press 1 and to stop press any number=');
if y==1
midexam3
elseif y~=1
break
end
end
end

采纳的回答

Image Analyst
Image Analyst 2022-12-9
Use hold on after plot
plot(i,x,'*r')
hold on

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by