フィルターのクリア

How to produce and save in a variable a list of a folder's files?

28 ビュー (過去 30 日間)
Beatriz Sanchez
Beatriz Sanchez 2018 年 12 月 4 日
コメント済み: Beatriz Sanchez 2018 年 12 月 5 日
Hello, so I'm trying to get a list of the names of every file .mat on a folder (all of the files on this folder) and save this result in a variable so I can use it later on a for loop. I've tried this:
cd 'C:\Users\David\Documents\Tesis\matlab\resultados\saves' % folder that I want the files from
folder= dir ('*.mat')
bea= zeros(16,1) % 16 is the number of elements in the folder
contador=0
for i=1:16
contador= contador+1
name=folder(i).name
bea(contador,:)= name
end
I don't even know if this is possible this way, I'm just trying a lot of things. I will definitely appreciate it if somebody can help me

採用された回答

Fangjun Jiang
Fangjun Jiang 2018 年 12 月 4 日
a=dir('*.mat');
b={a.name}

その他の回答 (1 件)

Stephen23
Stephen23 2018 年 12 月 5 日
編集済み: Stephen23 2018 年 12 月 5 日
Do NOT use cd unless you want to force yourself into writing slow hard-to-debug code. It is better to use a full path name:
D = 'C:\Users\David\Documents\Tesis\matlab\resultados\saves';
S = dir(fullfile(D,'*.mat'));
C = {S.name}
  1 件のコメント
Beatriz Sanchez
Beatriz Sanchez 2018 年 12 月 5 日
alright, I'll keep that in mind, thank you

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

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by