Remove elements from a structure array, whose values also exist in a different structure array

6 ビュー (過去 30 日間)
Hi all. Question from novice: I have 2 structure arrays and I would like to remove all elements from one array, which have a name, that also exist as the same name in the other structure array. My code so far:
file_plots = dir('*.jpg');
file_raw = dir('*.csv');
% remove file extensions
for i = 1:1:length(file_raw)
file_total_raw(i).name = file_raw(i).name(1:length(file_raw(i).name)-4);
end;
for i = 1:1:length(file_plots)
file_existing_plots(i).name=file_plots(i).name(1:length(file_plots(i).name)-4);
end;
Some more info:
file_plots =
6x1 struct array with fields:
name
date
bytes
isdir
datenum
file_raw =
11x1 struct array with fields:
name
date
bytes
isdir
datenum
Specifically: I want to filter out all elements of file_raw, which share a name with file_plots and the results should also be a new structure array called file_raw_filtered. Hope this describes my problem and many many thanks! Max

採用された回答

Jan
Jan 2016 年 10 月 28 日
name_raw = {file_raw.name};
name_plots = {file_plots.name};
keep = ~ismember(name_raw, name_plots);
file_raw_filtered = file_raw(keep);
  2 件のコメント
Max Leh
Max Leh 2016 年 10 月 28 日
plain and simple. awesome, thanks!
Jan
Jan 2016 年 10 月 28 日
You are welcome. Matlab is a nice and compact programming language. If I try this in C, it would look like somebody rolled an angry armadillo over the keyboard.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by