문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top