Hi all!
Could you please help me understand this piece of code here?
classdef Tire<handle properties (Constant) DEFAULT_DIR = 'C:\Users\Vicente Silva\Desktop\'; end properties Name; Dir; end properties % here comes the declaration of a bunch of properties,
% which are not important for understanding the code itself
end methods function tire = Tire(varargin) tire.Name = varargin{1}; if nargin > 1 tire.Dir = varargin{2}; else tire.Dir = Tire.DEFAULT_DIR; end try load([tire.Dir tire.Name '.mat']); catch tire = tire.LoadFromTir([tire.Name '.tir']); tire.Fzo = tire.FNOMIN; end end function tire = LoadFromTir(tire, tir_filename) tirfile = fopen([tire.Dir tir_filename], 'r'); line = fgetl(tirfile); while ischar(line) if regexp(line, '^[A-Z]') prop = strsplit(line,{'=' '$'}); propname = char(strtrim(prop{1})); if isprop(tire, propname) propval = char(strtrim(prop{2})); if ~strncmpi(propval,'''',1) tire.(propname) = str2double(propval); else tire.(propname) = strrep(propval, '''', ''); end end end line = fgetl(tirfile); end fclose(tirfile); end function Save(tire) save([tire.Dir tire.Name '.mat'], inputname(1)); end
I have used 'help' command for most of the commands I didn't know, but it didn't help understand much. More importantly, it surely didn't allow me to understand how to keep on writing pieces of code myself! Keep in mind, this is part of a work I'm currently developing with a friend of mine. But he is the computer sciences student, and I'm the mechanical engineering one. I only understand a bit of coding in MATLAB and Simulink. This here is practically russian for me. I have tried asking my friend for more help and clarifications, but it seems he is busy. I really wish I could do all this work on my own, but I'm at a much more superficial level of coding right now. My work is due at the 15th this month, and without any help I won't be able to finish everything. Please, help me!
Best Answer