joining a character variable and a numerical variable to call a filename within a loop
3 ビュー (過去 30 日間)
古いコメントを表示
how do i join the variable n to the variable filename to get the name of a real file that i want to call in a loop?
example
real files called: file 1, file 2 etc..
filename='file';
n=1:5;
for
some action filename + n;
end
many thanks
James
0 件のコメント
採用された回答
Robert Cumming
2011 年 2 月 24 日
there are lots of ways to do this, see num2str or using low level sprintf, a few examples:
fname = [ filename num2str(n) ];
fname = strcat ( filename, num2str(n) );
fname = sprintf ( '%s %i', filename, n );
I always use the last example
1 件のコメント
m naveed
2016 年 6 月 20 日
hi @Robert Cumming...i am using a nested for loop to place simulink blocks to form a 4 X 4 mesh of same element in combination with add_block and add_line function. how should i use num2str to name my elemens in the row differently than the elements in columns. e.g. for row elements, the blocks should bear the names B11 B12 B13 B14 and the next three rows should follow as...B21 B22 B23 B24 and so on until the 4x4th element to be B44
その他の回答 (2 件)
Jan
2011 年 2 月 24 日
See also the FAQ:
It is alway a good idea to look for an answer there before asking here.
2 件のコメント
Jan
2011 年 2 月 24 日
Take all the terms you have searched for and set them as tags to your question here, such that others will find it fast. You are not allone with this problem - otherwise it would not be in the FAQ...
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!