Area Under the Curve value from txt file that has two columns
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello! I was a txt file from a graph that has two columns (x and y value). How I get the values from that txt file into MATLAB and find the area under the curve for values upto a certain x = value? For example, I want to find the area under the curve for values under the x =400? Thank you for your help!
0 Kommentare
Antworten (2)
Chandrika
am 11 Jul. 2022
As per my understanding, for finding area under the curve using values entailed over two columns in a .txt file, you want to import the data into MATLAB.
You can do this using a datastore to get the data from the.txt file to MATLAB.
Assuming, 'X' and 'Y' are the name of the two columns in the txt file and are of type integer, try using the following code:
ds = tabularTextDatastore("file.txt","TreatAsMissing","NA",...
"MissingValue",0);
ds.SelectedVariableNames = ["X","Y"];
ds.SelectedFormats = ["%d","%d"];
You can preview the data stored in the form a table in the datastore using:
Data=preview(ds)
For a better understanding, please refer to the following documentation: https://in.mathworks.com/help/matlab/ref/matlab.io.datastore.tabulartextdatastore.html#mw_7e1955a2-061d-495c-9122-07c4ad79de55
Further, for finding the area under curve for values upto a certain 'x', kindly attach your text file for reproducing the issue.
0 Kommentare
Star Strider
am 11 Jul. 2022
The integration would go something like this —
x = linspace(0, 600, 250).'; % Create 'x'
y = 10*(1-exp(-0.001*x)); % Create 'y'
Lv = x <= 400; % Logical Vector
AUC = trapz(x(Lv), y(Lv)); % Integration
figure
plot(x, y)
hold on
patch([x(Lv); flipud(x(Lv))], [ones(size(y(Lv)))*min(y(Lv)); flipud(y(Lv))], 'b', 'FaceAlpha',0.5)
hold off
xlabel('X')
ylabel('Y')
text(250, max(y(x<=200))/2, sprintf('AUC = %.3f', AUC), 'Horiz','center')
The plot simply illustrates the idea, and is not necessary for the area calculation.
.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB 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!