How to find highest and lowest numbers in vector without using build in functions?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a task to find highest and lowest numbers in vectros using while and if
Any help would mean a lot to me since I'm only a begginer and have no Idea how to do this
댓글 수: 0
채택된 답변
Walter Roberson
2021년 4월 10일
That cannot be done. See https://www.mathworks.com/matlabcentral/answers/38787-what-can-be-programmed-without-any-built-in-functions?s_tid=srchtitle
Both while and if are keywords rather than functions, so saying that those are permitted to be used does not alter what can be done without functions.
In short: in order to compare numbers to each other you have to do a computation (checking to see if they are equal, at the very least), and all computation involving two numbers in MATLAB involves using built-in functions, but you are not permitted to use built-in functions.
Example:
A = 3; %does not involve any functions
if A == 1 %involves the function eq()
elseif A < 3 %involves the function le()
end
So you cannot compare x(1) to x(2) without using a comparison and that involves using a built-in function.
There are computer languages where comparisons and very simple indexing are both built-in operators, and with those languages it is technically possible to sort a fixed-length vector without using any built-in functions... but it might be very tedious. And those languages are not MATLAB.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!