How to get answers in a matrix form

조회 수: 8 (최근 30일)
Houman Qadir
Houman Qadir 2020년 11월 11일
댓글: Houman Qadir 2020년 11월 11일
I have this code that outputs answers separately for each column I use the function for. How can I get all the answers in a single concise matrix form?
% matrix
for i = 1:15
y = yval(:,i);
trapz(xcord, y)% Function applied to each column
end

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 11월 11일
Houman - if we assume that the result of trapz is a scalar, then you could do something like
trapzResults = zeros(size(yval,2),1); % pre-size output array
for i = size(yval,2) % iterate over the columns of yval
y = yval(:,i);
trapzResults(i) = trapz(xcord, y);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by