Info

この質問は閉じられています。 編集または回答するには再度開いてください。

could anyone help me to solve the issue

1 回表示 (過去 30 日間)
Prabha Kumaresan
Prabha Kumaresan 2018 年 8 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
If there are 12 numbers in a row how to select 1,3,5,7,9,11 numbers.
  2 件のコメント
Stephen23
Stephen23 2018 年 8 月 15 日
編集済み: Stephen23 2018 年 8 月 15 日
@Prabha Kumaresan: surely you can do this! You have asked over two hundred and fifty questions on this forum over the last year. Surely at some point you must have learned something about basic MATLAB indexing! Put in some effort, otherwise you will not learn anything at all.
This is very basic MATLAB, which the introductory tutorials give enough information for you to solve. So for a start, please show us what you have tried so far.
Stephen23
Stephen23 2018 年 8 月 16 日
@Prabha Kumaresan: please do not close threads that have answers.

回答 (3 件)

Tiasa Ghosh
Tiasa Ghosh 2018 年 8 月 15 日
One can check whether the index number is odd or even with
if mod(i,2)==1
% do something
end
  3 件のコメント
Stephen23
Stephen23 2018 年 8 月 15 日
編集済み: Stephen23 2018 年 8 月 15 日
@Tiasa Ghosh: from your comment (which you have since deleted):
a=1:12; % <- yes, good start.
a(1),a(3),a(5)... % no!
The introductory tutorials, which I linked to in my comment above, give enough information to solve this problem in a much simpler way. Look at the pattern of the indices... why write them separately? Hmmm... does MATLAB possibly have an easy way of generating the sequence 1,3,5,...? Hmmm... maybe I could use this sequence as an index!
Tiasa Ghosh
Tiasa Ghosh 2018 年 8 月 15 日
oh yes, I am sorry I deleted that comment. It was:
a=1:12;
a(1),a(3),a(5)...
wouldn't this require more manual work?

Tiasa Ghosh
Tiasa Ghosh 2018 年 8 月 15 日
Without any loop, this should work:
a=1:12
a(1:2:end)

Image Analyst
Image Analyst 2018 年 8 月 15 日
If you are going to select 1 number, or 3 numbers, or 5 numbers, or however many numbers you want, you can specify their indexes but you need to decide which one(s). For example, if you are going to select (extract) 3 numbers, which three are they? The first three? The last three? The numbers at indexes 4, 6, and 10? You need some kind of rule.
Or do you want every possible combination of 3 numbers?
For example, let's say you wanted the 3 numbers at indexes 2, 8, and 11, from vector v, you'd do
v3 = v([2,8,11])
  1 件のコメント
Prabha Kumaresan
Prabha Kumaresan 2018 年 8 月 16 日
編集済み: Matt J 2018 年 8 月 16 日
I am having 12 different possible combination. Out of 12 i need to select only 6 which means(1st,3rd,5th,7th,9th and 11th combination)
for example I am having the first combination as
A = 1
A = 2 12
A = 3 10 11
A = 4 7 8 9
A = 5
A = 6
could you please help me on this.

Community Treasure Hunt

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

Start Hunting!

Translated by