How to customize the answer of Matlab in advance?

Hello,
I have an input matrix like [a b c d e] at the start.
I order these elements in the result according to my codes but I want to predefine the first element of my result. Let's say I obtain a result such as ans = [b e d a c] but I want the first element of this matrix to be d for instance.
What should I write to achieve this kind of a result?
Thank you :)

5 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 2 日
What is the expected result?
Pinar
Pinar 2013 年 8 月 2 日
Actually my input matrix contains x y coordinates of cities and I obtain a distance matrix between cities by calculating the Euclidean distances. I am achieving the optimum routing between these cities in the result. I want this routing to start from the central depot. My routing is like [2 4 6 7 1 5 3 2]. These numbers stand for the city numbers. I want this routing to start from 1 (which is the central depot) and there again.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 2 日
What do you mean by : My routing is like [2 4 6 7 1 5 3 2] ? and when you say I want this routing to start from 1 do you think it's enough to understand what you are looking for?
Pinar
Pinar 2013 年 8 月 2 日
This is a vehicle routing problem. A vehicle starts from city 2, then stops by city 4, 6, 7, 1, 5, 3 respectively and comes back again to city 2. I want that the vehicle starts its routing from city 1.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 2 日
What are you expecting as result?

回答 (4 件)

Iain
Iain 2013 年 8 月 2 日

0 投票

Its hard to see what you're trying to achieve, but this MIGHT be what you want to know
> data = [a b c d e];
> order_I_want = [4 3 2 1 5]; %
> data(order_I_want)
ans = [d c b a e]
> output = sort(data)
output = [e b c a d];
> order_I_want = [5 3 2 4 1]; %
> output(order_I_want)
ans = [d c b e a]

1 件のコメント

Iain
Iain 2013 年 8 月 2 日
"This is a vehicle routing problem. A vehicle starts from city 2, then stops by city 4, 6, 7, 1, 5, 3 respectively and comes back again to city 2. I want that the vehicle starts its routing from city 1."
data = [2 4 6 7 1 5 3];
data = data([find(data==1):end 1:(find(data==1)-1)])
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 2 日
編集済み: Azzi Abdelmalek 2013 年 8 月 2 日

0 投票

a_input=[1 2 3 4 5]
a_output=[2 5 4 1 3]
a_output(a_output==4)=[];
a_output=[4 a_output]
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 2 日

0 投票

a=[2 ,4, 6, 7, 1, 5, 3 ]
idx=find(a==1)
out=circshift(a, [0 -idx+1])
Andrei Bobrov
Andrei Bobrov 2013 年 8 月 2 日

0 投票

n = numel(a);
out = a(mod((2:n+1)-find(a == 1),n)+1);

この質問は閉じられています。

タグ

質問済み:

2013 年 8 月 2 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by