sorting the values of a vector into a new one by its elements size

1 回表示 (過去 30 日間)
MagJ_
MagJ_ 2018 年 11 月 29 日
コメント済み: MagJ_ 2018 年 12 月 5 日
Hey all
I made some measurements. Between these values, I interpolated. Now, I want to merge both vectors into one but withouth changing the order. Just copy in the new interpolated values into the intervalls of the measured values.
Is there a predefined function from matlab or do I have to write it myself?
Thanks in advance
  2 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 29 日
upload a short example to know what you are talking about
MagJ_
MagJ_ 2018 年 11 月 29 日
Alright, sorry:
Say I have a vector
x=[1,5,7,9]
Now, I interpolated between these values and I get a new vector with
y=[0.5,1.5,2,2.5,3,3.5,4...]
and some more values which I left away for now. I don't know wether this is real linear interpolation. I should think about it but it did not matter atm.
Well, now I want to merge both vectors like this:
xnew=[0.5,1,1.5,2,2.5,3,3.5,4...,5,7,9]
Values shall get sorted into the vector by it's values basically.
I hope you understand my problem now. I fear that it is very simple but I don't see it yet.

サインインしてコメントする。

採用された回答

Luna
Luna 2018 年 11 月 29 日
Try this,
xnew = sort(horzcat(y,x)) % concatane vectors then sort all
%% OR
xnew = horzcat(sort(y),sort(x)) % sort x, sort y seperately then concatanate
  3 件のコメント
Luna
Luna 2018 年 11 月 29 日
Yes :) thanks!
MagJ_
MagJ_ 2018 年 12 月 5 日
Thanks for this answer. And please apologize my late response.

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 29 日
編集済み: madhan ravi 2018 年 11 月 29 日
Simple and easy solution:
xnew=sort([x y])

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by