Order and plot two linked vectors
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hi, I have two vectors in which all the elements of the vector called "rho" in the Matlab code corresponds exactly at the elements in the other vector called "h". I want to order the vector "rho" from the smallest value to the greatest one, but when I do that, Matlab linked, for example the first element (the smallest) of the reorderd "rho" with the first element of "h", but in my work this is not correct. I write you the code:
if true
% num = 250;
delta_omega = 1/num;
h = 0.1+0.006:0.006:1.6
for i=1:length(h)
RXi=RX1 - h(i)*RX2
fx = (sort(RXi)')';
n = length(RXi);
p = ((1:n)/n)';
F=2.59
x=3.59
c=3.59
k=0.5
K = (F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - k^2*exp(-k*(F + c - x))*(F*exp(-x) - 1) - F*exp(-k*(F + c - x))*exp(-x) + 2*F*k*exp(-k*(F + c - x))*exp(-x) + F*k^2*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1)^2 + 2*F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1))/(k*exp(-k*(F + c - x))*(F*exp(-x) - 1) + F*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F)) - F*exp(-k*(F + c - x))*exp(-x) + F*k*exp(-x)*exp(-k*(F + c - x - (exp(F) - exp(x))/F))*(exp(x)/F - 1));
phi=(K*exp(-K*p))/(1-exp(-K));
if true
% code
rho=phi.*(RXi.*p)
rho1= -phi.*(RXi.*p)
VX=[rho, h']
VX1=[rho1,h']
plot(h', rho)
plot(h',rho1)
end
How can I order the vectors together in order to have the correct correspondence of values? I remeber you that I want to order "rho" from the smallest value to the greatest one.
댓글 수: 0
답변 (2개)
Star Strider
2015년 8월 3일
From the documentation:
- B = sortrows(A,column) sorts matrix A based on the columns specified in the vector, column. This input is used to perform multiple column sorts in succession.
Try this:
Vxs = sortrows(Vx, 1);
and see if that does what you want.
댓글 수: 4
Star Strider
2015년 8월 3일
PIERLUIGI PEDERZOLI’s ‘Answer’ moved here:
Yes I have a the correct order into the matrix! Thank you..but now I have to plot that in a chart with on the x axis h, and in the y axis rho..
Star Strider
2015년 8월 3일
You simply have to ‘split’ the ‘Vx’ matrix column-wise:
figure(1)
plot(Vx(:,2), Vx(:,1))
grid
However, note that this is sorted by Vx(:,1), not Vx(:,2), so you need to be aware of that.
PIERLUIGI PEDERZOLI
2015년 8월 4일
Star Strider
2015년 8월 4일
My pleasure!
If my Answer solved your problem, please Accept it.
Ortinomax
2015년 8월 4일
Another simple way is to use indice in the second output of the sort function.
[rho_sorted order]= sort(rho);
h_rho=h(order);
[rho1_sorted order]= sort(rho1);
h_rho1=h(order);
Then you can plot vectors.
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!