# ワークスペースにある​複数個のベクトルをf​or文で1つずつ繰り​返し処理する方法。

6 views (last 30 days)
Yuki Donen on 21 Jan 2022
Commented: Yuki Donen on 21 Jan 2022
Combined_Ch1.mat というファイルに 1*2600 の double 型 ベクトル配列が格納されています。

で読み取ると、
c001_Unnamed, c002_Column__2, c003_Unnamed, c004_Column__2, c005_Unnamed, c006_Column__2, c007_Unnamed, c008_Column__2, c009_Unnamed, c010_Column__2, c011_Unnamed, c012_Column__2, c013_Unnamed, c014_Column__2, c015_Unnamed, c016_Column__2, c017_Unnamed, c018_Column__2, c019_Unnamed, c020_Column__2, c021_Unnamed, c022_Column__2, c023_Unnamed, c024_Column__2, c025_Unnamed, c026_Column__2
のように複数のベクトル配列がワークスペースに表示されます。ここから、『_Columm__2』と末尾につくデータのみを取り出し、for文で繰り返し処理をしたいです。
ご回答よろしくお願いいたします。

Hernia Baby on 21 Jan 2022

まずはワークスペースを作成します
leg = ["c001_Unnamed";
"c002_Column__2"
"c003_Unnamed"
"c004_Column__2"
"c005_Unnamed"
"c006_Column__2"
"c007_Unnamed"
"c008_Column__2"
"c009_Unnamed"
"c010_Column__2"
"c011_Unnamed"
"c012_Column__2"
"c013_Unnamed"
"c014_Column__2"
"c015_Unnamed"
"c016_Column__2"
"c017_Unnamed"
"c018_Column__2"
"c019_Unnamed"
"c020_Column__2"
"c021_Unnamed"
"c022_Column__2"
"c023_Unnamed"
"c024_Column__2"
"c025_Unnamed"
"c026_Column__2"];
for i = 1:length(leg)
assignin("base",leg(i),i);
end
who
Your variables are: c001_Unnamed c004_Column__2 c007_Unnamed c010_Column__2 c013_Unnamed c016_Column__2 c019_Unnamed c022_Column__2 c025_Unnamed leg c002_Column__2 c005_Unnamed c008_Column__2 c011_Unnamed c014_Column__2 c017_Unnamed c020_Column__2 c023_Unnamed c026_Column__2 c003_Unnamed c006_Column__2 c009_Unnamed c012_Column__2 c015_Unnamed c018_Column__2 c021_Unnamed c024_Column__2 i
__2で終わるもの以外を消します
clearvars -except -regexp __2\$
who
Your variables are: c002_Column__2 c004_Column__2 c006_Column__2 c008_Column__2 c010_Column__2 c012_Column__2 c014_Column__2 c016_Column__2 c018_Column__2 c020_Column__2 c022_Column__2 c024_Column__2 c026_Column__2
Yuki Donen on 21 Jan 2022

R2021a

### Community Treasure Hunt

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

Start Hunting!