How do I plot with error bars in both directions
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Okay, I have two variables, time and temperature. both are 1x10 vector. I also have the error in time and the error in temperature. my time will go on the x axis and the temperature on the y axis. I need to put error bars for the time and temperature points once i have ploted them. I need to do this for various files. So I have recorded them on a text file and done a loop. The errors in the time and temp are also recorded in the txt files. for example in each text file i have the following variables:- row1=time =.......... row2=temp=................. row3=error in time=........... row4=error in temp=.............
I have started like this:-
%Define the file structure
nFiles=500;
filenamePrefix='v';
filenameExtension = '.txt';
for i=1:nFiles
filename= [filenamePrefix, int2str(i), filenameExtension];
tmptimeData=load(filename,'-ascii');
time{i}=tmptimeData(1,:);
temp{i}=tmptimeData(2,:);
figure(i)
plot(time{i}, temp{i}, 'ro')
grid on
hold on
xlabel('temp')
ylabel('time')
end
clear tmptimeData;
So How would I add the error bars on each of the points which are in the same txt files?
1 commentaire
Adithya Addanki
le 13 Jan 2016
Hi MampsRex,
Let me make sure I understand you correctly, you have the time(x) and temperature(y) data along with error in a file.
For error bars, you may use the "errorbar" function. For instance, if you assume time data as "x" and temperature data as "y", you can do this:
x = 1:10;
y = x.*2;
e = std(y)/10*ones(size(x)); % assuming e as error
plot(x,y,'ro')
hold on
errorbar(x,y,e)
Thank you,
Adithya
Réponses (1)
Christopher Thissen
le 1 Fév 2016
Hi Mamps,
You can use my errorbarxy function to plot error bars in x and y (time and temperature in your case). For your specific example, your code might look like this:
nFiles=500;
filenamePrefix='v';
filenameExtension = '.txt';
for i=1:nFiles
filename= [filenamePrefix, int2str(i), filenameExtension];
tmptimeData=load(filename,'-ascii');
time{i}=tmptimeData(1,:);
temp{i}=tmptimeData(2,:);
dtime{i}=tmptimeData(3,:);
dtemp{i}=tmptimeData(4,:);
figure(i)
plot(time{i}, temp{i}, 'ro')
errorbarxy(time{i},temp{i},dtime{i},dtemp{i})
grid on
hold on
xlabel('temp')
ylabel('time')
end
clear tmptimeData;
Let me know if you need more explanation. - Chris
0 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!