필터 지우기
필터 지우기

How do I plot with error bars in both directions

조회 수: 9 (최근 30일)
MampsRex
MampsRex 2016년 1월 11일
답변: Christopher Thissen 2016년 2월 1일
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
Christopher Thissen 2016년 2월 1일
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에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by