Converting Cell matrix to a Numeric Matrix

3 ビュー (過去 30 日間)
Souarv De
Souarv De 2021 年 5 月 12 日
コメント済み: Souarv De 2021 年 5 月 12 日
I have a cell matrix as shoown below.
B={'2' '3' '5'; '4' '7' '2'; '7' '5' '2'}
B =
3×3 cell array
{'2'} {'3'} {'5'}
{'4'} {'7'} {'2'}
{'7'} {'5'} {'2'}
I want to convert it a numeric matrix like as follows:
A =
2 3 5
4 7 2
7 5 2

採用された回答

Stephan
Stephan 2021 年 5 月 12 日
編集済み: Stephan 2021 年 5 月 12 日
B={'2' '3' '5'; '4' '7' '2'; '7' '5' '2'}
B = 3×3 cell array
{'2'} {'3'} {'5'} {'4'} {'7'} {'2'} {'7'} {'5'} {'2'}
C = cellfun(@(x)str2double(x),B)
C = 3×3
2 3 5 4 7 2 7 5 2
  3 件のコメント
Stephen23
Stephen23 2021 年 5 月 12 日
Or, by simply reading the str2double documentation, you can easily have much much more efficient code:
B = {'2','3','5';'4','7','2';'7','5','2'};
M = str2double(B)
M = 3×3
2 3 5 4 7 2 7 5 2
Souarv De
Souarv De 2021 年 5 月 12 日
Woow. That's one is more easier to remember. Thanks to you once again Stephen.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by