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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by