Creating a plotting Threshold across multiple variables

3 ビュー (過去 30 日間)
Thallon Pitchure
Thallon Pitchure 2020 年 9 月 23 日
回答済み: Raag 2025 年 6 月 24 日
Hello again!
Today I am trying to add a second layer to an exisiting plot by using a threshold for when the distance from the median deviates +/- 5 mm. I am not sure using logical operators is helpful or just confusing me more.
I have attached my code below. The issue I am having is retaining the original matrix column and carrying the values over into a new matrix when I get a logical 1. I cannot figure out how to turn my logical array back into a matrix with the appropriate/orignal numbers in the correct placement with respect to the original matrix column.
I apologize if my description is confusing. I will be actively viewing if any one has any questions. I feel like I am on the right idea but still not sure if this actually makes sense from a programming stand point.
Thank you for your time and help.
%% 3) Adding multiple lines to a plot
% - Color the part of the line from the previous plot where the CoP deviates more than 5mm away from
% the center on the x axis or more than 5mm away from the center on the y axis in red.
% Do this by plotting a second line on top of the line from question number 2.
Mx = median(COPD_data.AnteriorPosteriorSway_mm_) %median(Sortx)
My = median(COPD_data.MedioLateralSway_mm_) %median(Sorty)
Basex_plus = Mx+5 %mm
Basex_minus = Mx-5
Basey_plus = My+5 %mm
Basey_minus = My-5
Adjust_AP = (COPD_data.AnteriorPosteriorSway_mm_ >= Basex_minus &...
COPD_data.AnteriorPosteriorSway_mm_ >= Basex_plus)
Adjust_ML = (COPD_data.MedioLateralSway_mm_>= Basey_minus &...
COPD_data.MedioLateralSway_mm_>= Basey_plus)
%Dev_AP(Adjust_AP)
plot (Adjust_AP, Adjust_ML, 'r--')
hold off

回答 (1 件)

Raag
Raag 2025 年 6 月 24 日
Hi Thallon,
As per my understanding, you are trying to overlay a threshold-based highlight on an existing sway plot, where the threshold is defined as a ±5 mm deviation from the median in either the anterior-posterior or medio-lateral directions.
The issue you are encountering seems to stem from using logical arrays directly in the plot function, which does not retain the original data values or structure. To resolve this, you can use logical indexing to extract the actual sway values that exceed the threshold and then overlay them on the original plot. Here's how you can do it:
% Calculate medians
Mx = median(COPD_data.AnteriorPosteriorSway_mm_);
My = median(COPD_data.MedioLateralSway_mm_);
% Define ±5 mm thresholds
Basex_plus = Mx + 5;
Basex_minus = Mx - 5;
Basey_plus = My + 5;
Basey_minus = My - 5;
% Extract sway data
x = COPD_data.AnteriorPosteriorSway_mm_;
y = COPD_data.MedioLateralSway_mm_;
% Identify points that deviate beyond the threshold
deviation Mask = (x > Basex_plus | x < Basex_minus | y > Basey plus | y < Basey minus);
% Plot original sway data
plot(x, y, 'b'); % Blue line for all data
hold on;
% Overlay deviations in red
plot(x(deviation Mask), y(deviation Mask), 'r--');
% Red dashed line for deviations
xlabel('Anterior-Posterior Sway (mm)');
ylabel('Medio-Lateral Sway (mm)');
title('Sway Plot with Threshold Highlighting');
legend('Within ±5 mm', 'Beyond ±5 mm');
hold off;
This will result in the following output:
For more information, refer:

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by