I keep getting the following error when trying to use another ROI than the one that was made when I wrote the function and script:
Subscript indices must either be real positive integers or logicals.Error in getROIvals (line 10) roi_vals(i) = mean(cur_img(ROI));Error in roi_fit (line 12)roi_vals = getROIvals(data,slice,ROI);
Can somebody please point out how to fix it? I originally used a ROI = roipoly(mat2gray(S0)) which has size 128×128, so I thought there would be no problem using another ROI-mask with same size and format (perhaps the problem is that it's not same size and format, allthough it is 128×128).
The function is:
function roi_vals = getROIvals(data,slice,ROI) S = double(squeeze(data(:,:,slice,:))); %size 128x128x8
n = size(S,3);roi_vals = zeros(n,1);for i = 1:n cur_img = S(:,:,i); roi_vals(i) = mean(cur_img(ROI)); endend
What does not work:
slice = 3; %the slice the mask is applied to
data = load4D('VOLUME_IMAGEb0',8,[0 50 100 150 400 500 600 800]);%S0 = double(squeeze(data(:,:,slice,1))); % for the ROI = roipoly(mat2gray(S0)), which works..
ROI = mat2gray(BW); %BW is a 128x128 mask yielded from another script
imagesc(ROI);save('ROI');roi_vals = getROIvals(data,slice,ROI);
Best Answer