-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLP_Sort_Sweep.m
More file actions
39 lines (36 loc) · 1.62 KB
/
LP_Sort_Sweep.m
File metadata and controls
39 lines (36 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Name: LP_Sort_Sweep.m
% Author: Claes Weyde
% Description:
% [Vs,Is,Q] = LP_Sort_Sweep(V,I)
%
% The data is adjusted the vectors (matrices) containing the data are sorted with
% respect to higher bias potential.Note that sorting is only needed if we have both
% down and up sweeps.
%
% 1. Now the data is sorted in ascending bias potential order. Here the MATLAB function "sort" is used,
% which sorts the potential in ascending order and saves the indices order. Thus, those indices can
% then be used on the current to sort it in the same way as the potential. The easiest way to do it in
% for example C++ would be to construct a "search for the least and swap"-algorithm using a nested for
% loop.
% 2. The adjusted data vectors are now returned from the function.
%
% Input:
% V Bias potential [V]
% I Probe current [A]
%
% Output:
% Vsorted Sorted bias potential [V]
% Isorted Sorted probe current [I]
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Vsorted,Isorted] = LP_Sort_Sweep(V,I)
[Vsorted,ind] = sort(V); % The function sort, sorts the elements of V
% in ascending order
Isorted = I(ind); % The elements of the current-vector Isorted changed
% accordingly, so that
% the correspondance in (V,I)-pairs remain the same after sorting
end