MATLAB: Error in code for windowing

Hi i wrote a code in which i applied a linear equation ax+b=0 to a image that is in format DCM. I think my code is fine, just at the end of the code i have "Array indices must be positive integers or logical values.
Error in windowin (line 38) transimage(i,j)=line(rho);"
can someone tell me why?
i attach the code..

Best Answer

rho = img(i,j) can be 0 or even negative. Your variable line is an array. So line(rho) is asking to index line at that location. But you cannot index at negative or 0.
Note: your DCM file appears to be a DICOM file. You should use dicomred() instead of the code you are using.