Removing values so two vectors are the same length

Determine how to remove values from the time vector which correspond exactly with those removed from the data vector, so these two vectors are synchronized.
Essentially we need to construct a code which synchronizes the two data sets which have different lengths. Been working on this for a week and have gotten nowhere.
With the code constructed already, this converted error flagged outlier sea-surface temperature data into zeros and then with another line of code this removed the zeros from the data so the length of this data is now less than the data we have for time. I know the code process to flag and convert the time data into zeros then remove those zeros but the problem lies in establishing a code which will remove values from the time vector which correspond exactly with data removed from the sea-surface temperature data vector.

답변 (2개)

Star Strider
Star Strider 2017년 10월 17일
If I understand correctly what you want to do, something like this will work:
time = 1:15; % Create ‘time’ Vector
sst = rand(size(time)); % Create ‘sea surface temperature’ Vector
outlier_idx = sst > 0.9; % Logical Vector Identifying Outliers
new_time = time(~outlier_idx); % Keep ‘time’ For Accepted Data
new_sst = sst(~outlier_idx); % Keep ‘sst’ For Accepted Data
The negation ‘~’ operator here keeps the elements not identified as outliers in ‘outlier_idx’.

댓글 수: 4

Thanks for the response! I'll rephrase my question b/c it was wordy and I'm sure confusing. Essentially, we used MATLAB to open up an excel file which had sea-surface temperature data and time data. We had 194 samples of data for each. We constructed a code which converted error flagged and outlier data from the sea-surface temperature data set into 0's then constructed a code to eliminate these numbers, this reducing the length of this data.
Now we need to construct a code which will eliminate the time data which corresponds to the data removed from the sea-surface temperature data. In the end we will need 40 values removed. so if we had an a sea-surface temperature value removed, that corresponding time value needs to be removed.
This is the graph we have and when constructed correctly those outliers should be removed and the gaps filled in:
Maybe just to add. Let's say my x column has values 2, 5, 0, 7, 6, 0 and my y column is 1, 2, 3, 4, 5, 6..so we have (2, 1) (5, 2), (0,3), (7,4), (6,5), (0,6). so I would want to remove the y =3 and y =6. but need to do this for 40 values
That requires only a slight variation on my code:
x = [2, 5, 0, 7, 6, 0];
y = [1, 2, 3, 4, 5, 6];
remove_idx = x == 0;
new_x = x(~remove_idx)
new_y = y(~remove_idx)
new_x =
2 5 7 6
new_y =
1 2 4 5
This will work with row and column vectors.
My pleasure!
If you look at the plot you posted before, note that the y-axis spans the range of 0 to 1000, while your latest plot ranges from about 22 to 34. With the ‘outliers’ eliminated, you are likely seeing your actual data.
One way to verify this is to take the earlier plot and restrict the y-axis limits. Put this set call after the plot call for your original data (that created your earlier plot):
set(gca, 'YLim',[-10 50])
(I don’t know what the actual ranges are, so you may have to adjust the ones I provided.) You will then likely see similar variation in the original data you are now seeing with the ‘outliers’ removed.

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

KL
KL 2017년 10월 17일

0 개 추천

Why don't you put those two vectors (time and data) in table (or even better in a timetable, if you're using 2016 or later) before you process the flags? Then you could simply remove the entire rows that you don't want.

카테고리

도움말 센터File Exchange에서 Vector Fields에 대해 자세히 알아보기

태그

질문:

2017년 10월 17일

댓글:

2017년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by