Adding vectors in Matlab

Hi! I have 4 different vectors and I need to add them like this:
mod1+lan1= x1
mod2+lan2= x2
But as you can see in the code the numbers are different.
mod1= [413 443 467 487 531 547 648 666 677 747 859 867 905 936 1388 1631 2121];
mod2= [mout8_c mout9_c mout3_c mout10_c mout11_c mout12_c mout1_c mout13_c mout14_c mout15_c mout2_c mout16_c mout17_c mout18_c mout26_c mout6_c mout7_c]
lan1= [485 560 660 815 1650 2215];
lan2=[out1_c out2_c out3_c out4_c out5_c out7_c]
So, what I've done for the x1 is:
x=[mod1 lan1];
x1= sort(x);
But the problem is on y because I need that the positions would be the same (like for example, on the position 413=mout8_c) but the numbers are totally diferents.
To sum up (maybe it's better if you look at this graph). I have that points and I need to add them in the order of each one.
Thanks a lot in advance and greetings,
Emma

댓글 수: 4

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 12일
not clear, plus the frog?
Emmanuelle
Emmanuelle 2012년 9월 12일
편집: Emmanuelle 2012년 9월 12일
Hi Azzi, sorry. The graph is because I think it's more clear. I have 4 vectors: 2x and 2y. But the order of the x are different:
mod1= [413 443 467 487 531 547 648 666 677 747 859 867 905 936 1388 1631 2121];
lan1= [485 560 660 815 1650 2215];
The problem is on y. I have different numbers, as you can see in the graph. And I need to add both. What happen? I don't need an order (like 1 2 3 4). I want them like in the image, in that order. But the x are different...
You don't need to sort them to do the regression. If the ‘mout’ values are scalars (as I assume), you can sort both vectors by the values in the x1 vector with the sort function.
If I understand you correctly, this would likely do what you want:
[x1s x1s_idx] = sort(x1);
and the corresponding x2 becomes:
x2s = x2(x1s_idx);
Emmanuelle
Emmanuelle 2012년 9월 13일
Thanks Star. At the end, I used the below code!

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 9월 12일

0 개 추천

mod1= [413 443 467 487 531 547 648 666 677 747 859 867 905 936 1388 1631 2121]';
lan1= [485 560 660 815 1650 2215]';
mod2 = { 'mout8_c' 'mout9_c' 'mout3_c' 'mout10_c' 'mout11_c' 'mout12_c' 'mout1_c' 'mout13_c' 'mout14_c' 'mout15_c' 'mout2_c' 'mout16_c' 'mout17_c' 'mout18_c' 'mout26_c' 'mout6_c' 'mout7_c'}';
lan2 = {'out1_c' 'out2_c' 'out3_c' 'out4_c' 'out5_c' 'out7_c'}';
[x1,i1] = sort([mod1;lan1]);
y = [mod2;lan2];
out = y(i1);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by