Borrar filtros
Borrar filtros

Why am I getting "Too many output arguments"?

5 visualizaciones (últimos 30 días)
gm76
gm76 el 10 de Mzo. de 2013
I am trying to run this function with a 3x3 input matrix, and I am getting the "Too many output arguments" error using row_sums.
Here is the code for my main function:
function ms_equal_col_row_diag_sums(square_matrix)
N=length(square_matrix);
magic_sum =(N*(N^2+1))/2;
row_sum=row_sums(square_matrix);
column_sum=column_sums(square_matrix);
ll_ur_diagonol=ll_ur_diagsum(square_matrix);
ul_lr_diagonal=ul_lr_diagsum(square_matrix);
if row_sum(1,:)==column_sum(1,:)==N*magic_sum & ll_ur_diagonol==ul_lr_diagonal==magic_sum
disp(1)
else disp(0)
end
end
This is the code for row_sums:
function row_sums(square_matrix)
sum(square_matrix')
end
row_sums works if I use it individually with the same input. Ex. row_sums([2 7 6; 9 5 1; 4 3 8])=[15 15 15]
Thanks!

Respuestas (1)

Cedric
Cedric el 10 de Mzo. de 2013
Editada: Cedric el 10 de Mzo. de 2013
Actually row_sums doesn't work as it outputs nothing. However, you have the impression that it works because it displays the output of sum(square_matrix') as the line doesn't end with a ; . For solving this issue specifically, you need to define an output argument:
function s = row_sums(square_matrix)
s = sum(square_matrix') ;
end
Note that SUM can take an optional argument that defines the dimension (1 by default, but you could specify 2).

Categorías

Más información sobre MATLAB Mobile Fundamentals en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by