MATLAB: Function and mask : from vector to line

functionvector

Hello,
I have a function and when calling it with vectors, it changes the orientation from vectors to lines ; I do not understand why ?
Do you have explanations ? I'd like to understand instead of just transposing…
My function :
function ratio = ratiocu(teta,bbb,rrr)
G1 = 0.000382806d0;
G2 = 1.32407d0;
G3 = 0.00167634d0;
G4 = 0.789953d0;
RRRcal = max(0.d0,bbb.*rhoc0(273.15d0,rrr)./rhoc0(teta,rrr));
mask1 = (RRRcal > 1);
ratio(mask1) = G1.*(RRRcal(mask1).^G2)./(1+G3.*(RRRcal(mask1).^G4))+1;
mask2 = (RRRcal > 40000);
ratio(mask2) = NaN;
mask3 = ~(mask1 | mask2);
ratio(mask3) = 1.d0;
end
teta and bbb are two vectors of same length, rrr is a number.
rhoc0 is a function rendering a vector.
I think this is because of the use of mask1…as the function gives a vector if i remove it.
Cheers.
FP
PS : you can test it by yourself by using this one for instance ;
function ratio = ratiocu(teta,bbb,rrr)
G1 = 0.000382806d0;
G2 = 1.32407d0;
G3 = 0.00167634d0;
G4 = 0.789953d0;
RRRcal = teta;
mask1 = (RRRcal > 1);
ratio(mask1) = G1.*(RRRcal(mask1).^G2)./(1+G3.*(RRRcal(mask1).^G4))+1;
mask2 = (RRRcal > 40000);
ratio(mask2) = NaN;
mask3 = ~(mask1 | mask2);
ratio(mask3) = 1.d0;
end

Best Answer

Your question is very unclear. What does "changes the orientation from vectors to lines" mean? Do you mean that it changes the orientation from column vector to row vector?
Note that your code will always create a row vector, regardless of the shape of the inputs, because your create the output ratio with:
ratio(someindices) = something %ratio is created as it is indexed. matlab rules is it will be a row vector
If you want ratio to be the same shape as teta, then you need to create it before indexing into it:
ratio = zeros(size(teta));
ratio(mask1) = ...
While you're at it, you may want to ensure that your (badly named variables) bbb and teta have the same shape, as otherwise, you'll get different results in R2016b than in previous versions. The first line of the function should be:
assert(size(bbb) == size(teta), 'inputs do not have the same size or shape') %or similar check