|Sep30-09, 04:44 PM||#1|
Organizing output in MATLAB
So I have this code:
function ApproxSinDeriv(x,n) h=.5; for i = 0:n h; approx = (1/(2*h))*(sin(x+h)-sin(x-h)); error = abs(approx-cos(x)); h = h/2; A=[i,h,approx,error] end
I put A equal to a matrix of these values, but the output comes out in 30 clunky, individual, one-row matrices.
How would I go about putting this data in an array? That is, one nice clean matrix with 30 rows and 4 columns [i,h,approx,error]?
|Oct1-09, 04:24 AM||#2|
function [A] = ApproxSinDeriv(x,n) A = zeros(n+1,4) h=.5; for i = 0:n approx = (1/(2*h))*(sin(x+h)-sin(x-h)); error = abs(approx-cos(x)); h = h/2; A(i+1,:)=[i,h,approx,error]; end
|Oct1-09, 12:18 PM||#3|
Thank you! That worked great!
|Similar Threads for: Organizing output in MATLAB|
|(MATLAB) Ignoring output arguments||Math & Science Software||6|
|Matrix Output (Matlab)||Math & Science Software||1|
|Self-organizing quantum universe explained in July SciAm feature||Beyond the Standard Model||47|
|Java project output problem. Can't output objects from a method.||Engineering, Comp Sci, & Technology Homework||0|
|Self organizing systems : Conway's The Game of Life||General Discussion||36|