MATLAB: Matlab wont plot anything

MATLABplotting

I have read several people asking about why their matlab wont plot anything. I still can't figure out why mine wont plot. This is my code
>> close all
>> n=1:25;
>> R(n) = -80;
>> while n<26
R(n+ 1) = -0.8*R(n);
end
plot(n,R(n))
once I type end and press enter, the hashmark showing exactly where you are typing disappears and stops blinking so I feel like my plotting isn't going through. I don't know if that has anything to do with it. Another thing I notice is that why it shows >> for previous statements and once I enter the while n<26 line, it doesn't give me anymore >> lines. I am very inexperienced with Matlab, any help is highly appreciated. I've read figure() helps some people, where exactly in my code am I supposed to type this?
Also, when I close my matlab it says "an operation is in progress….." I don't know if this matters.

Best Answer

You have
n=1:25
while n<26
R(n+ 1) = -0.8*R(n);
end
After the first statement, n is a vector of 25 values. The n<26 in the next line is then comparing that vector of 25 values to the value 26. It happens that all of them are less than 26 so the result of the < is a vector of 25 "true" (1) values. When you use "if" or "while" with a vector or array of values, "if" or "while" consider the condition to be true if all of the values are non-zero, which they are in this case (being all true which is 1). So the test in the while is satisfied and the loop body is entered.
In the first execution of the loop body, since n is 1:25, you are doing the equivalent of
R((1:25)+1) = 0.8*R(1:25)
which is
R(2:26) = 0.8*R(1:25)
you have 25 values on the right side and 25 output locations on the left, so the assignment is well defined. This will extend R (which you defined as length 25) to being length 26. This will not change n in any way.
You then reach the end of the while loop, and you go back up to the test while n<26. n has not changed at all, so the test is still true, and R(2:26) = 0.8*R(1:25) is done again. And then it loops back and n has not changed so n<26 is still completely true and R(2:26) = 0.8*R(1:25) is done again, and so on. n never changes so n<26 never changes and the loop never ends. You never get back the >> prompt because the "while" is still executing.
You should be using a for loop:
R = zeros(1,26);
R(1) = -80;
for n = 1 : 25
R(n+ 1) = -0.8*R(n);
end