2010-12-21, 13:13
#1
Hej jag behöver hjälp med min matlabs uppgift.
Det är såhär att man skall
Mitt program ser ut såhär
function [D] = diagsum ( A )
A
B = A'
c = reshape(B,1,[])
Sajs = size( A );
for k = 1 : length( c )
l = 1;
f = 0;
if (k+Sajs(1,2) < length( c ))
while (l*(Sajs(1,2) < length ( c ))
f = f + c(1,k+(l*(Sajs(1,2)+1)));
l = l + 1;
end
a(1,k) = c(1,k) + f;
else
a(1,k) = c(1,k);
end
end
a
D = (reshape(a,Sajs(1,2),Sajs(1,1)))';
Fast ngt skiter sig på vägen... Är verkligen kass på matlab och behöver hjälp.
Ngn som vet vad som är fel?
Det är såhär att man skall
----------------------------------------------------------------------
Write a function that in a given matrix calculates the cumulative sums
in the matrix diagonals, starting from bottom right and advancing
against top left. For instance, the cumulative sum of the vector
[1 2 3 4] is, from right to left, [1+2+3+4 2+3+4 3+4 4] = [10 9 7 4].
Syntax: D = diagsum(A)
--------------
where A is a M-by-N matrix with numbers,
D is the M-by-N resulting matrix with the diagonal cumulative
sums.
Basic functionality:
>> A = [ 1 2
3 4 ];
>> B = diagsum(A)
B =
5 2
3 4
>> A = [ 1 2 3
4 5 6
7 8 9 ];
>> B = diagsum(A)
B =
15 8 3
12 14 6
7 8 9
Write a function that in a given matrix calculates the cumulative sums
in the matrix diagonals, starting from bottom right and advancing
against top left. For instance, the cumulative sum of the vector
[1 2 3 4] is, from right to left, [1+2+3+4 2+3+4 3+4 4] = [10 9 7 4].
Syntax: D = diagsum(A)
--------------
where A is a M-by-N matrix with numbers,
D is the M-by-N resulting matrix with the diagonal cumulative
sums.
Basic functionality:
>> A = [ 1 2
3 4 ];
>> B = diagsum(A)
B =
5 2
3 4
>> A = [ 1 2 3
4 5 6
7 8 9 ];
>> B = diagsum(A)
B =
15 8 3
12 14 6
7 8 9
Mitt program ser ut såhär
function [D] = diagsum ( A )
A
B = A'
c = reshape(B,1,[])
Sajs = size( A );
for k = 1 : length( c )
l = 1;
f = 0;
if (k+Sajs(1,2) < length( c ))
while (l*(Sajs(1,2) < length ( c ))
f = f + c(1,k+(l*(Sajs(1,2)+1)));
l = l + 1;
end
a(1,k) = c(1,k) + f;
else
a(1,k) = c(1,k);
end
end
a
D = (reshape(a,Sajs(1,2),Sajs(1,1)))';
Fast ngt skiter sig på vägen... Är verkligen kass på matlab och behöver hjälp.
Ngn som vet vad som är fel?