2014-07-10 37 views
0

我被认为是MATLAB的初学者。 我需要找到一些图形的FWHM,这些图形在峰值时相当嘈杂且不一致。 下面是我的基本代码,在一些来自stackoverflow用户的代码的帮助下。如何找到噪声图的平均值以获得FWHM?

DD11=dicomrt_read3ddose(1,'waterphantom50x1mm15x1cmslabs500Mill_2.5cmFS_20cmx20cmDE.3ddose'); 
%plot first function 
a=squeeze(DD11(100,:,55)); 
figure; 
plot(a); 
hold on; 
%find half of maximum value 
max(a); 
halfAmax=0.5*(max(a)); 
%plot straight line across the first function 
x2=[1:1:200]; 
LineValue=halfAmax; 
plot(x2,LineValue); 


%Find the starting indices of those segments of consecutive points that exceed LineValue 
idx = find(diff(a >= LineValue)) 
hold on; 
x3 = x2(idx) + (LineValue - a(idx)) .* (x2(idx+1) - x2(idx)) ./ (a(idx+1) - a(idx)) 
plot(x3, LineValue, 'go', [x2(1) x2(end)], LineValue*[1 1], 'k:'); 

%distance of the two points 
fwhmwidth=[x3(end)-x3(1)].*0.1 

hold on; 

%plot first function 
b=squeeze(DD11(100,:,7)); 
plot(b); 
hold on; 
%find half of maximum value 
max(b); 
halfAmax=0.5*(max(b)); 
%plot straight line across the first function 
x2=[1:1:200]; 
LineValue=halfAmax; 
plot(x2,LineValue); 


%Find the starting indices of those segments of consecutive points that exceed LineValue 
idx = find(diff(b >= LineValue)) 
hold on; 
x3 = x2(idx) + (LineValue - b(idx)) .* (x2(idx+1) - x2(idx)) ./ (b(idx+1) - b(idx)) 
plot(x3, LineValue, 'go', [x2(1) x2(end)], LineValue*[1 1], 'k:'); 

%distance of the two points 
fwhmwidth=[x3(end)-x3(1)].*0.1 

我希望那个; (1)我可以找到这些峰值的平均值,因为它们很嘈杂 (2)我可以更好地解释我上面的代码,如下所示;

%Find the starting indices of those segments of consecutive points that exceed LineValue 
    idx = find(diff(b >= LineValue)) 
    hold on; 
    x3 = x2(idx) + (LineValue - b(idx)) .* (x2(idx+1) - x2(idx)) ./ (b(idx+1) - b(idx)) 
    plot(x3, LineValue, 'go', [x2(1) x2(end)], LineValue*[1 1], 'k:'); 

非常感谢。

回答

0

应答(2):

%Find the starting...是解说。在Matlab中,它们由%开始。

idx = find(diff(b >= LineValue))定位数组diff(b >= LineValue)的所有非零元素,并返回矢量idx中那些元素的线性索引。在这种情况下,它只会返回第一个非零元素。检查Find

hold on指的是情节。你已经有了一个阴谋,通过使用hold on,你将会在同一个阴谋中增加更多的曲线。

x3 = x2(idx) + (LineValue - a(idx)) .* (x2(idx+1) - x2(idx)) ./正在用数字和矩阵执行操作。 c = a .* b将元素ab乘以元素并将结果返回c。输入a和b必须具有相同的大小,除非其中一个是标量。您可以通过点击F1来查看Matlab帮助。

plot(x3, LineValue, 'go', [x2(1) x2(end)], LineValue*[1 1], 'k:')绘制2条不同的曲线。第一项包含x轴值,第二项包含y轴值,第三项包含LineStyle,Color和Marker的信息。在这种情况下,'go' =绿色圆圈,'k:' =黑色圆点。查看Matlab's plot documentation了解更多信息。

希望可以帮到