I just need to get the numbers from this vector. The result must be a double. I need fast and clean code, as this operation is performed over and over again in my code.
2 ビュー (過去 30 日間)
古いコメントを表示
vector = {'G07'} {'G23'} {'G04'} {'G08'} {'G20'} {'G13'} {'G30'}
This code below is my code but it is slow when running too many times.
PRN = vector;
PRN = char(PRN);
PRN = PRN(:,2:end);
PRN = str2num(PRN);
0 件のコメント
回答 (2 件)
Mathieu NOE
2021 年 9 月 21 日
hello
try this alternative :
vector = [{'G07'} {'G23'} {'G04'} {'G08'} {'G20'} {'G13'} {'G30'}];
% Calling the regexp() function over the above cell array to extract number part
B = regexp(vector,'\d+(\.)?(\d+)?','match');
% Calling the str2double() function to convert the text to double-precision values
out = str2double([B{:}])
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!