Weird output and calling to another function

I'm having weird issues with a weird output of ans = 1 from this code
function m = primefactors(m)
k=zeros(1,m);
x = 2;
while m>1
if mod (m,x) == 0
m=m/x;
k(end+1)=x;
else
x=x+1;
end
end
z=k(k~=0);
disp(z)
end
I'm then also trying to store those outputs into another function but i'm not sure how
function g = RSA(n,e)
[p,q] = primefactors(n);
disp(p)
disp(q)
end

4 件のコメント

darova
darova 2020 年 4 月 14 日
What is this?
Les Beckham
Les Beckham 2020 年 4 月 15 日
darova
It appears to be a tiny, tiny image that is impossible to read unless I zoom the entire web page to around 500%. :) Can you make it bigger?
James Tursa
James Tursa 2020 年 4 月 15 日
What do you mean by "storing p and q into another function"? Can you elaborate?
darova
darova 2020 年 4 月 15 日
Les Beckham, user right button mouse:

サインインしてコメントする。

 採用された回答

James Tursa
James Tursa 2020 年 4 月 15 日
編集済み: James Tursa 2020 年 4 月 15 日

0 投票

That's because you are returning m. I think you want to return z:
function z = primefactors(m)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePlatform and License についてさらに検索

質問済み:

2020 年 4 月 14 日

コメント済み:

2020 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by