index must be a positive integer or logical

1 次查看(过去 30 天)
I have this simple code I'm trying to run but I keep getting the error 'index must be a positive integer or logical.' Basically I'm attempting to make a 32x32 image of the f(x,y) bounded by x=0, x=2 and y=0, y=2
a=1;
b=1;
% dbstop if error
for x=0:.0645:2;
for y=0:.0645:2;
f(x,y)=1+sin(2*pi*(a.*x + b.*y));
end
end
imshow(f)

采纳的回答

Image Analyst
Image Analyst 2014-8-23
编辑:Image Analyst 2014-8-23
Indexes can't start at zero like it said, but like you tried to do. To fix it, if you want to use a for loop, do this:
a=1;
b=1;
% dbstop if error
x=0:.0645:2;
y=0:.0645:2;
for column = 1 : length(x)
for row = 1 : length(y)
f(row, column)=1+sin(2*pi*(a.*x(column) + b.*y(row)));
end
end
imshow(f, [], 'InitialMagnification', 600);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by