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

1 view (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 23 Apr 2014
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));

Community Treasure Hunt

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

Start Hunting!