我试图遍历一些日志空间来计算Z值并创建等高线图。但我被卡住了。如何创建轮廓图现在我有Z值?我怎样才能设置我的Z变量?我对Z的计算是基于图像而我不能以其他方式进行。
X = logspace(-10,0,10);
Y = logspace(-10,0,10);
for x = X
for y = Y
% here should some magic happen... but you have to assign real positive integers as indices for z
z(x, y) = 1; % some other heavy calculation
end
end
% what should I do here?
contourf(x, y, z); % does not work unfortunately
答案 0 :(得分:2)
这有用吗?
X = logspace(-10,0,10);
Y = logspace(-10,0,10);
for x = 1:numel(X)
for y = 1:numel(Y)
%// Note the reversed y,x - this is because the x-axis in an image / chart is usually mapped to the horizontal axis which is the columns whereas matrix representations would have dimension one as the rows. Hence you need to put x in dimension 2 and y in dimension 1
z(y,x) = 1; %// i.e. z(y,x) = f(X(x), Y(y))
end
end
contourf(X, Y, z);