How to not plot a single file in a directory?

2 ビュー (過去 30 日間)
Ted Baker
Ted Baker 2020 年 1 月 10 日
コメント済み: Ted Baker 2020 年 1 月 10 日
Hi I am wanting to compare every file in a directory with one specific file in the same directory for a closest match, say compare file a,b,c with file x. I import the data of file x first, with
targetfilename = 'x.txt';
matchT = readtable(targetfilename,'Delimiter',' ','ReadVariableNames',false,'Format','%f%f%f%f%f%f%f%f%f', 'HeaderLines', 6);
And then import each file a,b,c in turn after doing some work on each data, like:
txtfiles = dir('*.txt');
for file = txtfiles'
filename = file.name;
T = readtable(filename,'Delimiter',' ','ReadVariableNames',false,'Format','%f%f%f%f%f%f%f%f%f', 'HeaderLines', 6);
S21complex = complex(T.Var4, T.Var5);
%doing a comparison here with file x
end
So I first compare x with a, then x with b, etc... However, file x is still in the same directory, the above code will compare x with x, and find it to be the closest match. I tried using something like
if filename ~= targetfilename
after the 'for' line, but the length of the real names of x and a,b,c do not match.
Is there a convenient way to exclude a particular file from my second block of code? If it helps, my targetfilename will always start with a letter, whilst a,b,c will always start with a number. Thanks in advance.

採用された回答

Stephane Dauvillier
Stephane Dauvillier 2020 年 1 月 10 日
You can use the function setdiff to remove one value from a set of values:
f = dir;
names = setdiff({f.name},"myfileIDontWantToProceed")
  1 件のコメント
Ted Baker
Ted Baker 2020 年 1 月 10 日
Thank you Stephane, that worked perfectly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAdding custom doc についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by