extracting data from a multidimensional array

조회 수: 11 (최근 30일)
JGareis
JGareis 2018년 1월 17일
댓글: JGareis 2018년 1월 18일
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 52x1 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.

채택된 답변

Guillaume
Guillaume 2018년 1월 17일
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)
  댓글 수: 1
JGareis
JGareis 2018년 1월 18일
Thank you very much - this worked perfectly!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by