How to import randomly named files from a folder into different matrices

1 回表示 (過去 30 日間)
Jørgen
Jørgen 2019 年 7 月 1 日
編集済み: Jan 2019 年 7 月 1 日
Hi,
I have the same problem as stated here https://se.mathworks.com/matlabcentral/answers/1810-opening-files-with-randomly-varying-file-names, but the problem is to go further from Olegs answer. Once I have the matrix called names, how to I add the matrix content into a path directory ( for example like
Matrix = fopen('C:\Users\Oleg\Desktop\Nuova cartella\names(1)');
where names(1) should be transfered into the name of the file currently in names(1).
  1 件のコメント
Stephen23
Stephen23 2019 年 7 月 1 日
What exactly is a "path directory" and what does it mean to "...add the matrix content into a path directory" ?
The sentence "...where names(1) should be transfered into the name of the file currently in names(1)" is unclear: can you provide an example of what you are trying to achieve? Are you trying to rename files?

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

回答 (1 件)

Andy
Andy 2019 年 7 月 1 日
If I understand correctly, try
filename=strcat('c:\Users\Oleg\Desktop\Nuevo cartella\',names(1,:));
matrix=fopen(filename);
Of course, they can be combined into one line.
Hope this is what you are after.
  2 件のコメント
Jan
Jan 2019 年 7 月 1 日
編集済み: Jan 2019 年 7 月 1 日
Most likely names is not a char matrix. Then, if it is a cell string:
filename=strcat('c:\Users\Oleg\Desktop\Nuevo cartella\', names{1});
Remember, that strcat removes leading spaces smartly. Although leading spaces are a bad idea for file names, this would be safer:
filename = ['c:\Users\Oleg\Desktop\Nuevo cartella\', names{1}];
[EDITED, after Stephen's comment] And even better, because it cares for the path separators:
filename = fullfile('c:\Users\Oleg\Desktop\Nuevo cartella\', names{1});
Stephen23
Stephen23 2019 年 7 月 1 日
It is recommended to use fullfile rather than concatenating strings together.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by