Skip to content

Commit 1e64227

Browse files
committed
collapse measurementList according to JSNIRF spec
1 parent 16c7ab4 commit 1e64227

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

aos2soa.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function st=aos2soa(starray)
2+
%
3+
% st=aos2soa(starray)
4+
%
5+
% Convert an array-of-structs (AoS) to a struct-of-arrays (SoA)
6+
%
7+
% author: Qianqian Fang (q.fang <at> neu.edu)
8+
%
9+
% input:
10+
% starray: a struct array, with each subfield a simple scalar
11+
%
12+
% output:
13+
% str: a struct, containing the same number of subfields as starray
14+
% with each subfield a horizontal-concatenation of the struct
15+
% array subfield values.
16+
%
17+
% example:
18+
% a=struct('a',1,'b','0','c',[1,3]');
19+
% st=aos2soa(repmat(a,1,10))
20+
%
21+
% this file is part of JSNIRF specification: https://github.com/fangq/jsnirf
22+
%
23+
% License: GPLv3 or Apache 2.0, see https://github.com/fangq/jsnirf for details
24+
%
25+
26+
27+
if(nargin<1 || ~isstruct(starray))
28+
error('you must give an array of struct');
29+
end
30+
31+
if(numel(starray)==1)
32+
st=starray;
33+
return;
34+
end
35+
36+
st=struct;
37+
fn=fieldnames(starray);
38+
for i=1:length(fn)
39+
st.(fn{i})=[starray(:).(fn{i})];
40+
end

snirfdecode.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747

4848
if(issnirf==0 && isfield(data,'nirs') && isfield(data,'formatVersion') && ~isfield(data,'SNIRFData'))
4949
data.SNIRFData=data.nirs;
50+
if(isfield(data.SNIRFData,'data') && isfield(data.SNIRFData.data,'measurementList'))
51+
data.SNIRFData.data.measurementList=aos2soa(data.nirs.data.measurementList);
52+
end
5053
if(iscell(data.nirs))
5154
for i=1:length(data.nirs)
5255
data.SNIRFData{i}.formatVersion=data.formatVersion;

0 commit comments

Comments
 (0)