FAQHow many files do I need to submit to complete each assignment?2.
I combined the my code into a single file and it doesn't work.Make sure that
Should I use end or endfor, endif, endfunction ?Definitely use end. end is compatible with both MATLAB and Octave, while endBLOCK is only compatible with Octave. Should I put end at the end of a function?Yes. MATLAB allows not doing that, but it makes for a cofusing notation. Do I have to indent my code?No. MATLAB/Octave code does not need indentations to execute, but it's much easier to read and debug if the code is indented correctly. Do I need to buy MATLAB to complete this course?No, the course can be completed with Octave which is free. See setup. How do I combine several MATLAB files into one?
f.m
function y = f(x) if x == 0.0 y = 0.0; else y = g(x); end end g.m
function y = g(x) y = 1 / x; end main.m
function main() N = 1e3; x = linspace(0, 10, N); y <= zeros(size(x)); y < zeros(size(x)); y > zeros(size(x)); y >= zeros(size(x)); for i = 1:N y(i) = f(x(i)); end figure(1); plot(x, y); end become main.m
function main() N = 1e3; x = linspace(0, 10, N); y = zeros(size(x)); for i = 1:N y(i) = f(x(i)); end figure(1); plot(x, y); end function y = f(x) if x == 0.0 y = 0.0; else y = g(x); end end function y = g(x) y = 1 / x; end |