76
76
if ~ischar(varargin{1 }) && nargin == 1
77
77
obj .ErrorCheck();
78
78
return
79
- end
79
+ end
80
80
81
81
if nargin == 2
82
82
obj .SetDataStorageScheme(varargin{2 });
@@ -238,8 +238,12 @@ function SortData(obj)
238
238
239
239
% ---------------------------------------------------------
240
240
function err = LoadProbeMeasList(obj , fdata , err )
241
- if isproperty(fdata ,' SD' )
242
- obj .CopyProbe(fdata .SD );
241
+ SD = fdata ;
242
+ while isproperty(SD ,' SD' )
243
+ SD = SD .SD ;
244
+ end
245
+ if isproperty(SD ,' SrcPos' )
246
+ obj .CopyProbe(SD );
243
247
if isempty(obj .SD ) && err == 0
244
248
err = - 4 ;
245
249
end
@@ -361,10 +365,15 @@ function SaveMat(obj, fname, options)
361
365
end
362
366
[~ , k1 ] = sortrows(obj .SD .MeasList );
363
367
[~ , k2 ] = sortrows(obj2 .SD .MeasList );
364
- if ~all(obj .SD .MeasList(k1 ,: ) == obj2 .SD .MeasList(k2 ,: ))
368
+
369
+ % Compare meas list dimensions first - if that's not equal then the probes aren't equal
370
+ if ~all( size(obj .SD .MeasList(k1 ,: )) == size(obj2 .SD .MeasList(k2 ,: )) )
365
371
return ;
366
- end
372
+ end
367
373
374
+ if ~all(obj .SD .MeasList(k1 ,: ) == obj2 .SD .MeasList(k2 ,: ))
375
+ return ;
376
+ end
368
377
369
378
for kk = 1 : length(fields )
370
379
for jj = 1 : length(fields{kk })
@@ -1261,7 +1270,7 @@ function FixProbeSpatialUnit(obj)
1261
1270
1262
1271
1263
1272
% ----------------------------------------------------------------------------------
1264
- function CopyProbe(obj , SD ) % #ok<INUSD>
1273
+ function CopyProbe(obj , SD )
1265
1274
fields = propnames(obj .SD );
1266
1275
for ii = 1 : length(fields )
1267
1276
if eval( sprintf(' isfield(SD, ''%s'' )' , fields{ii }) )
@@ -1339,7 +1348,7 @@ function CopyProbe(obj, SD) %#ok<INUSD>
1339
1348
1340
1349
% MesListAct
1341
1350
if size(obj .SD .MeasListAct ,1 ) < size(obj .SD .MeasList ,1 )
1342
- d = size(obj .SD .MeasListAct ,1 ) - size(obj .SD .MeasList ,1 );
1351
+ d = size(obj .SD .MeasListAct ,1 ) - size(obj .SD .MeasList ,1 ); % #ok<*PROPLC>
1343
1352
if d < 0
1344
1353
obj .SD .MeasListAct(end + 1 : end + abs(d )) = ones(abs(d ),1 );
1345
1354
elseif d > 1
@@ -1376,8 +1385,68 @@ function CopyStruct(obj, s)
1376
1385
end
1377
1386
end
1378
1387
end
1388
+
1389
+
1390
+
1391
+ % ----------------------------------------------------------------------------------
1392
+ function b = IsProbeFlat(obj )
1393
+ b = false ;
1394
+ if length(obj .SD .SrcPos ) == length(obj .SD .SrcPos3D )
1395
+ if ~all(obj .SD .SrcPos == obj .SD .SrcPos3D )
1396
+ return ;
1397
+ end
1398
+ end
1399
+ if length(obj .SD .DetPos ) == length(obj .SD .DetPos3D )
1400
+ if ~all(obj .SD .DetPos == obj .SD .DetPos3D )
1401
+ return
1402
+ end
1403
+ end
1404
+ optpos = [obj .SD .SrcPos3D ; obj .SD .DetPos3D ];
1405
+ ncoord = size(optpos , 2 );
1406
+ for ii = 1 : ncoord
1407
+ if length(unique(optpos(: ,ii )))==1
1408
+ b = true ;
1409
+ return
1410
+ end
1411
+ end
1412
+ b = true ;
1413
+ end
1414
+
1415
+
1416
+
1417
+ % ----------------------------------------------------------------------------------
1418
+ function b = Are3DLandmarksFlat(obj )
1419
+ b = true ;
1420
+ if isempty(obj .SD .Landmarks3D .pos )
1421
+ return ;
1422
+ end
1423
+ ncoord = size(obj .SD .Landmarks3D .pos , 2 );
1424
+ for ii = 1 : ncoord
1425
+ if length(unique(obj .SD .Landmarks3D .pos(: ,ii )))==1
1426
+ return ;
1427
+ end
1428
+ end
1429
+ b = false ;
1430
+ end
1431
+
1379
1432
1380
1433
1434
+ % ----------------------------------------------------------------------------------
1435
+ function b = AreLandmarksFlat(obj )
1436
+ b = true ;
1437
+ if isempty(obj .SD .Landmarks .pos )
1438
+ return ;
1439
+ end
1440
+ ncoord = size(obj .SD .Landmarks .pos , 2 );
1441
+ for ii = 1 : ncoord
1442
+ if length(unique(obj .SD .Landmarks .pos(: ,ii )))==1
1443
+ return ;
1444
+ end
1445
+ end
1446
+ b = false ;
1447
+ end
1448
+
1449
+
1381
1450
1382
1451
% ----------------------------------------------------------------------------------
1383
1452
function err = ConvertSnirfProbe(obj , snirf )
@@ -1391,7 +1460,7 @@ function CopyStruct(obj, s)
1391
1460
try
1392
1461
obj.SD.Lambda = snirf .probe .wavelengths ;
1393
1462
obj.SD.SrcPos = snirf .probe .sourcePos2D ;
1394
- obj.SD.DetPos = snirf .probe .detectorPos2D ;
1463
+ obj.SD.DetPos = snirf .probe .detectorPos2D ;
1395
1464
obj.SD.SrcPos3D = snirf .probe .sourcePos3D ;
1396
1465
obj.SD.DetPos3D = snirf .probe .detectorPos3D ;
1397
1466
obj.SD.MeasList = snirf .GetMeasList();
@@ -1400,17 +1469,17 @@ function CopyStruct(obj, s)
1400
1469
obj.SD.Landmarks3D.labels = snirf .probe .landmarkLabels ;
1401
1470
obj.SD.Landmarks3D.pos = snirf .probe .landmarkPos3D ;
1402
1471
end
1403
- if length(snirf .probe .landmarkLabels ) == size(snirf .probe .landmarkPos2D ,1 )
1404
- obj.SD.Landmarks2D.labels = snirf .probe .landmarkLabels ;
1405
- obj.SD.Landmarks2D.pos = snirf .probe .landmarkPos2D ;
1406
- end
1407
- if ~isempty(obj .SD .Landmarks3D .labels )
1408
- obj.SD.Landmarks.pos = obj .SD .Landmarks3D .pos ;
1409
- obj.SD.Landmarks.labels = obj .SD .Landmarks3D .labels ;
1410
- elseif ~isempty(obj .SD .Landmarks2D .labels )
1411
- obj.SD.Landmarks.pos = obj .SD .Landmarks2D .pos ;
1412
- obj.SD.Landmarks.labels = obj .SD .Landmarks2D .labels ;
1413
- end
1472
+ if length(snirf .probe .landmarkLabels ) == size(snirf .probe .landmarkPos2D ,1 )
1473
+ obj.SD.Landmarks2D.labels = snirf .probe .landmarkLabels ;
1474
+ obj.SD.Landmarks2D.pos = snirf .probe .landmarkPos2D ;
1475
+ end
1476
+ if ~isempty(obj .SD .Landmarks3D .labels )
1477
+ obj.SD.Landmarks.pos = obj .SD .Landmarks3D .pos ;
1478
+ obj.SD.Landmarks.labels = obj .SD .Landmarks3D .labels ;
1479
+ elseif ~isempty(obj .SD .Landmarks2D .labels )
1480
+ obj.SD.Landmarks.pos = obj .SD .Landmarks2D .pos ;
1481
+ obj.SD.Landmarks.labels = obj .SD .Landmarks2D .labels ;
1482
+ end
1414
1483
catch
1415
1484
err = - 1 ;
1416
1485
end
@@ -1452,10 +1521,7 @@ function ConvertSnirfStim(obj, snirf)
1452
1521
1453
1522
% ----------------------------------------------------------------------------------
1454
1523
function ConvertSnirfAux(obj , snirf )
1455
- obj.aux = zeros(length(obj .t ), length(snirf .aux ));
1456
- for ii = 1 : length(snirf .aux )
1457
- obj .aux(: ,ii ) = snirf .aux(ii ).dataTimeSeries;
1458
- end
1524
+ obj.aux = snirf .GetAuxDataMatrix();
1459
1525
end
1460
1526
1461
1527
@@ -1541,7 +1607,14 @@ function ErrorCheck(obj)
1541
1607
end
1542
1608
end
1543
1609
end
1544
-
1610
+ if obj .IsProbeFlat()
1611
+ obj.SD.SrcPos3D = [];
1612
+ obj.SD.DetPos3D = [];
1613
+ end
1614
+ if obj .Are3DLandmarksFlat() && ~obj .AreLandmarksFlat()
1615
+ obj.SD.Landmarks3D.pos = obj .SD .Landmarks .pos ;
1616
+ obj.SD.Landmarks3D.labels = obj .SD .Landmarks .labels ;
1617
+ end
1545
1618
end
1546
1619
1547
1620
0 commit comments