Create array with integral values
9 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
i have a vector of 3366 elements. Basically i have a nan value every 66 elements. I want to create a new vector that cointains the integration (trapz) of the first 66 elements as the first value, than the integral from the 68 to the 134 as the second value and so on. How can this be achivied ? Could anyone please help me ?
0 个评论
采纳的回答
the cyclist
2021-2-9
编辑:the cyclist
2021-2-9
% original vector
v = rand(1,3366);
r = reshape(v,66,[]);
% You may need to do a step where you remove the last row of r, which has the NaNs.
r(end,:) = [];
trapz(r)
3 个评论
the cyclist
2021-2-10
Let's look at what I did, and try to understand it together, and see how it differs from what you just said.
I created a vector with 3,366 elements in it. I made up values, and called it v. But you can call it x if you want.
Then I reshaped that vector into a 66x51 array.
Since every 66th value of the vector is NaN, that means that the bottom row of the array is entirely NaN. That's why I removed it. So now the array is 65x51.
Then, I used the trapz function on the array. If you read the documention, you will see that trapz acting on an array input will perform an integration down each column of that array. Therefore, the result is a 1x51 vector, where each element is the integral of the column.
Other than your expectation of 50 values, instead of the 51 I got, I don't see how what I did differs from what you asked.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!