I am not sure why i can't do this. Why cant I declare a variable outside a function before it gets used. I get error an error saying temp is an undefined function or variable. I realize I can pass the variable into the function thisblah(temp) but that is not what I want to do. The below is a shortened/redacted version of what I want to do. I am trying to add functionality in an existing function and want to know how many times I enter. Also I know you can solve calling the temp variable persistent inside the function but I dont think that is right answer. Global doesnt work either.
temp = 0;
for i = 1:5
thisblah
end
function thisblah
temp = temp + 1;
if temp(3)
fprintf('yes a three');
end
fprintf('temp is %d, temp);
end
tempeitherpersistentorglobal(which should work, you've given no details why it doesn't for you), but I think you should understand the basics around scoping first