- a matrix of size [52, 141, 43] has 52 rows, 141 columns and 43 pages.
- find is frequently over used and unneeded. The code
extracting data from a multidimensional array
11 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Guillaume
2018-1-17
A few comments:
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)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!