How can I select items in a double list?

27 次查看(过去 30 天)
Hi everyone!
I have a variable which is (105 x 1 double) and I need to select from the first item to 3rd, from 4th item to 6th and from 7th item to 9th.
When, for instance, I apply:
TA8=T_C((1:3):1)
Only appears the first element and not the 2nd and 3rd ones.
How can I show the three elements?
Thank U

采纳的回答

Walter Roberson
Walter Roberson 2019-6-14
reshape(T_C,3,[])
Now the groups of 3 appear as columns.
  7 个评论
Walter Roberson
Walter Roberson 2019-6-14
编辑:Walter Roberson 2019-6-14
You need one output for each column.
Though I thought you were giving examples and wanted to continue for all of the groups. If you just want those specific parts then just do three assignments,
T_A8 = T_C(1:3);
T_C5 = T_C(4:6);
T_E1 = T_C(7:9);
Though seeing your response to someone else, it looks like what you want is
T_A8 = T_C(1:3:end);
T_C5 = T_C(2:3:end);
T_E1 = T_C(3:3:end);
Jonathan Bijman
Jonathan Bijman 2019-6-14
Thank U again @Walter Roberson for your wisdom and help.
Very thankful =)

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2019-6-14
Try
TA8 = T_C(1:3);
etc. Or for all of them in turn:
for k = 1 : 3 : length(T_C) % Starting at 1, 4, 7, etc....
TA8 = T_C(k:k+2); % Get this group of 3 elements.
% Now do something with TA8
end
  6 个评论
Image Analyst
Image Analyst 2019-6-14
Sounds like, from your comment to Walter, that you've got it all solved now, so there is no need for me to answer anymore.
Jonathan Bijman
Jonathan Bijman 2019-6-14
Yes, but I appreciate your help @Image Analyst anyway.
Thank U =)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by