I dont understand this code with dir and sprintf

3 ビュー (過去 30 日間)
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan 2017 年 5 月 2 日
コメント済み: Stephen23 2017 年 5 月 3 日
Hey
I want to convert mat-files and my supervisor gave me this matlab-code to do it with. I am not sure I understand it fully, can you help?
  1 件のコメント
Stephen23
Stephen23 2017 年 5 月 3 日
What is the point of this line?:
sprintf([''], ii, segment)

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 2 日
編集済み: Stephen23 2017 年 5 月 3 日
1) Do not use "path" as a variable name, as doing that interferes with using the MATLAB path.
2) Instead of
files = dir(sprintf('%s/%s/*.mat', path, hemi(ee))
use
files = dir( fullfile(path, hemi(ee), '*.mat') )
and later when the file name is being constructed, use fullfile() then as well.
3)
sprintf([''], ii, segment)
is going to result in the empty vector because of the empty format '' . The purpose of that code is confusing.
4) it really looks to me as if the code for filesB and B is wrong. Different directories are being referred to in the different lines.
  2 件のコメント
Zahra  S. Abd Al-Hassan
Zahra S. Abd Al-Hassan 2017 年 5 月 2 日
編集済み: Zahra S. Abd Al-Hassan 2017 年 5 月 2 日
What does ‰s means? And what does segment='name' represent? is it and cell array or a mat.file a should save before matlab can understand it?
Walter Roberson
Walter Roberson 2017 年 5 月 3 日
%s means that a string should be read from the next available parameter and transfered to the output as characters.
segment = 'name'
means that at some point in the development of the program, there was a directory that was named either literally 'name' or else name with a numeric prefix, such as '1name', '2name' and so on. But with the [''] format of the sprintf() the content of the segment variable is being ignored.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by