How do i plot sections of a wave fuction that doesn't happen at integers?

1 回表示 (過去 30 日間)
Charles
Charles 2014 年 4 月 22 日
回答済み: Image Analyst 2014 年 4 月 23 日
I am not using this command correctly
inital=x(0:.2222) (output) Warning: Integer operands are required for colon operator when used as index
My graphy is ploted correcdtly and my x axis goes negative to positive purposly. how do I define the reagions using decimals?
If i use Inital=x(1:2)
All integers thus no problem. But i need decimals.
Thankyou

回答 (1 件)

Image Analyst
Image Analyst 2014 年 4 月 23 日
Two problems. Actually 3. First, there is no zeroth element of a matrix. Elements are indexed 1,2,3,4,..., in other words integers starting at 1 (or logical values).
Second: there is no 0.2222 element of a vector. Same reason - indices must be indexes starting at 1, not fractional numbers.
Third problem: even if those were allowed 0 : 0.2222 is a null vector. Why? Well since you have no increment (middle number), the increment is 1 so it would be 0,1,2,3,4,5, etc. But after you add 1 to zero you get 1, which is already past your stopping value of 0.2222, so it can't do anything and that makes it null.
x may well be positive and negative, for example
x = linspace(-5, 9, 400); % 400 elements going from -5 to +9
but you need to figure out where x is 0 and where it's 0.2222. find those two elements like this
index1 = find(x >= 0, 1, 'first');
index2 = find(x > 0.2222, 1, 'first');
plot(x(index1:index2), y(index1, index2));

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by