Clear Filters
Clear Filters

how to find the first nonzero value of a multidimensional matrix, with a certain value for some dimensions in that matrix

1 view (last 30 days)
I want to find the first nonzero element in a matrix, I'm now using
idx = find(NH3summer==min(NH3summer(NH3summer>0)));
[E,B,M,P,U,L] = ind2sub(size(NH3summer),idx);
NH3summer is a 6D matrix, but now i want to find the first nonzero value of NH3summer(:,B1,:,:,:,:) How can i index NH3summer so that it only looks in B1 for the second dimension? Thanks!
  1 Comment
Rik
Rik on 20 Feb 2017
Doesn't the code below work?
temp=NH3summer(:,B1,:,:,:,:);
idx = find(temp==min(temp(temp>0)));
[E,B,M,P,U,L] = ind2sub(size(temp),idx);
B=B1;
B will be 1 by definition, so we can ignore that one by setting it to B1.

Sign in to comment.

Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!