Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: variables different formats

  1. Jun 14, 2010 #1
    Hi all,

    I need some help with matlab. I am trying to set up different variables with different formats. For example: "format long", "format short eng".. etc.

    My problems is that when I use the command "format", it assigns the selected format to all the variables. But I want to create a file where some variables have certain format, and some other variables have another format.

    Thank you very much,
  2. jcsd
  3. Jun 15, 2010 #2


    User Avatar
    Science Advisor

    Welcome to PhysicsForums!

    Unfortunately, I don't believe that there is a simple way of doing this. Note also that MATLAB's format command only affects the way variables are displayed, not the way they're stored (or treated) internally:

    If you want to display certain variables in certain formats, I'd code that in the script you're using to process those in the first place (with format changes everywhere). That or just accept MATLAB's display (and be cognizant of the underlying structure).

    Alternately, instead of displaying variables using the variable name, you can make use of the fprintf feature and C-style explicit formatting:

    Good luck!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook