필터 지우기
필터 지우기

Error when using resample and smooth surfaces in CAT12

조회 수: 30 (최근 30일)
Maaike Vorsteveld
Maaike Vorsteveld 2024년 7월 5일 12:26
댓글: Umar 2024년 7월 5일 16:41
I am trying to use CAT12 to make do surface based morphometry. I am trying to load my cortical thickness maps in the resample and smooth function, but when doing that I get this error when trying to load the files clicking on 'specify':
Index exceeds the number of array elements. Index must not exceed 0.
Error in cat_surf_info (line 241)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
Error in cat_conf_stools>vout_surf_resamp (line 2245)
sinfo = cat_surf_info(job.data_surf{i});
Error in cat_conf_stools>@(job)vout_surf_resamp(job) (line 1275)
surfresamp.vout = @(job) vout_surf_resamp(job);
Error in cfg_exbranch/harvest (line 99)
item.sout = feval(item.vout, val);
Error in cfg_util (line 704)
[tag, val, u3, u4, u5, jobs(cjob).cj] = harvest(subsref(jobs(cjob).cj, ...
Error in cfg_ui_util>local_setvaledit (line 661)
cfg_util('harvest', ciid{1:end-1});
Error in cfg_ui_util>@(nval)local_setvaledit(ciid,nval,dflag) (line 275)
udvalshow.setvalcb = @(nval)local_setvaledit(ciid, nval, dflag);
Error in cfg_ui_util (line 454)
feval(udvalshow.setvalcb, val);
Error in cfg_ui>local_valedit_EditValue (line 404)
cfg_ui_util('valedit_EditValue', ciid, itemname, val);
Error in cfg_ui>module_Callback (line 978)
local_valedit_EditValue(hObject);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in cfg_ui (line 53)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)cfg_ui('module_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
What can I do to fix this error? I am using Matlab 2022a with SPM12 and CAT12.

답변 (2개)

Umar
Umar 2024년 7월 5일 12:38
Hi Maaike,
To fix the "Index exceeds the number of array elements" error in CAT12, you can try the following steps. Review the code in the cat_surf_info function at line 241 where the error occurs. Ensure that the indexing is correct and does not exceed the array size. Verify that hemi_ind(1) and the subsequent index calculations are within the bounds of the array. If necessary, adjust the indexing logic to ensure that the indices are valid and do not exceed the array size. After making adjustments, test the code again to see if the error has been resolved.
  댓글 수: 2
Maaike Vorsteveld
Maaike Vorsteveld 2024년 7월 5일 13:19
As CAT12 is a toolbox of SPM I thought it would be best to not edit the source code of the toolbox, so I am not sure if this is what I want to do...
Umar
Umar 2024년 7월 5일 16:41
Hi Maaike,
I do understand your concern about modifying the source code directly which can have significant consequences, such as affecting the stability and functionality of the toolbox. However, there are ways to customize or extend the functionality without directly altering the source code.
One approach is to utilize the provided customization options within the toolbox itself. Many toolboxes, including CAT12, offer configuration files or settings that allow users to tailor the behavior without modifying the source code. This method is preferred as it maintains the integrity of the original codebase while still providing flexibility for specific needs.
Another option is to create wrapper functions or scripts that interact with the toolbox's existing functions. By writing custom scripts that call the toolbox functions with additional parameters or logic, users can achieve the desired modifications without changing the core source code. This approach is more sustainable and easier to maintain than directly editing the source files.
If the required customization goes beyond what can be achieved through configuration or scripting, it might be necessary to delve into the source code. In such cases, it is advisable to create a copy of the toolbox and work on the duplicated version to avoid affecting the original installation. This way, any changes made can be isolated and tested without risking the stability of the primary toolbox.

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


Voss
Voss 2024년 7월 5일 14:52
편집: Voss 2024년 7월 5일 15:13
Here are lines 232-242 of cat_surf_info.m:
[~,ff2] = spm_fileparts(SPM.xY.VY(1).fname);
% find mesh string
hemi_ind = strfind(ff2,'mesh.');
if ~isempty(hemi_ind)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+3);
else
% find lh|rh string
hemi_ind = [strfind(ff2,'lh.') strfind(ff2,'rh.') strfind(ff2,'lc.') strfind(ff2,'rc.')];
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
end
That section of code gets the file name ff2 from SPM.xY.VY(1).fname, searches for 'mesh.', 'lh.', 'rh.', 'lc.', and 'rc.' in the file name, and assigns the first one found (in the order it searches, not in the order they appear in the file name) to sinfo(i).side (without the trailing '.').
The problem is that none of those are found in the file name, so hemi_ind is empty, so an error happens when trying to access hemi_ind(1).
For example, this file name contains 'rh.' and 'lh.', so sinfo(i).side is assigned to be 'lh' (since 'lh.' is searched for before 'rh.' is):
(I put the relevant code from above into the function get_side, defined below, to avoid having to repeat it three times.)
i = 1;
ff2 = 'some_file_name_containing_rh._and_lh._and_some_other_stuff';
sinfo = get_side(i,ff2)
sinfo = 'lh'
This file name contains 'mesh.', so sinfo(i).side is 'mesh':
ff2 = 'some_file_name_containing_rh._and_lh._and_mesh._and_some_other_stuff';
sinfo = get_side(i,ff2)
sinfo = 'mesh'
This file name contains none of the search terms, so hemi_ind is empty, and the error occurs when trying to access hemi_ind(1):
ff2 = 'some_file_name_containing_some_stuff';
sinfo = get_side(i,ff2)
Index exceeds the number of array elements. Index must not exceed 0.

Error in solution>get_side (line 16)
side = ff2(hemi_ind(1):hemi_ind(1)+1);
function side = get_side(i,ff2)
% find mesh string
hemi_ind = strfind(ff2,'mesh.');
if ~isempty(hemi_ind)
side = ff2(hemi_ind(1):hemi_ind(1)+3);
else
% find lh|rh string
hemi_ind = [strfind(ff2,'lh.') strfind(ff2,'rh.') strfind(ff2,'lc.') strfind(ff2,'rc.')];
side = ff2(hemi_ind(1):hemi_ind(1)+1);
end
end
As for how to fix it, execute the command
dbstop if error
on the MATLAB command line, then click the 'Specify' button, and when the breakpoint is triggered, check the value of SPM.xY.VY(1).fname and see if it's what you expect. The variable SPM comes from loading a .mat file a few lines above:
load(fullfile(pp,'SPM.mat'),'SPM');
so you may need to also verify that that .mat file (located at the location given by fullfile(pp,'SPM.mat')) is the file you want to be using. If everything is valid, but ff2 just doesn't contain any of the character sequences the developers of CAT12 assumed it would ('mesh.', 'lh.', 'rh.', 'lc.', or 'rc.'), then you may try adapting the code to handle that case without error. I don't know what would be the correct thing to do in that case, so I can't help you with that. Another option would be to modify the value of SPM.xY.VY(1).fname stored in that SPM.mat file so that it does conform to the CAT12 developers' unstated assumption(s), but this may have unintended side-effects, I don't know.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by