Create a new array over each iteration
显示 更早的评论
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 个评论
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
2021-6-14
Rik
2021-6-14
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
2021-6-14
Rik
2021-6-14
Why do you want numbered variables? They force you to write difficult and buggy code.
Riccardo Tronconi
2021-6-14
Stephen23
2021-6-15
"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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!