フィルターのクリア

String select specific positions

2 ビュー (過去 30 日間)
Patrick Brown
Patrick Brown 2017 年 1 月 31 日
回答済み: Jan 2017 年 1 月 31 日
Hi, I have a cell (Numbers) with different values and I have a vector with the positions I want to take (NumbersSelect) When I write a=Numbers{NumbersSelect} I only get in the variable a the first number I want to select I have developed a for loop in order to take all the numbers there is a way to do it without a for loop ??? thanks

回答 (2 件)

Adam
Adam 2017 年 1 月 31 日
a = [ Numbers{NumbersSelect} ];
  2 件のコメント
Patrick Brown
Patrick Brown 2017 年 1 月 31 日
thanks :) but in the case of a string all the values will be together without spaces
Star Strider
Star Strider 2017 年 1 月 31 日
If you have spaces in your original string, first use a regexp call to create a cell array of strings from the individual words:
str = 'I have a string';
strc = regexp(str, '\ ', 'split')
strc =
1×4 cell array
'I' 'have' 'a' 'string'
That should work with Adam’s code. If you have something else that wouldn’t work with this approach, you need to share it with us.

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


Jan
Jan 2017 年 1 月 31 日
Perhaps you mean:
a = Numbers(NumbersSelect)
or
a = sprintf('%s ', Numbers{NumbersSelect})
If this does not help, please post some real example data and the wanted output in valid Matlab syntax.

カテゴリ

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