Error bars at intervals of data
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Shivam Chaturvedi
am 3 Mär. 2016
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
Hope this helps!
1 Kommentar
Abel Rangel Trejo
am 18 Feb. 2021
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 !
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!