Matlab: variables different formats

  • Context: MATLAB 
  • Thread starter Thread starter camimfajardo
  • Start date Start date
  • Tags Tags
    Matlab Variables
Click For Summary
SUMMARY

This discussion focuses on the limitations of MATLAB's format command, specifically version R2023a, which applies a single display format to all variables. Users seeking to display variables in different formats must implement formatting directly in their scripts or utilize the fprintf function for explicit formatting. The format command only alters the display and does not affect the internal storage of variables. For tailored variable presentation, coding adjustments are necessary.

PREREQUISITES
  • Familiarity with MATLAB syntax and commands
  • Understanding of variable types and display formats in MATLAB
  • Knowledge of the fprintf function for formatted output
  • Basic scripting skills in MATLAB
NEXT STEPS
  • Explore MATLAB's format command documentation for detailed usage
  • Learn how to use fprintf for custom variable formatting
  • Investigate MATLAB's data types and their display characteristics
  • Review best practices for scripting in MATLAB to manage variable formats
USEFUL FOR

MATLAB users, data analysts, and engineers who need to manage and display variables in different formats within their scripts.

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 ·
Replies
4
Views
2K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K