필터 지우기
필터 지우기

Solving Equation for different matrix size

조회 수: 3 (최근 30일)
Preet Lal
Preet Lal 2021년 11월 15일
편집: Preet Lal 2021년 11월 16일
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
William Rose 2021년 11월 16일
편집: William Rose 2021년 11월 16일
You have not done what @dpb wisely suggested.
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.
Preet Lal
Preet Lal 2021년 11월 16일
편집: Preet Lal 2021년 11월 16일
Yes, there is dimension mis-match, I have to run a window on matrix as 15X15 for A and B, and C is main matrix of 200m and 45X45 of 200m for 9000m.
I have to fill the result of equation in Output NaN value.
If any data have NaN, it will go as NaN, No worries for that

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by