Solving Equation for different matrix size
3 次查看(过去 30 天)
显示 更早的评论
Hello experts, I have an equation :
Output = A + B * {[C + D]} + 1.2*[C + D]}
I have attached mat file:
A if of 3000 m grid size
B is of 3000 m grid size
C is of 200 m grid size
D we have to compute from "C" 200 m to 9000 m grid size by averaging 45 pixel as mean.
%%Code for calculating D can be :
winSz = [45,45]; % window size [width (x), height (y)]
[m, n] = size(C);
winX0 = 1:winSz(1):n-winSz(1)+1; % starting index of x-values for each window
winY0 = 1:winSz(2):m-winSz(2)+1; % starting index of y-values for each window
%Loop through windows
D = NaN(numel(winY0),numel(winX0));
xWin = 0:winSz(1)-1;
yWin = 0:winSz(2)-1;
for i = 1:size(D,1)
for j = 1:size(D,2)
D(i,j) = nanmean(C(winY0(i)+yWin, winX0(j)+xWin),'all');
end
end
% I have to run window on 3000 km as base.
I want output in output matfile which is of 200m grid size.
Please suggest or help me in code.
6 个评论
William Rose
2021-11-16
编辑:William Rose
2021-11-16
Your equation for Output has mismatched {}. Fix. Clarify whether the multiplication in the equation for D is matrix multiplication or point-by-point multiplication. Neither form of multiplication will work, with the matrices you have provided, and the instructions for calculating D, because the dimensions are incompatible.
The .mat files you have supplied are A which is 29x19 with no NaNs, B which is 29x19 with 12 NaNs, C, which has a different name in the .mat file, and is 413x264 with about 35% NaNs, and Output, which is 413x264 and is 100% NaNs.
I infer that each matrix represents an image, and that the image pixel size is 200m x 200m for C, and 3000 m x 3000 m for A and B, and 9000 m x 9000 m for D. The dimensions of A, B, C, and Output do not quite match, if that is the case, but they are close. Your written instructions for D produce a matrix D: (9 or 10) x (5 or 6), depending on how you handle the edges. Either way you cannot add C + D because the dimensions don't match. And you can't multiply B by (C or D or C+D), because of dimension mismatch - whether you use matrix multiplication or point-by-point multiplication.
Please describe the propblem more clearly, and post supporting data that does not have NaNs, unless the NaNs are a necessary part of the problem. And get the dimensions to agree.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!