Borrar filtros
Borrar filtros

Merging vectors into one

4 visualizaciones (últimos 30 días)
Lucas Stadnik
Lucas Stadnik el 29 de Oct. de 2019
Comentada: Lucas Stadnik el 29 de Oct. de 2019
Hi, I am new to Matlab and I'm trying to use it as a tool to create a model.
I have two vectors, both of them are <1x6001> double,
x=(x1,x2,x3...)
y=(y1,y2,y3...)
but what I need is to merge them as one in the following way:
z=(x1,y1;x2,y2;x3,y3...,xn;yn) - comma separates the elements, and semicolon separates the pairs.
so that I can use it as input data.
Is there a way to do it?

Respuesta aceptada

Daniel M
Daniel M el 29 de Oct. de 2019
Editada: Daniel M el 29 de Oct. de 2019
Simple:
x = 1:10;
y = x + 10; % for example
% x and y are both [1x10] row vectors as you mentioned
z = [x(:), y(:)];
% z is a [10x2] matrix of
% [x1, y1;
% x2, y2;
% .....
% xn, yn]
And if you want it back in 'row' form, just transpose z using an apostrophe '
  7 comentarios
Daniel M
Daniel M el 29 de Oct. de 2019
You can use writematrix to save it as a txt (among other similar things). save only save mat files.
Lucas Stadnik
Lucas Stadnik el 29 de Oct. de 2019
Thank you for your help and time.
I appreciate it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by