lola
lola

Reputation: 5789

issue with surface with MATLAB

a = 10:100
b = 10:100
c = power(a,b)
surf(a,b,c)

=> Error using surf (line 78) Z must be a matrix, not a scalar or vector

any clue ?

Upvotes: 0

Views: 268

Answers (2)

Ander Biguri
Ander Biguri

Reputation: 35525

c=power(a,b) does not give you the combinations of all a power b, unfortunately.

Here there is a way of doing it (though most likely there is a vectorizedd way of doing it)

a = 10:100;
b = linspace(1,10,length(a)); 
% I changed the values of b, because 100^100 is that a big number that Matlab will not plot it, it is too big for storing in a double

%loop and save
for ii=1:length(b)
   c(ii,:)=a.^(b(ii)); 
end

surf(a,b,c)

enter image description here

Upvotes: 1

Luis Mendo
Luis Mendo

Reputation: 112679

Here's a vectorized way using bsxfun:

a = 10:100;
b = 1:.1:10; %// changed b to avoid very large numbers
c = bsxfun(@power, a, b.');
surf(a,b,c)

Upvotes: 1

Related Questions