How to get answers in a matrix form

8 visualizaciones (últimos 30 días)
Houman Qadir
Houman Qadir el 11 de Nov. de 2020
Comentada: Houman Qadir el 11 de Nov. de 2020
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

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 11 de Nov. de 2020
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

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by