在matlab中基于数据绘制矩形
我有一行数据如下:在matlab中基于数据绘制矩形,matlab,text,label,rectangles,Matlab,Text,Label,Rectangles,我有一行数据如下: 0 -> 2 DATA 1.000000 - 1.000100 SUCCESS 1.000100 - 1.000200 FAIL 我想按如下方式绘制数据: 我想我可以使用矩形,但它不显示x轴的时间?如何解决这个问题 如果成功,它将填充蓝色,否则将填充红色。您应该使用fill命令而不是rectangle命令。请参阅下面的代码以开始。若要根据您的喜好进行调整,只需参考MatLab中有关我正在使用的函数的帮助文件 祝你好运,玩得开心 clear all clc clos
0 -> 2 DATA 1.000000 - 1.000100 SUCCESS 1.000100 - 1.000200 FAIL
我想按如下方式绘制数据:
我想我可以使用矩形,但它不显示x轴的时间?如何解决这个问题
如果成功,它将填充蓝色,否则将填充红色。您应该使用fill命令而不是rectangle命令。请参阅下面的代码以开始。若要根据您的喜好进行调整,只需参考MatLab中有关我正在使用的函数的帮助文件 祝你好运,玩得开心
clear all
clc
close all
% Declare input string
input_str = '0 -> 2 DATA 1.000000 - 1.000100 SUCCESS 1.000100 - 1.000200 FAIL';
% Analyse string by using textscan, the columns of your data is stored in
% cells C{n}, where n denotes the column
C = textscan(input_str,'%d -> %d DATA %f - %f %s %f - %f %s');
% Declare data labels
data_label = cell(length(C{1}),1);
for ii=1:length(C{1})
data_label = ['DATA ',num2str(C{1}(ii)),'->',num2str(C{2}(ii))];
end
% Draw the rectangle, first define a rectangle height
r_height = 0.00002;
figure(1)
% Plot all elements in same figure and save all elements plotted
hold on
% Show the grid
grid on
for ii=1:length(C{1})
% Rectangle 1
% Declare vertices
xs=[C{3}(ii) C{4}(ii) C{4}(ii) C{3}(ii)];
ys=[0 0 r_height r_height];
% Determine color
if(strcmp(C{5}(ii),'FAIL'))
rgb_color = [1 0 0]; % Red
else
rgb_color = [0 0 1]; % Blue
end
% Plot rectangle
fill(xs,ys,rgb_color)
% Rectangle 2
% Declare vertices
xs=[C{6}(ii) C{7}(ii) C{7}(ii) C{6}(ii)];
ys=[0 0 r_height r_height];
% Determine color
if(strcmp(C{8}(ii),'FAIL'))
rgb_color = [1 0 0]; % Red
else
rgb_color = [0 0 1]; % Blue
end
% Plot rectangle
fill(xs,ys,rgb_color)
% Force to use the same axis scale:
axis equal;
% Set the limits
% Create offset value
offsetval = 0.1*(C{7}(ii)-C{3}(ii));
% Set x limites
xlim([C{3}(ii)-offsetval C{7}(ii)+offsetval])
% Finally plot the labels
text(C{3}(ii),r_height/2,data_label,'Color',[1 1 1])
text(C{6}(ii),r_height/2,data_label,'Color',[1 1 1])
end
数据是否在.txt文件中?您可以在轴打开时打开轴。