excel - How can I implement for-loop to calcuate partial area of the curve in MATLAB? -
i have large data set in excel file having 100 rows , 300 columns. first row name of variable (y1:y300), rest of data numeric. interested calculate partial auc present between 2 fixed points of x axis. using @shellfish solution how calculate partial area under curve matlab?. want implement loop can calculate partial area every y value y1 y300. how can use for-loop achieve this? used code..i imported .xls file using matlab import function.
data = importfile('test.xls','sheet1','a2:az100'); y1 = data(:,1); y2 = data(:,2); y3 = data(:,3); y4 = data(:,4); y5 = data(:,5); ... x = [-1000:10:1000]; startingindex = find(x==-350); endingindex = find(x==-100); desiredx = x(startingindex:endingindex); desiredy = y1(startingindex:endingindex); area = trapz(desiredx,desiredy); area
my try for-loop calculate desiredy every time
for i=y1:y100 desiredy = i(startingindex:endingindex); area = trapz(desiredx,desiredy); area end
but thing terribly wrong code..not working.
it great, if me correct code.
there's couple things wrong here. first, can't define iterators for
loop that. second, there's no reason explicitly define y1, y2, ..., yn
, can address data
array directly. fingers hurt thinking typing of out :(
using linked question sample data , code:
% set sample data data = rand(100,3); x = 0:100; startingindex = find(x == 20); endingindex = find(x == 80); desiredx = x(startingindex:endingindex); % preallocate [nrows, ncolumns] = size(data); desiredy = zeros(ncolumns, 1); area = zeros(ncolumns, 1); ii = 1:ncolumns desiredy = data(startingindex:endingindex, ii); area(ii) = trapz(desiredx, desiredy); end
this goes through every column of data
, performs linked integration, storing result in area
. each index of area
corresponds column in y
.
Comments
Post a Comment