Using count with negatives
5 ビュー (過去 30 日間)
古いコメントを表示
I've written a code (as below), and now i'm trying to count the values of S_coeff_fact, however it won't work for the negative numbers?! I don't know why as ive never had this problem before.
function [S, R] = poly_fact(P, Q)
sizeP = size(P); rowsP = sizeP(2);
sizeQ = size(Q); rowsQ = sizeQ(2);
diff_in_length = rowsP - rowsQ;
i = diff_in_length+1;
count = 0;
while i>0
i = i-1;
count = count+1;
zero_input = zeros(1,diff_in_length);
Q = [Q zero_input];
S_coeff_fact = P(1, 1)/Q(1,1);
Q = Q*S_coeff_fact
P = P - Q
P = P(find(P ~= 0)); % Removing zeros from P.
Q = Q(find(Q ~= 0)); % Removing zeros from Q.
sizeP = size(P); rowsP = sizeP(2);
sizeQ = size(Q); rowsQ = sizeQ(2);
diff_in_length = rowsP - rowsQ;
S(count) = count(S_coeff_fact)
end
S = S
R = P
end
2 件のコメント
Image Analyst
2013 年 4 月 10 日
What does " count the values of S_coeff_fact" mean? Do you mean length(S_coeff_fact), or sum(S_coeff_fact)??? Can you put some comments in to explain the code (actually that might help you realize a logic error)? Can you supply some small sample arrays for P and Q so we can try it?
回答 (1 件)
Jan
2013 年 4 月 10 日
Your variable count is a scalar, such that indexing it with count(S_coeff_fact) must fail for anything but S_coeff_fact == 1. Therefore I claim, that this code did not work properly ever.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!