Create a new array over each iteration
Mostra commenti meno recenti
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 Commenti
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
il 14 Giu 2021
Rik
il 14 Giu 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
il 14 Giu 2021
Rik
il 14 Giu 2021
Why do you want numbered variables? They force you to write difficult and buggy code.
Riccardo Tronconi
il 14 Giu 2021
Stephen23
il 15 Giu 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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!