MATLAB Matlab: variables different formats

  • Thread starter Thread starter camimfajardo
  • Start date Start date
  • Tags Tags
    Matlab Variables
AI Thread Summary
In MATLAB, the "format" command applies a display format universally to all variables, which can be limiting when different formats are desired for specific variables. The format command only affects how variables are displayed, not how they are stored or processed internally. To achieve varied display formats for different variables, users are advised to implement format changes directly in their scripts during processing. Alternatively, using the "fprintf" function allows for explicit formatting of output, providing more control over how individual variables are displayed.
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!
 

Similar threads

Replies
4
Views
1K
Replies
18
Views
6K
Replies
2
Views
2K
Replies
2
Views
4K
Replies
5
Views
3K
Replies
22
Views
4K
Back
Top