MATLAB Answers

Using dir to extract the names of plexon files for upload

1 ビュー (過去 30 日間)
Caitli Newman
Caitli Newman 2019 年 12 月 8 日
Edited: dpb 2019 年 12 月 9 日
Hey I am trying to write a script that will scroll through all my folders and save the names of the plexon files I want. However matlab doesn't recognize the plexon file and thus keeps saving as an empty structure array and I don't know how to fix it.
D = dir;
D = D(~ismember({D.name}, {'.', '..'}));
for k = 1:numel(D)
currD=D(k).name
cd(currD)
dinfo=dir('day1')
end
dinfo =
0×1 empty struct array with fields:
name
folder
date
bytes
isdir
datenum

  3 件のコメント

dpb
dpb 2019 年 12 月 9 日
Matlab doesn't care what a file is named so whatever issue you have isn't that...
What is the extension of a "plexon" file, whatever that is???
Caitli Newman
Caitli Newman 2019 年 12 月 9 日
I believe .plx is the extension but if I try and do something like dir .plx it returns no files. I haven't worked with plexon files before so it has been a bit of a learning curve.
Stephen Cobeldick
Stephen Cobeldick 2019 年 12 月 9 日
Using cd like that is unlikely to work correctly.
Use absolute/relative filepaths instead, generating them using fullfile.
Is 'day1' supposed to be the name of a subfolder or a file?
Where do you specify the file extensions that you want to match?

サインイン to comment.

件の回答 (2)

Walter Roberson
Walter Roberson 2019 年 12 月 9 日
cd(currD)
dinfo=dir('day1')
Don't do that. Instead
dinfo = dir(fullfile, currD, 'day1');
dinfo(ismember({dinfo.name}, {'.', '..'})) = [];
filenames = fullfile({dinfo.folder}, {dinfo.name});

  0 件のコメント

サインイン to comment.


dpb
dpb 2019 年 12 月 9 日
編集済み: dpb 2019 年 12 月 9 日
targetDir='WhteverisDirNeeded';
d=dir(fullfile(targetDir, '*.plx')); % return all files of desired extension
for i=1:numel(d)
fname=fullfile(d(i).folder},d(i).name); % build qualified filename
...
Using the specific file extension will return only those files wanted. As others say, use a path to the desired directory instead of trying to cd all over the place. You don't provide enough info to know whether your location is relative to working directory or not so the minimum you can get away with isn't possible to say for the search directory. dir() returns a fully-qualified directory regardless of whether the search is absolute or relative.
You don't have to worry about the . or .. entries with this way with the one caveat you've not named a directory with a .plx extension. If you have, you deserve the grief... :)

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

タグ


Translated by