I am trying to Integrate data (discontinuous) over certain range and get error
Show older comments
Hi all,
I am trying to Integrate data (discontinuous) over certain range and get error. It displays as follows
"Error using permute
ORDER contains an invalid permutation index.
Error in cumtrapz (line 46)
y = permute(y,perm);
Error in Effi1 (line 72)
yy=cumtrapz(Sol_wv(1:i),Sol_wv(1:i)'.*Sol_energy(1:i));"
My goal is to have all of Ai values as in the form of a vector contained in Aii. (without replacing the old Ai value generated)
In other words, I would like to see length(Aii)= length(Sol_wv).
Here are my codes.
______________________________
A=(theta/(P_t*h*c)); % All the variables are constants
for i=1:length(Sol_wv) % length(Sol_wv) is 2002
y=((h*c./Sol_wv(i))-E_loss); %E_loss is a constant
yy=cumtrapz(Sol_wv(1:i),Sol_wv(1:i)'.*Sol_energy(1:i));
% I would like yy to return the area under the data of specified range (defined by i)
% The dimensions of Sol_wv and Sol_energy agree. I have confirmed it.
Ai(i)=A*(y).*yy;
% Return the iterative Ai(i) into Ai(i), in which gets replaced per iteration
Aii(i)=Ai;
% Store the array of Ai values into Aii. This will be used for plotting later.
length(Aii)
plot(Sol_wv,Aii)
end
% Somehow length(Aii) returns 1631, which is supposed to be 2002 if the codes are right
%I have tried while methods, yet this also fails to work.
Thanks in advance,
Ian
Answers (2)
Walter Roberson
on 17 Mar 2014
Your Sol_wv(1:i) is 0, so Sol_wv(1:i)'.*Sol_energy(1:i) is 0, and your cumtrapz() call becomes cumptraz(0,0) which gives you the error.
Try adding the dimension to the call:
cumtrapz(Sol_wv(1:i), Sol_wv(1:i)'.*Sol_energy(1:i), 2)
1 Comment
Taehyun Kim
on 17 Mar 2014
Taehyun Kim
on 18 Mar 2014
Categories
Find more on Numerical Integration and Differentiation 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!