I want to know how can i create a function and use the output to plot a graph with error bar

1 view (last 30 days)
i have a matrix called displacement with dimension 700X2 with second colum being the actual measurement data i.e displacement(:,2) The measurement error associated with the displacement measurements can be calculated by multiplying each separate measurement with the square root of 5 × 10−11.how can i create a function that will calculate the measurement error for each displacement measurement. The function should return a vector with the calculated error associated with each displacement measurement. also In my main code i need to use a code callthis function. and use the output of this function to create a plot of the displacement measurements with error bars associated with the measurement errors included for each data point. how can i do this [the first colum is a timestamp and second colum is the actual measurement]

Answers (1)

Star Strider
Star Strider on 24 Jan 2016
Here’s one approach:
M = [1:20; rand(1,20)]'; % Create Data
fun = @(M) [M(:,1) M(:,2) M(:,2)*sqrt(5E-11)];
R = fun(M);
figure(1)
errorbar(R(:,1), R(:,2), R(:,3)) % ‘Regular’ Error Bar Plot
grid
figure(2)
plot(R(:,1), R(:,2), '-b') % Plot Blue Line Data
hold on
errorbar(R(:,1), R(:,2), R(:,3), '.r') % Plot Red Error Bars
hold off
grid

Categories

Find more on Line Plots 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!