a = 10:100
b = 10:100
c = power(a,b)
surf(a,b,c)
=>使用冲浪时出错(第78行) Z必须是矩阵,而不是标量或向量
任何线索?
答案 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)
答案 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)