필터 지우기
필터 지우기

find values in a matrix

조회 수: 1 (최근 30일)
elisa ewin
elisa ewin 2016년 9월 7일
답변: Aditya Warnulkar 2016년 9월 7일
Hi,
I have a matrix A (attached):
A=[0 0 0 0 0 0 0 0 0 0 1933724 260957;
341255 0 0 0 0 0 0 0 0 0 12973 0;
23261 0 0 0 0 0 0 153505 0 420315 0 15372;
0 0 0 0 0 0 0 0 0 5535878 0 0;
0 0 0 0 0 0 0 0 0 16516 0 316637]
the rows of the matrix reppresent trajectories, every cell of the matrix contains the location id of trajectories and the colums indicated the time of study of this trajectories. The time is 24 hours so the rows are divide in interval of 2 hours: total 12 intervals that corrispond to the columns. I hope it's clear. Now I want to find in A, if a location rows is present in a particular interval. Eg. I want to know if 12973 is present in interval 1: if it's present I want to indicate it in another matrix in the same position with the value one, if it's not present I want to extend the interval of research until I can found the value.
Can you help me?

채택된 답변

Aditya Warnulkar
Aditya Warnulkar 2016년 9월 7일
Hi Elisa,
You can find the interval of the location ID using "find" and "any" command as follows
X = 12973; % Location ID of trajectory
I = find(any(A==X,2)); % I represents the interval
If the location ID occurs multiple times, then the above mentioned piece of code will output all the possible intervals. If you want to capture the value of first internal, then modify the code as follows
X = 12973; % Location ID of trajectory
I = min(find(any(A==X,2))); % I represents the interval

추가 답변 (1개)

Meghan
Meghan 2016년 9월 7일
You should be able to use the ismember function for that.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by