MATLAB: MATLAB syntax (parantheses without intermediate steps)

indexingMATLABparenthesessyntax

Why is following intermediate calculation step necessary?
temp = abs(rand(10)-eye(10));
result = mean(temp(:));
In Octave is it possible to write the same on one single line:
result = mean(abs(rand(10)-eye(10))(:));

Best Answer

Because to date TMW has chosen to not implement post-addressing expressions on results.
"WHY?" you'd have to ask TMW and it's unlikely they will discuss such internals design decisions/plans publicly.
You can write the expression on one line in MATLAB, too, just more explicitly...
result = mean(mean(abs(rand(10)-eye(10)))); % is one common idiom for 2D arrays
or
result = mean(reshape(abs(rand(10)-eye(10))),:,1); % is generic