trasform from a cell array into a matrix

조회 수: 9 (최근 30일)
elisa ewin
elisa ewin 2016년 6월 13일
댓글: Star Strider 2016년 6월 13일
Hi! I want to represent the values in pairs (attached) in a matrix
A = [
21714 1067829 '';
21714 18417 '';
21714 9241 420315;
21714 420315 420315;
21714 211286 '']
can you help me?
  댓글 수: 1
David H
David H 2016년 6월 13일
I'm afraid you need to be more specific, what you have there is not valid matlab syntax. If you have a cell array you want to convert to a matrix you can use "cell2mat" but I am not sure this is exactly what you are asking.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 6월 13일
This isn’t quite as efficient as I’d like it, but it works:
A={21714 1067829 ''; 21714 18417 ''; 21714 9241 420315; 21714 420315 420315; 21714 211286 ''};
LM = cellfun(@isempty, A, 'Uni',0);
LMN = find(cell2mat(LM));
A(LMN) = {NaN};
Result = cell2mat(A)
Result =
21714 1067829 NaN
21714 18417 NaN
21714 9241 420315
21714 420315 420315
21714 211286 NaN
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2016년 6월 13일
A(cellfun(@isempty,A)) = {nan};
out = cell2mat(A);
Star Strider
Star Strider 2016년 6월 13일
Brilliant as usual, Andrei! Thank you!
I couldn’t make the logical array work without the intermediate find call. Now I see I wasn’t using the most optimal approach.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by