Problem with getting results for plotting (X,Y)

조회 수: 2 (최근 30일)
Armin Majidian
Armin Majidian 2021년 3월 27일
댓글: DGM 2021년 3월 27일
  • Question is:
  • X axis (t) = from 0 to 30;
  • Y axis (A) = if command; if t>=10 and if not,
Error:
Subscript indices must either be real positive integers or logicals.
Error in SpecifyLineStyleColorAndMarkerExample (line 9)
A(t) = rav * t;
A=ones(1,30);
rav = 0.5;
rln = 0.1;
for t = linspace (0,30,31);
if t<=10
A(t) = rav * t;
else
A(t)= rav*10 + rln * (t-10);
end
end

채택된 답변

DGM
DGM 2021년 3월 27일
The index t increments through the integers 0 to 30. While it's true that t is always an integer, it is not a positive integer. For the first pass through the loop, t=0. A has no zeroth element. Matlab uses a 1-based indexing convention, so perhaps:
for t=1:30
would work (provided all the other math works out).
  댓글 수: 4
Armin Majidian
Armin Majidian 2021년 3월 27일
That was really helpful. Thank you for your guidance,
And now how can I connect the (0,0) to the rest of the plot?
DGM
DGM 2021년 3월 27일
Oh, my bad. In this context, since t is not an index, you can use:
t=0:30;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by