how can I have a single number as the result of dividing two numbers?

2 次查看(过去 30 天)
I am implementing this formula in MATLAB:
I[i], is the intensity of my signal and i is the index for each row. My code is as follow:
I attached my signal to this message.
Based on the formula, each time for specific i, I should have a number and then put it in the ith u. but in my code the result of the division is a matrix each time(xc(:,i)./diff((accum))) and I have no idea how to fix it.
M1=length(xc);
accum1=zeros(M1,1);
accum=zeros(M1+1,1);
a=zeros(1,N);
N=200;
for i=1:N
for j=i:N
accum1=accum1+(xc(:,j));
end
accum(1:M1) = accum1;
a(1,i)=xc(:,i)./(2*diff((accum)));
accum1=zeros(M1,1);
accum=zeros(M1+1,1);
end
  2 个评论
Chunru
Chunru 2022-8-23
Can you explain the meaning of Δ in your formula?
It seems that the use of "diff" to accum produces a vector rather than a scalar.
2NOR_Kh
2NOR_Kh 2022-8-23
编辑:2NOR_Kh 2022-8-23
this is the definition:
"measurements of I[i] are given by the integrated signal over a small distance, defined by the pixel size Δ and commonly related to the coherence length of the light source"
so I get that "small distance" or saying Δ as diiferentiate function.
But, now that I am thinking, my implementation is not correct. It is saying that delta or Δ is the pixel size, I am not working with pixels but does it mean that this delta is a constant?

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2022-8-23
编辑:Image Analyst 2022-8-23
Try this:
s = load('matlab.mat')
xc = s.xc;
[rows, columns] = size(xc)
subplot(2, 2, 1);
imshow(xc, []);
subplot(2, 2, 2);
hold on;
grid on;
for col = 1 : columns
plot(xc(:, col), '-', 'LineWidth', 1);
end
delta = 2; % Whatever it is....
% Compute u for each column.
sumi = cumsum(xc);
for col = 1 : columns
u = zeros(rows, 1);
% Reinitialize
for i = 1 : rows
% Compute sum from i+1 to the end
theSum = sumi(end, col) - sumi(i, col);
u(i) = xc(i) / (2 * delta * theSum);
end
subplot(2, 2, 3:4);
plot(u, '-')
hold on
end
grid on;
  1 个评论
2NOR_Kh
2NOR_Kh 2022-8-23
the results should be something like (b):
However, maybe somewhere I forgot something.
This formula and figure are from this refrence:
Depth-resolved model-based reconstruction of attenuation coefficients in optical coherence tomography

请先登录,再进行评论。


Chunru
Chunru 2022-8-23
编辑:Chunru 2022-8-23
load(websave("matalb.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1104765/matlab.mat"));
[M1, N] = size(xc);
delta = 1;
% The formula is not well defined for i=M1
% The summation in denominator can be computed using cumsum for efficiency
den = cumsum(flipud(xc(2:end, :)));
a = xc(1:M1-1, :)./(delta*den(end:-1:1, :));
plot(xc(:, 1)); hold on
plot(a(:, 1))

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by