"Subscripted assignment dimension mismatch" when checking for signals in ventricles and outside of the brain

1 view (last 30 days)
When I enter a command "m= extract_gray_white_csf(dat);" it returns the following error message:
Extracting from gray_matter_mask.img.
Subscripted assignment dimension mismatch.
Error in image_vector/extract_gray_white_csf (line 36)
values(:, i) = nanmean(masked_obj.dat, 1)';
The other questions I have read seem to indicate that the source and destination are not of the same dimensions, but how to I solve that issue? Does the "m" workspace need to be expanded or shortened, and how do I tell which needs to be adjust? What code should I use to solve this error?
  3 Comments
Walter Roberson
Walter Roberson on 11 Oct 2015
At the MATLAB command prompt, command
dbstop if error
and then run the command again. When it stops at that line 91, please examine the values of m and of sd . I predict that at least one of the two is NaN . That could happen if it believes that the dat is all NaN.
Morgan Gianola
Morgan Gianola on 12 Oct 2015
Lines 48-50 of the code are below. it looks like both show up as NaN. Then the error line (91) is below those.
dat = remove_empty(dat);
sd = nanstd(dat.dat(:));
m = nanmean(dat.dat(:));
set(gca, 'XLim', XLim);

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 9 Oct 2015
What data are you passing in to the routine? What is its size() ?
At the MATLAB command prompt, command
dbstop if error
and run the program. When it stops because of the error, please show size(masked_obj.dat)
  4 Comments
Morgan Gianola
Morgan Gianola on 10 Oct 2015
I think I see the mismatch, as one came out 29 while the other was 30. Do I need to add a column to one of the data files?
K>> size(values)
ans =
30 3
K>> size(nanmean(masked_obj.dat,1)')
ans =
29 1
K>> i
i =
1
Walter Roberson
Walter Roberson on 11 Oct 2015
Looking through the code, it appears that it may have something to do with there being a row (or column) of the data that is either all 0 or all NaN. As I have not seen the program before it is a bit difficult to trace what is going on without access to sample data to test with.
It looks to me as if masked_obj might have a field named hist that might give some clues. Please show
masked_obj.hist
In the code, values is being initialized to the original size of the data; and nanmean() does not drop entries that happen to be all nan (you get NaN as the output), so it must be the case that apply_mask is returning smaller than the original.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!