MATLAB: Extracting data from a multidimensional array

extract datamultidimensional array

I have a multidimensional array (named "Xgrid") that is 52x151x43 (52 "pages", each with 151 rows and 43 columns). The rows and columns are excitation and emission data (ex and em in the examples below). I have already done a meshgrid step to to define ex and em over the relevant data interval:
[ex,em] = meshgrid(240:5:450,300:2:600)
I would like to extract paired data from each "page" of data. I know I can do this with the find function, but when I run it I end up with a single data point rather than one from each "page". For example, I get only a single value for Bpeak after running the lines below, rather than a 52×1 matrix containing Bpeak for each page:
B = find(ex==275 & em==310)
Bpeak = Xgrid(B)
Any advice on how to do this would be greatly appreciated! Thank you very much in advance.

Best Answer

A few comments:
  • a matrix of size [52, 141, 43] has 52 rows, 141 columns and 43 pages.
  • find is frequently over used and unneeded. The code
B = ex==275 & em==310; %logical array instead of indices
Bpeak = Xgrid(B)
would produce the exact same result faster.
Now to answer your question, you need to permute the dimensions of B so you have a 1x141x43 array, then repmat it across the rows, so:
B = ex==275 & em==310;
B = permute(B, [3 1 2]);
B = repmat(B, 52, 1, 1);
Bpeak = Xgrid(B)