フィルターのクリア

How to find columns by name in a cell aray

12 ビュー (過去 30 日間)
012786534
012786534 2017 年 4 月 11 日
コメント済み: 012786534 2017 年 4 月 11 日
Hello all,
Let's say I have a large cell array with similar variable names in the first row (A_F1 , B_F2 , A_F2 , G_F5 ...) followed by data.
I want to create a smaller cell array with just the columns where the variable name starts with A.
How would I do that?
Thank you

採用された回答

Stephen23
Stephen23 2017 年 4 月 11 日
編集済み: Stephen23 2017 年 4 月 11 日
This is easy with strncmp:
>> inp = {'A_F1','B_F2','A_F2','G_F5';1,2,3,4}; % demo matrix.
>> idx = strncmp(inp(1,:),'A',1); % indices of strings starting with A.
>> otp = inp(:,idx); % select those columns from inp.
As an alternative you could use the table class, and this task may well be easier.
  1 件のコメント
012786534
012786534 2017 年 4 月 11 日
Great job!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by