How to create a number of output tables at each iteration ?

5 visualizaciones (últimos 30 días)
MD Rabiul Islam
MD Rabiul Islam el 19 de Jun. de 2022
Comentada: Stephen23 el 3 de Oct. de 2023
Dear altruists,
Seek suggestion.
I have a "TW" table where TW(:,1) = start row number and TW(:,2) = end row number is mentioned.
I have a "D" table where raw data is present. D is a table which has 1 to 15,000 rows and 10 cols. For each iteration, I have to pick values from "D" table ( copy) with specified rows & cols. and drop it to an output table (paste them) and the requirement is that the output data table name will be change from Z1.........Z20.
I want to output various table for every iteration.
For example,
i =1 will create output table Z1 = D(rows, cols)
i = 2 will create output table Z2 = D(rows, cols)
.
.
i =20 will create output table Z20 = D(rows, cols)
**************************************************************************
for i = 1 : 20
cols = [1 2 5 7];
rows = TW(i,1):(TW(i,2));
Z = D(rows,cols);
end
  5 comentarios
MD Rabiul Islam
MD Rabiul Islam el 20 de Jun. de 2022
I also find this comment during googling...Can I request any alternative easiest solution to do this ?
Stephen23
Stephen23 el 20 de Jun. de 2022
"Can I request any alternative easiest solution to do this ?"
Indexing.

Iniciar sesión para comentar.

Respuestas (1)

Abhishek Chakram
Abhishek Chakram el 3 de Oct. de 2023
Hi MD Rabiul Islam.
It is my understanding that you are facing difficulty to extract multiple rows and columns from a bigger table and store it in multiple named variables. As a workaround, you can create a cell array to achieve a similar result. Here is an example for the same:
Z={};
for i = 1 : 20
cols = [1 2 5 7];
rows = TW(i,1):(TW(i,2));
Z{i} = D(rows,cols);
end
In this example, "Z" is a cell array. You can access each sub table using indexing as shown below:
Z{1}
Z{2}
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by