用MATLAB表面问题

时间:2015-02-17 14:21:38

标签: matlab

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

=>使用冲浪时出错(第78行) Z必须是矩阵,而不是标量或向量

任何线索?

2 个答案:

答案 0 :(得分:1)

不幸的是,

c=power(a,b)并没有为您提供所有a权力b的组合。

这里有一种方法(虽然很可能有一种矢量化的方式)

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

答案 1 :(得分:1)

这是使用bsxfun的矢量化方式:

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