How to open gaps after uses the "find" command?
4 次查看(过去 30 天)
显示 更早的评论
I am working with a matrix data=[time depth density], and I am trying to select the densities of a specific range of depth. I tried the following expression:
>>dens=data(:,3);
>>ind_10=find(data(:,2)>=10);
>>dens_10=dens(ind_10);
It worked, but the matrix now have a size smaller than the previous one. I would like to keep dens_10 following the same "time", in order to plot then together. In other words, how can I open gaps on the new matrix in other to this one have the same size as the old one?
Thank you very much!
0 个评论
采纳的回答
Stephen23
2015-2-3
编辑:Stephen23
2015-2-3
Although find is very attractive for beginners, it is actually faster and neater to use logical indexing, so the equivalent to your code above would be:
ind_10 = data(:,2) >= 10;
dens_10 = data(ind_10,3);
This also allows us to easily define not only which elements we select from an array, but also those that we allocate into an array:
ind_10 = data(:,2) >= 10;
dens_10(ind_10) = data(ind_10,3);
You will probably need to consider what values to put in the non-allocated positions, something like this:
dens_10(~ind_10) = NaN; % or 0?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!