Why does this appear as empty?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
James Tursa
2017 年 4 月 25 日
Do you mean you are trying to display the vector this way? Even though it contains all of the intermediate numbers? Or what?
回答 (2 件)
Image Analyst
2017 年 4 月 25 日
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 件のコメント
Walter Roberson
2017 年 4 月 25 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!