"My idea is to start of squaring the elements in x and then to check if any element in x equals any element in sqr." That's a good start.
Are all elements of the vector, x, whole numbers?
Steven hinted about ismember. Thus, look it up in the documentation. Type ismember in the command window, select it by double-clicking, right-click and chose "Help on Selection". Reading documentation is a large part of using Matlab.
"any element in x equals any element in sqr" That's what ismember does.
x = 2:12;
sqr = x.^2;
[ism,loc] = ismember( sqr, x );
if any( ism )
x(loc(ism))
else
disp('None found')
end
In the bottom of the documetation page of ismember you'll find See Also: ... intersect ... . It's documentation says: "C = intersect(A,B) returns the data common to both A and B, " Worth trying.
Best Answer