Any way to make this code take up even less lines?

clear;
close all;
clc;
iif = @(varargin) varargin{2 * find([varargin{1:2:end}], 1, 'first')}();
d = @(x)mod(x,2);
e = @(x)x/2;
o = @(x)(3*x+1);
r = @(x)iif(d(x)==0,true,d(x)==1,false);
members = 'Enter an integer: ';
members=input(members);
while members(end) > 1 % run the loop
members = [members,iif(r(members(end)),e(members(end)),true,o(members(end)))];
end
disp(['The sequence starting with ' num2str(members(1)) ' will have ' num2str(numel(members)-1) ' members.']);%output

답변 (1개)

Image Analyst
Image Analyst 2019년 1월 25일
You could combine 2 into 1:
members=input('Enter an integer ');
As someone whose programs typically are a few thousand lines long, I'm curious why shortening a 15 line long program is important to you.

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2019년 1월 24일

답변:

2019년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by