Extract a specified interval of numbers from a multidimensional array
Show older comments
Hello,
I have a multidimensional array, let's call it error, of the size (37,4,4,3) which is basically filled with numbers ranging from 0-1 describing the amount of error for a certain application. What I want to do is extract intervals for each vector (:,i,j,k) of the total array, when the numbers are within a certain tolerance of 0.03. For example if we take error(:,1,1,1), I want to be able to get a strict interval with the values from 0-0.03.
So far I have been using the find function in a for-loop to determine the 'first' position which is a value below 0.03 and the 'last' position which is a value below 0.03. The problem with this is that sometimes there is a value exceeding 0.03 within those positions, which I don't want.
for k = 1:3
for j = 1:4
for i = 1:4
pos_first(:,i,j,k) = find(error(:,i,j,k) <= 0.3,1,'first');
pos_last(:,i,j,k) = find(error(:,i,j,k) <= 0.3 & error(:,i,j,k) > 0,1,'last');
end
end
end
I also tried to write error(error < 0.03 & error > 0), but that bunched all of the numbers into one single vector, which I don't want. I need to have it in a format where I can distinguish between the dimensions (:,4,4,3).
I therefore wonder if anyone know a smart way to accomplish this.
/ Jonatan
Accepted Answer
More Answers (0)
Categories
Find more on Whos 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!