Matlab: variables different formats

  • Context: MATLAB 
  • Thread starter Thread starter camimfajardo
  • Start date Start date
  • Tags Tags
    Matlab Variables
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
camimfajardo
Messages
2
Reaction score
0
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,
Regards,
 
Physics news on Phys.org
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:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/format.html

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:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html

Good luck!