Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:12:36+00:00 2026-06-07T20:12:36+00:00

In a matlab script, I’m generating a latex table. A part of that table

  • 0

In a matlab script, I’m generating a latex table. A part of that table for example looks likes this.

\multirow{2}{*}{\textbf{b1}}
&
2 & 3 & 10092 & 10763 & 103390 & 2797 & 2929 & 3008 & 5\% & 8\% \\
& 4 & 2 & 20184 & 10763 & 74508 & 1830 & 1970 & 2029 & 8\% & 11\% \\

This string is saved in variable str. Now when I try to write str to a file by using the following code.

f = fopen( 'report\results.tex', 'w' );
fprintf( f, str );
fclose(f);

I get the following warning.

Warning: Invalid escape sequence appears in format string. 
See help sprintf for valid escape sequences.

That is probably due to many backslash characters in my string, which is used as escape sequence. Now how can I print this string to a file as it is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:12:38+00:00Added an answer on June 7, 2026 at 8:12 pm

    escape the backslashes and percent signs:

    str = strrep(str,'\','\\');
    str = strrep(str,'%','%%');
    

    If it’s just text your printing, this’ll be fine.

    Minimal working example:

    str = '2 & 3 & 10092 & 10763 & 103390 & 2797 & 2929 & 3008 & 5\% & 8\% \\'
    str = strrep(str,'\','\\');
    str = strrep(str,'%','%%');
    f=fopen('testing123.txt','w');
    fprintf(f,str);
    fclose(f);
    

    and the file reads:

    2 & 3 & 10092 & 10763 & 103390 & 2797 & 2929 & 3008 & 5\% & 8\% \\
    

    OR as Ben A. suggests, use fwrite:

    fwrite(f,str)
    

    and I think

    fprintf(f,'%s',str)
    

    will also do the trick, and it’s best to also include a newline:

    fprintf(f,'%s\n',str)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write a Matlab script that does this: The input is 2
I've written a Matlab script for classification. When I execute this I'm getting Out
I have a matlab script, lets call it master.m, that loads a file called
I'm writing a small C application that launchs a Matlab script (.m file). I
I have developed code on a m-file script in Matlab that communicates with a
I have a Matlab script that requires a function in a DLL, and calls
I am using a script in MatLab that works perfectly fine by itself, but
when i write this codes in MATLAB(script) I=imread('f:\oli.tif'); I2=nlfilter(I,[3 3],'std2'); imshow(I2) gives these following
Sometimes I start a MATLAB script and realize too late that it is going
Do you know a matlab script that gets the correlation matrix of a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.