I have been on a few forum posts now reading through trying to figure this out but I can’t seem to crack it. To summarise my function I have 2 arrays searchDates and searchIds. Now all I want to do is do a comparison on the size of one of the elements to the other array and this is the code I have so far but I don’t know how to carry over searchDates and searchIds
function a = compare(userNum)
if size(searchDates{1,userNum},2) == size(searchIds{1,userNum},2)
x = true
else x = false
end
TL;DR I just need to know how to pass from my BASE WORKSPACE to my FUNCTION WORKSPACE the two arrays from above.
Cheers!
You can rewrite your function so that you can directly pass the arrays:
then call compare with your workspace variables in the 2nd and 3rd argument.
If for some reason you need compare to only have one argument, you can create an anonymous function in your workspace by using the above function compare and writing:
Provided searchDAtes and searchIds are in your workspace, you will now have the function anon_compare, which you can use directly as
anon_compare(foo).For more on anonymous functions (an important aspect of several MATLAB programming techniques) you can read this post.