MATLAB: Perform calculation using for loop

array operationequationfor loopfor loop instead of array operation

So I have to use a for loop because I'm a student and the teacher said so. I've been trying to figure this one out and I'm sure theres a simple solution but because we are using matlab there aren't a whole lot of tutorials on using for loops when array operations are so much better.
I need to calculate the specific humidity using a for loop.
The equation is: q = (E*e)/P
where E = 0.622, e is a 96×144 matrix and, P represents p1 in my code which is another 96×144 matrix
I've coded something but I feel like the for loop is too simple.
Also the for loop and array operation return different values…is this normal?
% use for loop to calculate specific humidity
for q = 1:numel(p1)
q_for = (0.622.*e)./(p1(q));
end
% calculate specific humidity using array operations
q_array = (0.622.*e)./p1;

Best Answer

Ok I had to do a double for loop to make it work because I was dealing with a matrix so I ended up writing this code to solve my problem:
for q = 1:length(p1)
for p = 1:min(size(p1))
q_for(p,q) = (0.622.*e(p,q))./(p1(p,q));
end
end
The array operation was simple:
q_array = (e.*0.622)./p1;