Compare two vector arrays and if they match set vector array 2 = nan?
Show older comments
So i have two arrays the same size:
time = [0,0,0,0,2,3,4,5,5,6,7,8]';
solution = [1,2,0,0,1,1,2,2,2,0,0,0];
What would be the best way to compare the two and if both are the same make solution 0 = nan;
So the final outcome i would like is solution = [1,2,nan,nan,1,1,2,2,2,0,0,0];
would i use a function such as:
if strfind(time,solution)==0
Do something?
Thanks in adavnce!
Accepted Answer
More Answers (1)
Try this...
time = [0,0,0,0,2,3,4,5,5,6,7,8];
solution = [1,2,0,0,1,1,2,2,2,0,0,0];
[idx]=find(time==solution);
solution(idx)=[NaN NaN]
2 Comments
Stephen23
on 11 Feb 2022
FIND is not required, logical indexing is simpler and more efficient.
It would be better to allocate a scalar NaN.
Categories
Find more on Logical 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!