필터 지우기
필터 지우기

Merging vectors into one

조회 수: 4 (최근 30일)
Lucas Stadnik
Lucas Stadnik 2019년 10월 29일
댓글: Lucas Stadnik 2019년 10월 29일
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?

채택된 답변

Daniel M
Daniel M 2019년 10월 29일
편집: Daniel M 2019년 10월 29일
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
Daniel M
Daniel M 2019년 10월 29일
You can use writematrix to save it as a txt (among other similar things). save only save mat files.
Lucas Stadnik
Lucas Stadnik 2019년 10월 29일
Thank you for your help and time.
I appreciate it.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by