combining 3 different arrays of single column numbers into one array

조회 수: 4 (최근 30일)
basically i have 3 different columns: a, b, and c, which are all doubles
a = [1;2;3]; b = [2;0;1]; c = [1;0;1];
and i want to combine them into one, say d..
d = [121; 200; 311];
so d is a 3x1 vector od doubles

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 6월 10일
I'm pretty sure there's a better way but this will work:
cellfun(@(x)str2double(x(~isspace(x))),cellfun(@(x)num2str(x),mat2cell([a b c],ones(size(a,1),1),3),'uni',false))
%Needs more work to accept decimals.
  댓글 수: 3
Michael
Michael 2011년 6월 10일
no decimals needed in my case, only ever going to be integers
Matt Fig
Matt Fig 2011년 6월 10일
An alternative:
str2num(sprintf('%i%i%i %i%i%i %i%i%i',a,b,c))

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by