MATLAB Answers

How can I select items in a double list?

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

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Jun 2019
reshape(T_C,3,[])
Now the groups of 3 appear as columns.

  7 Comments

Show 4 older comments
Jonathan Bijman
Jonathan Bijman on 14 Jun 2019
I wrote:
BC = num2cell(reshape(T_C,3,[]), 1);
[T_A8, T_C5, T_E1] = deal(BC{:});
Appears:
Error using deal (line 37)
The number of outputs should match the number of inputs.
Error in T_Ambos (line 26)
[T_A8, T_C5, T_E1] = deal(BC{:});
Walter Roberson
Walter Roberson on 14 Jun 2019
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 on 14 Jun 2019
Thank U again @Walter Roberson for your wisdom and help.
Very thankful =)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Jun 2019
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 Comments

Show 3 older comments
Jonathan Bijman
Jonathan Bijman on 14 Jun 2019
I'm sorry, my english sometimes is bad =(.
I hope you get it with this image.
I want to associate all A8 (corresponds to 1, 4, 7, etc...), C5 (corresponds to 2, 5, 8, etc...) and E1 (3, 6, 9, etc...)
Thanks for youimage.pngr help
Image Analyst
Image Analyst on 14 Jun 2019
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 on 14 Jun 2019
Yes, but I appreciate your help @Image Analyst anyway.
Thank U =)

Sign in to comment.