How to plot vertical line when hitting the range?

1 Ansicht (letzte 30 Tage)
Chen yuru
Chen yuru am 30 Jul. 2019
Kommentiert: Michelle Hirsch am 14 Apr. 2020
Hello, I would like to plot four red lines on the figure.
which is on the edge of yellow block.
But, I don't know how to find and plot it.
Attachment is new.mat , included fx, dy, new value.
The blue blocks are all zero and the yellow blocks are all 1.
Thanks.
1.png
load new.mat
contourf(fx,dy,new,'linestyle','none');
ylabel('Range Cell','FontSize',15,'Fontname','Times');
xlabel('Radial Velocity (m/s)','FontSize',15,'Fontname','Times')
set(gca,'FontSize',15,'Fontname','Times');
  2 Kommentare
KSSV
KSSV am 30 Jul. 2019
You can insert lines manually or get the points and plot line...this is one of the option.
Chen yuru
Chen yuru am 30 Jul. 2019
I would like to automatically select the yellow region.
Thanks.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Michael Madelaire
Michael Madelaire am 30 Jul. 2019
%% Init
clear all; close all; clc;
cd 'C:\Users\s144117\Desktop\mathworks'
%% Load
load('new')
%% Find boarders
boarders = [];
for i=2:length(new(:,1))-1
column_before = new(i-1, :);
column = new(i, :);
column_after = new(i+1, :);
flag_before = sum(column_before == 1) > 0;
flag = sum(column == 1) > 0;
flag_after = sum(column_after == 1) > 0;
if flag_before == 0 && flag == 1
boarders = [boarders, i-1];
elseif flag == 1 && flag_after == 0
boarders = [boarders, i+1];
end
end
%% Plot
contourf(fx,dy,new,'linestyle','none');
ylim = get(gca, 'ylim');
hold on;
for i=1:length(boarders)
plot([1,1]*fx(boarders(i)), ylim, '-', 'Color', 'red')
end
ylabel('Range Cell','FontSize',15,'Fontname','Times');
xlabel('Radial Velocity (m/s)','FontSize',15,'Fontname','Times')
set(gca,'FontSize',15,'Fontname','Times');
  2 Kommentare
Chen yuru
Chen yuru am 30 Jul. 2019
Thank you so much!
Michelle Hirsch
Michelle Hirsch am 14 Apr. 2020
Here's a small simplification for releases since 18b - you can call xline to draw the vertical lines instead of having to use the clever plot([1,1]* ...) trick.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by