Problem 105. How to find the position of an element in a vector without using the find function
Solution Stats
Problem Comments
-
8 Comments
not set up right - only one input provided
Ditto Will's comment
Please corect it or remove it.
Acting as an Admin, I tried to clean up the problem. I am rescoring, but naturally some of the "correct" answers will now fail.
Lots of "solutions" use the find function. I don't get it - what's the point of doing the problem if you ignore the key instruction?
May you please add this (or something similar) to the test suite:
% Test for find usage
fid = fopen(which('test'), 'r');
c = onCleanup(@()fclose(fid));
tline = fgetl(fid);
while ischar(tline),
if strfind(tline,'find'),
error('Don''t use find');
end
tline = fgetl(fid);
end
This should work fine after you've renamed your function.
there should be more test suite. such as x =[1 2 3;4 5 6;7 8 9];y =5;then the output is [2,2]; x = [1 2 2 3]; y =2;then the output is [2;2];
The test suite needs to be very restrictive here, the amount of trivial solutions is alarming. Yan
Solution Comments
-
1 Comment
This user (mohamed elbesealy) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
-
1 Comment
No, this solution is not expected.
"without using the find function"
-
1 Comment
The idea to write a code without using the predefined function is a bit weird. So my solution is deliberately cheating.
-
1 Comment
Could you explain to me what's the function of '@' in your solution ?
-
1 Comment
It is funny that this
feval(@eval, '[~, ans] = max(x==y);')
has smaller size than this
[~, ans] = max(x==y);
-
1 Comment
...I cheated to find out if you really were checking the conditions. Which you aren't. Shame.
-
1 Comment
I know, I know, sorry about this...
-
1 Comment
cheater
-
1 Comment
What about the detail "without using the find function"?!
-
1 Comment
how does this solve the problem? assert(strfind~=find)=false.
-
2 Comments
-
1 Comment
What about the detail "without using the find function"?!
-
1 Comment
What about the detail "without using the find function"?!
-
1 Comment
What about the detail "without using the find function"?!
Problem Recent Solvers2573
Suggested Problems
-
6498 Solvers
-
Arrange Vector in descending order
6861 Solvers
-
955 Solvers
-
Sum the 'edge' values of a matrix
289 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
1121 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!