Rank: 9494 based on 0 downloads (last 30 days) and 0 file submitted
photo

Brad Stiritz

E-mail

Personal Profile:
Professional Interests:
algorithmic trading, object-oriented design, software quality methodologies

 

Watch this Author's files

 

Comments and Ratings by Brad View all
Updated File Comments Rating
02 May 2014 Read Unicode Files Reads Unicode strings from file, outputs character array of strings Author: Vlad Atanasiu

Very helpful function, thank you! One small issue needs to be fixed, however. Running the function with one argument only (the file name) generates a run-time error..

------------------------------------------
>>textscanu(file_spec);
Error using close (line 136)
Invalid figure handle.

Error in textscanu (line 141)
close(h)
------------------------------------------

This error results from:
(a) setting the waitbar handle to default value (0) in the switch block beginning on line 59.
(b) not checking (h) against the "magic" default value (0) before trying to close in line 141.

The simplest fix is to replace line 141 with the following code block:

------------------------------------------
% close waitbar if created
if h ~= 0
close(h)
end
------------------------------------------

However, I should point out that it's not a good choice to use (0) as the default value for (h), since (0) can be a valid handle in general. Better to use (NaN) as the default value, since:

------------------------------------------
>> ishandle(0)
ans = 1

K>> ishandle(NaN)
ans = 0
------------------------------------------

A safer way to code the function would be to initialize (h) to (NaN) before the initial switch block, then re-assign h = waitbar(..) within case 5. The conditional block at the end of the function should then be:

------------------------------------------
% close waitbar if created
if ishandle(h)
close(h)
end
------------------------------------------

21 Jul 2013 Compare Structures Compares two structured variables recursively and notes where the two structures are different. Author: michael arant

Very useful function, but message output is not conducive to machine-processing. It would be helpful to have an option to return only the non-matching field names per se.

I didn't choose to modify the function code, but instead wrote a helper function which extracts the field names from the output messages. Here's the core logic, hope it may be helpful to someone..

%{
Here's an example of the message output from comp_struct():

>>st_1.NAME = 'abc';
>>st_2.NAME = 'def';
>>[~,cv_st_1_msgs] = comp_struct(st_1,st_2,0,0,0,'','',0)
cv_st_1_msgs = '(1).NAME and (1).NAME do not match'

We want to extract 'NAME' from this string. Using free utility Expresso, I
developed a regular expression to capture the first occurence of 'NAME'.
%}

% Declare regular expression to capture field name from comp_struct()
% message output:
regex = '\(.*\)\.(.*)\sand';

% Apply (regex) to all comp_struct output strings & return the capture groups as an (N x 1) cell vector of doubly-nested cell vectors containing the token match.
cv_cv_cv_fieldnames = regexp(cv_messages,regex,'tokens');

% Preallocate output:
cv_fieldnames = cell(N_fields,1);

% Iterate through the regexp() output:
for i_field = 1 : N_fields

% Assign (i)'th output element:
cv_fieldnames{i_field} = cv_cv_cv_fieldnames{i_field}{1}{1};
end

30 Jul 2012 Write Cell Array to Text File A cell array is written to a delimited output file, incl. options for appending & custom delimiters. Author: Roland Pfister

This utility doesn't work consistently for me. Specific problems:

1) Documentation states that file name is taken as the file specification. However, the function occasionally generates errors like the following:

------------------------------
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in dlmcell (line 98)
fprintf(output_file,'%s',output{i,j});
------------------------------

fprintf() requires a file handle as first argument. I'll therefore have to dig into this F/E function & possibly modify.

2) This function doesn't return any values, even on error. Instead, it prints error messages at the command-line & returns normally. This is poor programming practice & makes it inconvenient to deploy within another function where error-detection must be handled programmatically.

One star subtracted for each of these problems.

18 Nov 2011 Design Pattern: Singleton (Creational) A MATLABĀ® OOP implementation of the Singleton Creational Design Pattern Author: Bobby Nedelkovski

Thank you Bobby! for your excellent implementation of this classic design pattern. I especially appreciate your extensive documentation & excellent, highly-descriptive coding style.
5-stars well-deserved. If only all MATLAB code could look like this! Highly recommended.

24 Jul 2011 subdir: a recursive file search Performs a recursive file search using same input and output format as dir function Author: Kelly Kearney

Perfect! Just what I needed. Very appreciated, thank you :)

Contact us