Stumped on matlab function

Write a function called maxsubsum that takes a matrix A as an input, computes the sum of elements in each of its submatrices, and finds the submatrix that has the maximum sum. (For the purposes of this exercise, we define a submatrix as a matrix formed by a contiguous set of elements of the original matrix.) If there are more than one with the same maximum sum, the function can pick any one of them. Note that the entire matrix is considered to be a submatrix of itself, but because some elements of the matrix may be negative, it may not have the maximum sum. The function is defined like this:
function [row,col,numrows,numcols,summa] = maxsubsum(A)
where row and col specify the indexes of the top left corner of the submatrix with the maximum sum, numrows and numcols are its dimensions, and summa is the sum of its elements.
My attempt:
function [ row,col,numrow,numcol,summa ] = maxsubsum( a )
n=0;
e=max(sum(a(:,:,:)));
f=max(e);
while (e<f)
n=n+1; %to get the position of the max sum among the other individual max sums
end
g=n;
b=a(:,:,n);
c=size(b);
numrow=c(1);
numcol=c(2);
summa=sum(b);
end

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by