find values in a matrix
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 PHY Components 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!