How to determine non-zero values from a string array?

4 ビュー (過去 30 日間)
Mohammed
Mohammed 2016 年 11 月 10 日
コメント済み: Mohammed 2016 年 11 月 10 日
I have following string array and I am trying to find out which string has value that are not equal to zero. I used str2num but apparently I am missing something here to get it right, any tips?
a =
' 0.5%'
' 0.0%'
' 0.0%'
' 0.0%'
'16.0%'
' 0.5%'
' 0.0%'
' 2.8%'
' 0.0%'
'11.6%'
' 0.5%'
' 8.3%'
' 0.0%'
'36.7%'
'23.2%'
Result should look like above except 0.0% taken out!

採用された回答

KSSV
KSSV 2016 年 11 月 10 日
clc; clear all ;
a = { ' 0.5%'
' 0.0%'
' 0.0%'
' 0.0%'
'16.0%'
' 0.5%'
' 0.0%'
' 2.8%'
' 0.0%'
'11.6%'
' 0.5%'
' 8.3%'
' 0.0%'
'36.7%'
'23.2%'} ;
% get strings which are 0
idx = strfind(a, '0.0%');
idx0 = find(not(cellfun('isempty', idx)));
% get indices of non-zeros
iwant = setdiff(1:length(a),idx0) ;
a(iwant)
  1 件のコメント
Mohammed
Mohammed 2016 年 11 月 10 日
Appreciate your prompt answer!

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

その他の回答 (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