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
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.
回答(2 个)
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;
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))
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!