find values in a matrix

1 view (last 30 days)
elisa ewin
elisa ewin on 7 Sep 2016
Answered: Aditya Warnulkar on 7 Sep 2016
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?

Accepted Answer

Aditya Warnulkar
Aditya Warnulkar on 7 Sep 2016
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

More Answers (1)

Meghan
Meghan on 7 Sep 2016
You should be able to use the ismember function for that.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!