Easier way to rename files?

2 ビュー (過去 30 日間)
NS
NS 2012 年 6 月 9 日
Hi all,
I run a code where in the end I rename a bunch of output files based on the date that the data was procured. So if my code finds xData, yData, zData and tData and I want to rename it as the following
xData060912=xData;
yData060912=yData;
zData060912=zData;
tData060912=tData;
clear xData yData zData tData
Is there an easier way to do this? rather than renaming the arrays manually everytime. Can I just input 060912 in one line and use a function that does it automatically?
Thanks, NS

採用された回答

per isakson
per isakson 2012 年 6 月 9 日
See "How can I create variables A1, A2,...,A10 in a loop?" in the Matlab FAQ.
Something like this is often recommended
str_name = sprintf( 'xData%06u', num )';
Data.(str_name) = xData;
etc.
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 6 月 9 日
NS: That approach is not recommended as it usually leads to problems. The approaches in the FAQ that Per referenced are more appropriate.
per isakson
per isakson 2012 年 6 月 10 日
@NS Did you read the entry in the FAQ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by