Borrar filtros
Borrar filtros

combining 3 different arrays of single column numbers into one array

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 10 de Jun. de 2011
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 comentarios
Michael
Michael el 10 de Jun. de 2011
no decimals needed in my case, only ever going to be integers
Matt Fig
Matt Fig el 10 de Jun. de 2011
An alternative:
str2num(sprintf('%i%i%i %i%i%i %i%i%i',a,b,c))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by