0

I have a problem with MATLAB that i cant quite fix. It is throwing me an error, stating

??? Error using ==> fprintf
Function is not defined for 'cell' inputs.

Error in ==> writedata at 93
           fprintf(fout, 'INSERT INTO postgres VALUES( %s, %s, %s.\n )', domain, start, stop);

@Florian Brucker wrote me this code and i changed the code to run 2 regular expressions instead of one, since the one regular expression seems to copy over both of the strings in the document into one cell array when its supposed to be in two separate cell arrays.

domain = '';
start = '';
stop = '';
fin = fopen('CathDomainDescriptionFile.txt', 'r');
fout = fopen('output_cath.txt', 'w');
% TODO: Add error check!
while true
    line = fgetl(fin); % Get the next line from the file
    if ~ischar(line)
        % End of file
        break;
    end
    [key, value] = strtok(line); % Split line at the first space
    switch key
        case 'DOMAIN'
           % Store domain
           domain = value;

        case 'SRANGE'


% two regular expressions since the doing it all in one throws an error
% Index exceeds matrix dimensions.

           m = regexp(value, 'START=(\d+)', 'tokens');
           m2 = regexp(value, 'STOP=(\d+)', 'tokens');

           start = m;
           stop = m2;


           % Print result
           fprintf(fout, 'INSERT INTO postgres VALUES( %s, %s, %s.\n )', domain, start, stop);
    end
end
fclose(fin);
fclose(fout);

It seems to print out the results for the DOMAIN, but not for the START and STOP values, due to the error. It should just simply, print out the Domain number, START and STOP values inside of the fprintf statement.

I am a beginner to MATLAB.

1 Answer 1

1

You should have a look at the return type of regexp.

In your call to fprintf you state that the input is an integer. This contradicts with the output of the regexp function called above.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry my apologies, that was suppose to be read as a string. I have updated my code. Do you know where else i could be going wrong?
You can use start = cell2mat(m{1}); to convert to numerical value, as long as you are sure that m{1} contains only one cell array.
Now it states , ??? Index exceeds matrix dimensions.. But somehow it saves 600 entries instead of over 10,000 entries.
I think i may have found the problem with the index matrix dimensions. Its because there is a negative integer in the data that im trying to extract from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.