Subscripted assignment dimension mismatch

I have the following algorithm and i keep getting an error, can anyone help?
for i = 1:nSlice
D1 = squeeze(IMs(:, :, i));
range = double(max(D1(:)));
norm_im = double(D1)/range;
level = graythresh(norm_im);
new_level = level*c_range;
BW = (D1>new_level);
IM_s(:,:,i) = BW(:); % error line
end

댓글 수: 1

Geoff
Geoff 2012년 4월 11일
Please edit your question and format the code as 'code' (highlight and press the 'code' button on the toolbar. Also, on which line does the error occur?

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

 채택된 답변

Geoff
Geoff 2012년 4월 11일

1 개 추천

When you reference BW(:), it turns your matrix into a vector. Just do this:
IM_s(:,:,i) = BW;
Assuming that IM_s(:,:,i) is actually the same dimension as IMs(:,:,i)...

댓글 수: 5

Mugo
Mugo 2012년 4월 11일
Thanks, it solved the error i was having but IMs and IM_s have different dimensions. So now i cant display IM_s like...
imagesc(IM_s(:,:,10));
Geoff
Geoff 2012년 4월 11일
Well, if it got rid of the error, then the first two dimensions of IM_s and IMs must surely be the same. When you say you "can't display" IM_s(:,:,10), what do you mean? Does it give you an error, or just a solid colour?
Mugo
Mugo 2012년 4월 11일
Oh my bad, they are the same dimensions but different sizes. size(IMs)= [512 512 34] and size(IM_s)=[2 2 34] so im getting a solid colour.
Geoff
Geoff 2012년 4월 11일
So, don't you want them to be the same dimension? I see you have accepted my answer, but have you resolved your problem?
Mugo
Mugo 2012년 4월 12일
Im happy with the solution to my initial error problem, but the dimension issue is a different thing im working on currently. I will post a new question if i cant figure it out. Thanks for your help...

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

추가 답변 (0개)

질문:

2012년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by