Swapping of data points

조회 수: 2 (최근 30일)
Sreeraj T
Sreeraj T 2018년 4월 12일
편집: Chris 2022년 9월 11일
I have a MATLAB code which has been attached with this question. when you run it and plot it (which has been already done in the program), the output file produces a zig-zag pattern. What really happens is that the values that is being written are being done so very randomly. For e.g. look the r(118,4) which is -32.654347733133000 and look at the value just below it r(119,4) which is 24.888699542411665 + 14.273828030014714i. If you look at the trend in which the fourth column goes one can see that whatever given in r(119,4) is unacceptable, but on the other-hand whatever in r(119,6)= -32.892395565247682 is acceptable. And once you do this for all the places where this happens, the plot becomes clear.
My question is why is this "root swapping" happens? And how can this be solved? I have tried 'sort' command, but that destroys whole order of 'r'.
Any help will be deeply appreciated...

답변 (1개)

Chris
Chris 2022년 9월 11일
편집: Chris 2022년 9월 11일
The hopping happens because the output of roots() isn't sorted in a way that is useful for this script.
Further, when you use sort() on complex numbers, the function considers their absolute values by default. That doesn't work in this case.
Try:
r(i,:)=sort(roots(q),'ComparisonMethod','real');
or after the loop has finished:
r = sort(r,2,'ComparisonMethod','real');

카테고리

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