Assigning variable for a certain output.

function toss = coinToss
coin = randi([0:1], [1,1]);
disp(coin)
end
I have this function that will dispay either one or zero when I run it.
For 1 I want the variable to be h and for 0 I want the variable to be t. How can I do this? I tried to do if and elseif statements inside the function already but it didnt work.

댓글 수: 2

Geoff Hayes
Geoff Hayes 2020년 3월 24일
Lauren - do you mean that you want to return an 'h' or a 't' (head or tail) if the coin is a 0 or 1 respectively? Since this is homework, how did you write the if/else statement (you don't need an elseif)?
Lauren Fennelly
Lauren Fennelly 2020년 3월 24일
I actually figured it out! Thanks for the reply though.

답변 (0개)

이 질문은 마감되었습니다.

제품

릴리스

R2019b

태그

질문:

2020년 3월 24일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by