How to compare a series of 50 values to a single value for each sample in a plot?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to compare a set of 50 values to a single value for each sample on a plot.
For example, for sample S1, I have 50 values and I want to show these values as a vertical line and then show where a single other value stands compared to these 50 values for S1, then do the same for the rest of the samples. So I want my x-axis to be S1, S2, S3, etc...and my y-axis to show the 50 values and the single value on top of each other or overlapping (depending on what the numerical values are). For example, for sample 1, my Y-values are:[0.6875, 0.6978, 0.7171...up to 50 values] and my x is 0.9180. I checked the available plots and also the plot gallery but couldn't find exactly what I was looking for.
Hope this makes sense, and someone can help me to create this plot.
Thanks.
0 个评论
回答(2 个)
Star Strider
2017-7-14
I am not certain what you want.
See if this works for you:
y = sort(rand(50,5)); % Dependent Values
x = sort(rand(1,5)); % Independent Variable
v = rand(1,5); % ‘Single Value’ To Compare
figure(1)
plot(x, y, '.b') % Plot Data As Blue Dots
hold on
plot(x, v, 'sr', 'MarkerSize',10) % Plot Comparison Value As Red Squares
hold off
0 个评论
alice
2017-7-14
I don't know if you have your data in structure arrays, vectors or others, but is this example similar to what you want to achieve?
% fake data generation:
data = [];
for i = 1:7
data = [data,struct('Y',10*randi(10)*rand(50),'x',randi(15))];
end
% figure generation:
figure; hold on;
for i = 1:length(data)
plot(i*ones(50,1),data(i).Y);
plot(i,data(i).x,'d');
end
set(gca,'xtick',1:length(data),'xticklabel',strcat('S',num2str((1:length(data))')));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!