a function problem about output number

Hi guys,
Why I can not get 2 answers for value 1 and 2 the output is only first entriy;
function [num11,num22] = tekcift(num1,num2)
if mod(num1,2)==0
num11=num1^2;
elseif mod(num1,2)==1
num11=num1^3;
else
end
if mod(num2,2)==0
num22=num2^2;
elseif mod(num2,2)==1
num22=num2^3;
else
end
end

回答 (1 件)

Stephen23
Stephen23 2020 年 4 月 23 日
編集済み: Stephen23 2020 年 4 月 23 日

0 投票

You need to call the function with two outputs, e.g.:
[N1,N2] = tekcift(... whatever inputs you use...)
Very basic MATLAB concepts, such as how to call functions with multiple output arguments, are explained in the introductory tutorials:
If the function is only intended to work on integer values, then elseif can be replaced with else:
if mod(num1,2)
num11 = num1^3;
else
num11 = num1^2;
end
Or without if:
num11 = num1.^(2+mod(num1,2));

2 件のコメント

Levent Sakin
Levent Sakin 2020 年 4 月 23 日
okkay thanks but ı have replaced my lines with your tips but ı am getting only one output still that is N1 ?
Stephen23
Stephen23 2020 年 4 月 23 日
It works when I call your function:
>> [N1,N2] = tekcift(1,2)
N1 = 1
N2 = 4
Unfortunately my magic crystal ball is at the workshop today getting fixed, so we will have to rely on you actually showing me exactly how you are calling the function.

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

カテゴリ

ヘルプ センター および File ExchangeEncryption / Cryptography についてさらに検索

タグ

質問済み:

2020 年 4 月 23 日

コメント済み:

2020 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by