How do I plot with error bars in both directions

6 次查看(过去 30 天)
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 个评论
Adithya Addanki
Adithya Addanki 2016-1-13
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

请先登录,再进行评论。

回答(1 个)

Christopher Thissen
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

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by