Thursday, March 14, 2013

Apparent Matlab R2012a Bug with 'clear' statement

So I found a problem with Matlab R2012a x64...

My problem (not really important):
I'm looking for a string inside a cell array using strfind.  This gives me a cell array with empty cells except where it finds the string.  Then i do a search for isempty in a loop until I find the one that contains a value and I save the index and break the loop.  Then I have a conditional to write data associate with that index.  This repeats for several strings so I clear the index after each completed set of operations.  Example:


% -------------------------------------------------------------------------
% Pressure
% -------------------------------------------------------------------------
    A=strfind(myData.textdata,'Pressure');

    for I=1:length(A)
        AA=isempty(A{I});
        if AA==0
            II=I-1;
            break;
        end
    end
 
    if J==1
        Mean_Pressure=reshape(myData.data(:,II),Nx,Ny);
    else
        Mean_Pressure(end+1:end+Nx,:)=reshape(myData.data(:,II),Nx,Ny);
    end
 
    clear II

Apparent Matlab Problem:  if the 'clear II' statement is exactly one line below the 'end' the variable never clears.

Solution:  There must be a blank line between the 'end' and the 'clear'.

No comments: