|
36 | 36 | %% ===== PARSE INPUTS ===== |
37 | 37 | global GlobalData; |
38 | 38 |
|
39 | | -% If target study is empty, we use the study of the source map |
40 | | -if (nargin < 5) || isempty(iStudy) |
41 | | - [~, iStudy] = bst_get('ResultsFile', ResultsFile); |
| 39 | +% No target study |
| 40 | +if (nargin < 5) |
| 41 | + iStudy = []; |
42 | 42 | end |
43 | 43 | % Is iVertices obtained on a volume atlas |
44 | 44 | if (nargin < 4) || isempty(isVolumeAtlas) |
|
75 | 75 | end |
76 | 76 | % Get associated data file |
77 | 77 | if ~isempty(ResultsMat.DataFile) |
78 | | - DataFile = file_short(ResultsMat.DataFile); |
| 78 | + [~, DataFile] = bst_fileparts(file_short(ResultsMat.DataFile)); |
79 | 79 | else |
80 | 80 | DataFile = []; |
81 | 81 | end |
|
124 | 124 |
|
125 | 125 | % ===== LOAD GAIN MATRIX ===== |
126 | 126 | bst_progress('text', 'Loading head model...'); |
| 127 | +% Get target study |
| 128 | +[sStudyResults, iStudyResults] = bst_get('ResultsFile', ResultsFile); |
| 129 | +if isempty(iStudy) || (iStudy == iStudyResults) |
| 130 | + sStudy = sStudyResults; |
| 131 | + iStudy = iStudyResults; |
| 132 | +else |
| 133 | + sStudy = bst_get('Study', iStudy); |
| 134 | + if isempty(sStudy) |
| 135 | + bst_error(sprintf('Target study (%d) does not exist in the Protocol.', iStudy), 'bst_simulation', 0); |
| 136 | + return |
| 137 | + end |
| 138 | +end |
127 | 139 | % Get default headmodel for this study |
128 | 140 | sHeadModel = bst_get('HeadModelForStudy', iStudy); |
129 | 141 | if isempty(sHeadModel) |
|
137 | 149 | nLocHeadmodel = size(HeadModelMat.GridLoc, 1); |
138 | 150 |
|
139 | 151 | % If the head model doesn't match the number of vertices: try loading the head model pointed by the results file |
140 | | -if (nLocHeadmodel ~= nLocResults) |
| 152 | +if (nLocHeadmodel ~= nLocResults) && (iStudy == iStudyResults) |
141 | 153 | % Get headmodel file from ResultsFile |
142 | 154 | HeadModelFile = ResultsMat.HeadModelFile; |
143 | 155 | % Load HeadModel file |
144 | 156 | HeadModelMat = in_bst_headmodel(HeadModelFile, 0, 'Gain', 'GridLoc', 'GridOrient', 'GridAtlas'); |
145 | 157 | % Number of dipoles in headmodel |
146 | 158 | nLocHeadmodel = size(HeadModelMat.GridLoc, 1); |
147 | | - % Check again the number of vertices |
148 | | - if (nLocHeadmodel ~= nLocResults) |
149 | | - bst_error(sprintf('Number of dipoles in the head model (%d) and the inverse model (%d) do not match.', nLocHeadmodel, nLocResults), 'bst_simulation', 0); |
150 | | - return; |
151 | | - end |
| 159 | +end |
| 160 | +% Check the number of vertices |
| 161 | +if (nLocHeadmodel ~= nLocResults) |
| 162 | + bst_error(sprintf('Number of dipoles in the head model (%d) and the inverse model (%d) do not match.', nLocHeadmodel, nLocResults), 'bst_simulation', 0); |
| 163 | + return; |
152 | 164 | end |
153 | 165 | % If no orientations: error |
154 | 166 | if (nComponents ~= 3) && isempty(HeadModelMat.GridOrient) |
|
211 | 223 | DataMat.Comment = DataComment; |
212 | 224 | DataMat.Time = TimeVector; |
213 | 225 | DataMat.F = F; |
214 | | -DataMat.ChannelFlag = GlobalData.DataSet(iDS).Results(iResult).ChannelFlag; |
| 226 | +DataMat.ChannelFlag = ones(size(HeadModelMat.Gain, 1), 1); |
215 | 227 | DataMat.DataType = 'recordings'; |
216 | 228 | % History |
217 | 229 | DataMat = bst_history('add', DataMat, 'simulation', 'File simulated: Headmodel * Results'); |
|
222 | 234 | %% ===== SAVE FILE ===== |
223 | 235 | % Output file |
224 | 236 | if isempty(DataFile) |
225 | | - outputFolder = bst_fileparts(GlobalData.DataSet(iDS).StudyFile); |
226 | | - newDataFile = bst_fullfile(ProtocolInfo.STUDIES, outputFolder, ['data_simulation_', strTime, '.mat']); |
| 237 | + OutputFileName = ['data_simulation_', strTime, '.mat']; |
227 | 238 | else |
228 | | - newDataFile = bst_fullfile(ProtocolInfo.STUDIES, strrep(DataFile, '.mat', '_simulation.mat')); |
| 239 | + OutputFileName = [DataFile, '_simulation.mat']; |
229 | 240 | end |
| 241 | +newDataFile = bst_fullfile(ProtocolInfo.STUDIES, bst_fileparts(sStudy.FileName), OutputFileName); |
230 | 242 | newDataFile = file_unique(newDataFile); |
231 | 243 | % Save file |
232 | 244 | bst_save(newDataFile, DataMat, 'v6'); |
|
0 commit comments