filter a matix column values

조회 수: 2 (최근 30일)
Boby S
Boby S 2019년 6월 13일
답변: Bob Thompson 2019년 6월 13일
Hi
I have a matrix with X and Y values for a trajectory. Also, distance and speed values.
I want to make a criteria(filter) for my speed or distance column; then, I will take those ralated XY points and plot/scatter them with different color code.
(for example, I want to plot XY points which distance is >1.5 for them).
The second goal which I am not sure if it is possible, is to plot these points on a figure which I plotted all XY points.

채택된 답변

KSSV
KSSV 2019년 6월 13일
Let X,Y,D,V be your (x,y) locations, distance and velocity respectively.
figure
hold on
plot(X,Y,'r')
plot(X(D>1.5),Y(D>1.5),'.b')
legend('path','locations D>1.5')

추가 답변 (1개)

Bob Thompson
Bob Thompson 2019년 6월 13일
The filtering can be accomplished using logic indexing. Plotting is simply a matter of storing the data separately and plotting again. For the example I am going to assume you have a 2D array, where the columns are in the following order: [X Y S D]
data = [X Y S D]; % Just assigning values, your initial data shouldn't look anything like this.
plot(data(:,1),data(:,2)) % Plot all X and Y points
red = data(data(:,4)>1.5,:); % Filter all results for distance > 1.5
hold on % Plot more than one thing on the previous figure
plot(red(:,1),red(:,2)) % Plot reduced data as a second line

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by