【发布时间】:2017-01-24 08:53:17
【问题描述】:
我有以下代码用于定位一些子图:
fig = figure;
fig.Units = 'centimeters';
fig.Position(3:4) = [25 25];
plotPositions = [ 3, 21, 7, 7;
12, 21, 7, 7;
];
nPlots=length(plotPositions); % shorthand variable for convenience
hAx=zeros(nPlots,1); % preallocate array for axes/subplot handles
for i = 1:length(plotPositions)
plotHandle = subplot(3, 2, i);
plotHandle.Units = 'centimeters';
plotHandle.Position = plotPositions(i,:);
hAx(i)=subplot(3, 2, i);
axis(hAx(i),[ -300 300 0 150]); %
end
如果我使用
plotPositions = [ 3, 21, 7, 7;
12, 21, 7, 7;
3, 12, 7, 7;
12, 12, 7, 7;
3, 3, 7, 7;
12, 3, 7, 7];
它有效,但如果使用
plotPositions = [ 3, 21, 7, 7;
12, 21, 7, 7;
];
它不起作用,我收到错误消息:
Matrix dimensions must agree.
Index exceeds matrix dimensions.
发生了什么事?
【问题讨论】:
标签: matlab matrix indexing plot matlab-figure