Frage

I'm coding a scenario in which I want unique strings in Matlab, i.e each iteration gives unique strings, however I tried a for loop iterations for unique strings in every iteration (or can say overall results are in the form of unique strings) as follows. But it gives unique strings in one iteration only, however I need on every iteration, or overall loop iterations. The bug forms as it unique strings by adding 1 but on the next iteration, it conflicts!!!

My Code (for simplicity, no output is shown):

for ii=1:10

matrix1=['Obj' num2str(ii)];
matrix2=['Obj' num2str(ii+2)];
matrix3=['Obj' num2str(ii+3)];
matrix4=['Obj' num2str(ii+4)];
matrix5=['Obj' num2str(ii+5)];

end

Any suggestions or piece of formula that makes my strings unique are welcomed.

War es hilfreich?

Lösung

You're question is unclear. Maybe that's what you're willing to do:

i = 1;
MATRIX = [];
for iter=1:5
   matrix=['Obj' num2str(iter)];
   MATRIX = [MATRIX ; matrix];
   iter = iter + 2;
end

Andere Tipps

If I undertand your question correctly, this is one possible solutuion:

for ii=1:10

    matrix1=['Obj' num2str(ii) '-1'];
    matrix2=['Obj' num2str(ii) '-2'];
    matrix3=['Obj' num2str(ii) '-3'];
    matrix4=['Obj' num2str(ii) '-4'];
    matrix5=['Obj' num2str(ii) '-5'];

end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top