Error bars at intervals of data

조회 수: 51(최근 30일)
Matthew Hpa
Matthew Hpa 2016년 2월 29일
댓글: Abel Rangel Trejo 2021년 2월 18일
Hi everyone,
I have been trying to plot the error bars on a curve, however I have ~120,000 data points in each file so error bars on all curves gets too crowded on the graph. I was wondering if anyone could please help me out about how I would go about plotting the error bars at intervals of every 10,000 data points or so?
Here is my code so far:
clear all
% Loading the xlsx file
FILEPATH='/Volumes/Lexar/Final Project/Edited Folders/Compression Data/';
num1 = xlsread(strcat(FILEPATH,'Compress D50 1.xlsx'),1,'A:O');
% In num1 you only have those two columns, so for Load related data
% you need to use only the 2nd column (K)
Load1 = num1(:,11);
% For displacement you use the first column (J)
Displacement1m = num1(:,10);
A = 0.0004;
L = 0.02;
Stress1=Load1/A;
Strain1=Displacement1m/L;
% Plot the curves in one figure %
% Velocity 1 mm/s %
figure,plot(Strain1,Stress1);
xlabel('Strain','FontSize',14)
ylabel('Stress, N/m^2','FontSize',14)
% Ensure to change the title depending on the density %
title('Static Compression - Stress vs. Strain for Density 50 Silicon','FontSize',14);
hold on;
errStress = num1(:,13);
errStrain = num1(:,14);
eStress = std(Stress1)*ones(size(errStress));
eStrain = std(Strain1)*ones(size(errStrain));
errorbar(Strain1,Stress1,eStress);
hold on;
herrorbar(Strain1,Stress1,eStrain);
Many thanks for the help - it is really appreciated.

답변(1개)

Shivam Chaturvedi
Shivam Chaturvedi 2016년 3월 3일
Hi Matthew,
It doesn't look like there's a direct way to restrict the individual error bars from being created.
However, you can remove the error values from the other points i.e. make them zero so it doesn't come up as an error bar. It still might not look good, but you can give it a try.
I tried the following example to try this out and print every 3rd error bar on an example shown here:
% error bar demo
x = 0:pi/10:pi;
y = sin(x);
e = std(y)*ones(size(x)); % calculate the initial errors
figure
% copy the initial errors and make the ones not required as zero
valToKeep = 1:3:length(z); % keep every third bar, start from 1
z = e;
for i=1:length(z)
if ~any(valToKeep == i)
z(i) = 0;
end
end
disp(z)
errorbar(x,y,z) % instead of errorbar(x, y, e) keep all third bars
You can then try to tinker with the error bar properties to adjust more visual cues as necessary.
Hope this helps!
  댓글 수: 1
Abel Rangel Trejo
Abel Rangel Trejo 2021년 2월 18일
You can asign value of NaN to each error bar that you don't want to show up in the plot.
Hope this helps to improve Shivam Chaturvedi answer !

댓글을 달려면 로그인하십시오.

범주

Find more on Graphics Object Programming in Help Center and File Exchange

태그

Community Treasure Hunt

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

Start Hunting!

Translated by