How to extract all values along the third axis of a 3d-array using a logical 2d-array?
Show older comments
clear all; close all; clc
a = rand(10,10);
a(5,5) = 10;
b = rand(10,10,1000);
c = b(a == 10,:);
I have a 3d-array from which I would like to extract all values along the third dimension, that meet a specific criterion outlined by a 2d-array. The result would be a vector with a length of 1000 in this example.
Using the above code yields
"The logical indices in position 1 contain a true value outside of the array bounds."
Is there another way to combine the logical 2d-array with : for the third dimension?
Accepted Answer
More Answers (1)
a = rand(10,10);
a(5,5) = 10;
b = a+rand(1,1,1000);
br=reshape(b,[],size(b,3));
c = br(a == 10,:)
1 Comment
Categories
Find more on Creating and Concatenating 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!