Another of the classic "check if MATLAB has a function that does this already" problems...
What about a vector like [2 3 1]? The top solution will still return true because 1^2 is still one but it is not the square of one of the OTHER numbers.
is the Str2func construct really more effective???
Is it possible that this distorts the metric a bit?
It is currently impossible to submit a solution for this problem. The web page will never load.
The problem description states that one of the numbers has to be a square of one of the OTHER numbers. Still, the test suite tests if  gives true. I think  should give false, or that describtion be modified.
Agree with Mattias. the length of input vector should be 2 or larger.
The difference between test 4 and 5 which returns different answers is the number 36.. but 36 is not a square root of any number of the list in test 4!!
Agree with Mattias: the Test Suite is defective, and not consistent with the problem specification.
Having an input of  is OK, but result should be false, as there is no OTHER element to compare the 1 to!
the word "other" should be ignored in the description...
The heading reads:
"...a square of one of the OTHER numbers...".
How can the function be expected to return [true] for a = ?
It makes no sense.
This problem is very good
空的 1×0 double 行向量
Tough one, but interesting
I solved it with 2 for-loops, 1 function, 1 if-condition.
It works, but there are more efficient ways apparently
Hey,the demand of this problem declare that "if one " and "the other",so if the intersect of x and x.^2 only have one value of 0 or 1,it may be return false because their squares are themselves, which is not satisfy the condition implied that c and c^2 is not one.
The question asks if one number is the square of one of the OTHER numbers. Test 3 should return false.
error in test 7 ! You missed 'd' in function.
Error has been fixed.
very challenging problem!!
I don't understand why #4 if false. Can someone help me?
Test case #4 is true, not false, because the vector contains a perfect square and its square root.
Your function is not passing because it overwrites the check variable for each vector element, only actually checking the last value to return the true/false variable. It happened to pass the other four cases because their answers (either false or true) happen to correlate with your check for the last (or only) element in the vector.
a = [20:30];
It should be true because in the array there is 25.
a = [20:30]
a = 20 21 22 23 24 25 26 27 28 29 30
The question asks that whether a perfect square and it's root both are present in the array or not. You have to check for both and not one only.
I verified this code with the given test suite. but the system is not accepting the code as it is.
What's wrong with this code? Runs perfectly on my computer.
I didn't see the leading code,so I put my code here to give some inspiration.
Looking forward to a shorter one
whoops, don't know how I managed to confuse .^ with .* for a bit there ---I was like, "What's WRONG?"
This type of cheat/hack answers are no longer allowed.
0 and 1 elements in a will show the bug in your code
a vector 'a' with elements 0 or 1 will show the bug in your code
Wow! This took me a couple of days to solve, but I did it and I’m very proud! :D
Hi. A vector with ones or zeroes as v = [3, 1] will show the bug in your code.
Test case : a = [20:30] contains a square. but its expected error is false. It should be fixed
where do you find a perfect square in [20:30]?
Hi Jann B,
25 is a perfect square, no?
How is the output true if the vector contains only one number? People posting such meaningless solutions: Please have some common sense!
a vector as v = [3,2,7,0,5] will show you your code's bug
a little smaller now
I want to make this code shorter!!
Case2,a = [20:30],fails.
in 2 test suite in a=[20:30] , contains 5^2 =25 so it has to be true not false
But there seems to be a better choice. Why forgetting ismember?
Test 2 in the test suite is wrong!
25 is clearly a perfect square.
the problem is to see if a number is the square of another number in the vector. Although 25 is a perfect square, 5 is not included in the vector
Though it passes the test suite, I feel like I could make this a better way but I am drawing a blank. Any feedback would be appreciated.
if a = [20:30] the output should be true as 25 is a perfect square, while in the test case output is given to be false.
25 is not a square of any other members of the group. If the group included 5 it would be true.
hur dur durrr durr. sqrt(25)==5, not included in givens
Yeah, I did it
My solution returns false for [20:30]; why not for [6 10 12 14 101]?
Instead of a(1):a(end) you should just write a.
Where did I do wrong？
The desired results are not the character strings 'true' and 'false' but the logical values true and false.
hint ; any and ismember.
submitted tested solution but still showing error......
L 17 (C 1-3): Parse error at END: usage might be invalid MATLAB syntax.
interesting solution... I like it :)
I disagree. Almost every problem has a solution wrapped in this function. It's cheating as it hides the complexity of the code from the scoring algorithm. That's why "eval" is not allowed ...
This is the correctly executing in matlab
I wonder...if you cheat, why even bother to actually solve the problem?
I have not heard of ismember before, thanks.
As primitive as my solutions are, I learn just as much from reading other peoples as doing the problem itself. Great setup mathworks :)
Code works on Matlab, but not on your test suite?
Srtr2func, classic way:)a new thing learned.
a = [20:30] 25 is in that array and is perfect square. Why should it return false?
because 5 isn't in the array. the perfect square and it's root should both be in the array.
test case 3 should be 'false'
it states 'one of the other' numbers, so for a =  it should be false
Assertion 2. is not correct. vector 'a' return with 6th element as 25 & thts a perfect square.. So it must be true!!
Deleting an element in a matrix
Flip the vector from right to left
Pernicious Anniversary Problem
Add offset to a signal
Given two arrays, find the maximum overlap
Select every other element of a vector
Make a Palindrome Number
Find the numeric mean of the prime numbers in a matrix.
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office