How can I select items in a double list?

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

 Respuesta aceptada

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

7 comentarios

Jonathan Bijman
Jonathan Bijman el 14 de Jun. de 2019
Thanks, but the double list corresponds to averages of measuments of 3 groups who are the same along the time, and I need to show them in such a way that appears from 1:3, 4:6, 7:9 (similar to a for loop), because I have to graph them next.
So my idea is:
T_A8 = (1:3) in all the double list
T_C5 = (4:6) in all the double list
T_E1 = (7:9) in all the double list
So that I plot them as 3 graphs along the time.
I hope you get it.
Thanks again
Walter Roberson
Walter Roberson el 14 de Jun. de 2019
I do not understand what you mean about "in all the double list" ? You indicated you have one variable that is 105 x 1, not several different variables.
Jonathan Bijman
Jonathan Bijman el 14 de Jun. de 2019
I mean that is only one variable T_C which correspond to the average of three different samples (in triplicate each one, 9 in total). That’s why I need to associate in three groups (A8, C5 and E1)
BC = num2cell( reshape(T_C,3,[]), 1);
[T_A8, T_C5, T_E1, T_whatever] = deal(BC{:});
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 el 14 de Jun. de 2019
Editada: Walter Roberson el 14 de Jun. de 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 el 14 de Jun. de 2019
Thank U again @Walter Roberson for your wisdom and help.
Very thankful =)

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Jun. de 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 comentarios

Thanks, I apply this
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.
T_A8=[TA8] % I want to show as a matrix of 1 column
end
but shows only 1 column of 3 firsts items, how can I show as a matrix of 1 column with all the items?
When I apply this:
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.
T_A8=[TA8,1] % Now do something with TA8
end
Appers this error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in T_Ambos (line 27)
T_A8=[TA8,1] % Now do something with TA8
Image Analyst
Image Analyst el 14 de Jun. de 2019
Attach a .mat file with the paper clip icon that has your variable in it.
I guess we really don't know what you want. Do you want extractions of 3 elements at a time like you asked for, and we gave you, or do you want something else? Please show, with a numerical example of say an input vector of 12 elements, exactly what you want as the output.
Jonathan Bijman
Jonathan Bijman el 14 de Jun. de 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 el 14 de Jun. de 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 el 14 de Jun. de 2019
Yes, but I appreciate your help @Image Analyst anyway.
Thank U =)

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Jun. de 2019

Comentada:

el 14 de Jun. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by