Why am I getting "Too many output arguments"?
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (1 件)
Cedric
2013 年 3 月 10 日
編集済み: Cedric
2013 年 3 月 10 日
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).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で MATLAB Mobile Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!