Reputation: 121
I wish to change the name of col_1 to col_2, col_3....col_N for each value of 'j'. Could anyone suggest on how to handle this.? The reason why I wish to do this way is that size of col_i changes for different j. Any valuable suggestions and corrections are highly appreciated.
for j=1:N
for i=1:dum+1
col_1(i,1)=x;
col_1(i,2)=y;
end
end
Upvotes: 0
Views: 107
Reputation: 1251
@KGV dynamic naming convention is not suggested in MATLAB. You have the indices already, you can call them easily. Don't try to rename/ use dynamic naming convention. You may read the below link for further information.
Upvotes: 1
Reputation: 18838
you can use eval
like the following:
for j=1:N
for i=1:dum+1
eval(strcat(strcat('col_',num2str(j)),'(i,1)=x'));
eval(strcat(strcat('col_',num2str(j)),'(i,2)=y'));
end
end
Upvotes: 2