Plotting only one data point

조회 수: 7 (최근 30일)
Aleily Partida
Aleily Partida 2021년 1월 29일
답변: KSSV 2021년 1월 29일
Hello im trying to do a plot but its only plotting one data point.
The code is:
Xei_1 = Xei;
Er = abs((Xei - Xei_1)/Xei_1)*100;% calculating Relative Error
plot(i,Er,'-o'); % plotting iterations and relative % errors
xlim([1,imax]);
ylim([0,100]);
xlabel('Iteration');
ylabel('Relative % Error')
grid on

답변 (1개)

KSSV
KSSV 2021년 1월 29일
It looks like you are running a loop. Follow like shown below:
N = 100; % loop count
Er = zeros(1,N) ;
for i = 1:N
Xei_1 = Xe(i);
Er(i) = abs((Xei - Xei_1)/Xei_1)*100;% calculating Relative Error
end
plot(1:N,Er)
Also you can vectorise the lines depending on what your code is.

카테고리

Help CenterFile Exchange에서 Frequency-Domain Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by