Converting Cell matrix to a Numeric Matrix
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Stephan
2021년 5월 12일
편집: Stephan
2021년 5월 12일
B={'2' '3' '5'; '4' '7' '2'; '7' '5' '2'}
C = cellfun(@(x)str2double(x),B)
댓글 수: 3
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)
추가 답변 (0개)
참고 항목
카테고리
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!