You just use the * operator, as you might expect, e.g.
y = x * k;
where x is the input image, k is a scalar value, and y is the resulting scaled image.
Answer from Paul R on Stack OverflowIn exactly the same way as on the left hand side:
testmatrix(testmatrix<10) = testmatrix(testmatrix<10)*2
Or as Amro points out, you can save on computations by creating a reusable logical indexing mask:
idx = testmatrix < 10
testmatrix(idx) = testmatrix(idx)*2
This second approach is particularly useful in more cases with more complex conditions or where the condition is repeated many times or when speed is a major concern
What you need is:
testmatrix(testmatrix < 10) = testmatrix(testmatrix < 10)*2;
You want to use element-wise multiplication (.*) because you still want to treat a and b as scalars (i.e. use each element individually).
You can make a 3D output, where each 2D slice corresponds to your meshgrid output, with one slice per component of U and V. Therefore in this example getting a 10*11*3 matrix.
To do this, just reshape the U and V vectors to be 1*1*3 in size
U = reshape( [1,1,0], 1, 1, [] ); % Or equivalently U(1,1,:) = [1,1,0]
V = reshape( [1,0,1], 1, 1, [] ); % Or equivalently U(1,1,:) = [1,0,1]
Then do element-wise multiplication
s = a.*U + b.*V;
Note: before MATLAB R2016b (when implicit expansion was introduced) you'll have to use bsxfun to get the equivalent:
s = bsxfun( @times, a, U ) + bsxfun( @times, b, V );
You can then plot the ith element of S changing with A and B by plotting s(:,:,i).
You could do it using a 3D matrix:
[A,B] = meshgrid(0:10,1:10);
U(1,1,:) = [1,1,0];
V(1,1,:) = [1,0,1];
s = A.*U + B.*V;
% s is now a NxMx3 matrix, where N = length(A) and M = length(B)
% We can plot how s varies with a and b as follows
surf(A,B,s(:,:,1)); % first component
surf(A,B,s(:,:,2)); % second component
surf(A,B,s(:,:,3)); % third component