Function sort and smooth in matlab

조회 수: 3 (최근 30일)
Shalini
Shalini 2012년 4월 10일
1) Consider the function sort:
You can call it with as below;
B = sort(A)
B = sort(A,dim)
If A is a vector, do I need the argument dim?
2)Now, consider the function smooth;
suppose I suply bot the independent variable x and dependent variable y as below;
yy = smooth(x,y,...)
Is it mandatory that I should be sorting all values of x in acending order before I plot?I mean does smooth carry out smoothing with x arrranged in ascending order?

답변 (1개)

Walter Roberson
Walter Roberson 2012년 4월 10일
1) If you are sorting a vector, you need to supply dim if you care about which direction the vector is sorted on.
In particular, it is possible that you expect your A to be a full array but there are conditions under which you might possibly get out a vector (e.g., a single row when you expect many rows.) If you do not specify the direction the sort could accidentally be a direction you did not expect.
yy = smooth(x,y,...) additionally specifies x data. If x is not provided, methods that require x data assume x = 1:length(y). You should specify x data when it is not uniformly spaced or sorted. If x is not uniform and you do not specify method, lowess is used. If the smoothing method requires x to be sorted, the sorting occurs automatically.
Note that final sentence.
  댓글 수: 13
Jan
Jan 2012년 4월 11일
@Geoff: Exactly.
Shalini
Shalini 2012년 4월 11일
@Geoff,Jan,Walter:
Please correct if I'm wrong and sorry if I'm fundamentally wrong.
We can sort with either dimension =1 or diemnsion =2.
When dimension =1 (during sort) the function 'sort', just arranges all the columns in ascending order.
When dimension =2 (during sort) the function 'sort', just arranges all rows in ascending order.
This is what (I think) is happening in the examples in this link:
http://www.mathworks.in/help/techdoc/ref/sort.html

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

카테고리

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