Why does this appear as empty?
    2 views (last 30 days)
  
       Show older comments
    
I want to create a from 200 to -300 with the direction going down by 2. I also want to skip the numbers from 197 to -298 with some dots. So it would look something like this:
I =
200
198
.
.
.
.
-298
-300
I understand I first have to start with I:(200:-300)' But it always come up as 0×1 empty double column vector
I also can't remember how the numbers can be counted by 2 AND skip from 198 to -298. Any help would be appreciated
2 Comments
  James Tursa
      
      
 on 25 Apr 2017
				Do you mean you are trying to display the vector this way? Even though it contains all of the intermediate numbers? Or what?
Answers (2)
  Image Analyst
      
      
 on 25 Apr 2017
        You say "I want to create a" but then you later create and use I. You say "skip the numbers from 197 to -298" but then your expected results actually include -298. Anyway, ignoring those discrepancies, I came up with this:
a = (200 : -2 : -300)';  % Or use I instead of a.
for k = 1 : length(a)
  if a(k) <= 197 && a(k) > -298 % or >= -298
    fprintf('.\n');
  else
    fprintf('%d\n', a(k));
  end
end
0 Comments
  Walter Roberson
      
      
 on 25 Apr 2017
        The basic issue is that when you have A:B and B < A, then the result will always be empty. The default increment is always 1. If you want to decrement, then you need to specify a negative increment, such as 200:-2:-300 .
The alternative is to use
   fliplr(-300:2:200)
0 Comments
See Also
Categories
				Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


