【发布时间】:2019-02-17 06:31:56
【问题描述】:
我有一个 data file,它有 3 列,第一列是数据的字段,或者你可以说不同的索引。第 2 列是 x 轴数据,第 3 列是 y 轴数据。现在我有不同变量的类似数据文件,比如 8 个文件。我想在 MATLAB 中将所有图形绘制在一个图中。对于我的问题,我只显示一个子图。该子图数据文件应为 5 个索引(第一列)绘制 5 个“线图”。但是当我将它绘制为子图时,它只显示 1 个图。这是我在下面的代码:
% open Zdiff Odd Mode data file
fid = fopen('Data_test.txt');
% Read data in from csv file
readData = textscan(fid,'%f %f %f','Headerlines',1,'Delimiter',',');
fclose(fid);
% Extract data from readData
index_Data = readData{1,1}(:,1);
% Identify the unique indices
uni_idx=unique(index_Data);
xData = readData{1,2}(:,1);
yData = readData{1,3}(:,1);
% Plot Data
f = figure;
%Top Title for all the subplots
p = uipanel('Parent',f,'BorderType','none');
p.Title = 'Electrical Characteristics';
p.TitlePosition = 'centertop';
p.FontSize = 14;
p.FontWeight = 'bold';
cla; hold on; grid on, box on;
ax1 = subplot(2,4,1,'Parent',p);
% Loop over the indices to plot the corresponding data
for i=1:length(uni_idx)
idx=find(index_Data == uni_idx(i));
plot(xData(idx,1),yData(idx,1))
end
当我将数据绘制成一个完整的图形时,该图是完美的。但是由于我有很多数据要绘制在一个图中作为子图,我需要知道我的子图代码中有什么问题。
这是我没有子图的整个数据图的代码
在绘制代码之前和之前一样:
% Plot Data
f1 = figure(1);
cla; hold on; grid on;
% Loop over the indices to plot the corresponding data
for i=1:length(uni_idx)
idx=find(index_Data == uni_idx(i));
plot(xData(idx,1),yData(idx,1))
end
我在子图中的绘图代码有什么问题?谁能帮帮我?
【问题讨论】:
-
你需要在每个子情节中坚持,而不是之前。只有这样才能选择轴
-
@AnderBiguri 非常感谢....真是个愚蠢的错误!
标签: matlab plot graph matlab-figure subplot