Create a new array over each iteration
Mostrar comentarios más antiguos
Hi guys! Starting from one table (A) I would divide it in n-table according to the max value of the A(:,4). At this point every each iteration I must create another table as it follows:
function [T_num2str(i)] = par(A)
n= max(A{:,4});
for i=1:n
search = find(A{:,4}==i);
eval(['T_' num2str(i) ' = table;']);
T_num2str(i) = position(search,:);
end
end
I have two problem:
1- How to define output values if I do not know how many they would be?
2- How to solve this indexing problem ?
T_num2str(i) = position(search,:);
7 comentarios
This is an example of the XY problem. Why don't you explain what you want to do? Your use of eval alone already suggests there is probably a better solution.
My guess would be that a solution would involve a comma separated list:
c=cell(1,3);
[c{:}]=ndgrid(1:2,2:3,4);
format compact,celldisp(c)
How exactly you can use this concept for your problem, depends on what you actually want to do.
Riccardo Tronconi
el 14 de Jun. de 2021
Rik
el 14 de Jun. de 2021
It is not clear to me what you want to have as an output variable. Can you give a hard-coded example?
%for example:
data_I_want=...
[2.693613716 2.652678399;
3.577557088 3.49910799;
2.56422065 2.604867068;
3.573647731 3.550236118;
2.661032734 2.607972076;
3.541105827 3.585182487];
Riccardo Tronconi
el 14 de Jun. de 2021
Rik
el 14 de Jun. de 2021
Why do you want numbered variables? They force you to write difficult and buggy code.
Riccardo Tronconi
el 14 de Jun. de 2021
Stephen23
el 15 de Jun. de 2021
"I need it parametric so Its functioning is still valid if max(indices) is either lower or greater. "
Sure, but you did not answer Rik's question.
So far there is no obvious reason why you cannot use simpler indexing, rather than your complex and inefficient approach.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!