Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to display and output the text of matlab?
How to display and output the text of matlab?
Hello, summarize all kinds of online resources and list the following four methods (taking txt as an example).

The first method: save (the simplest and most basic)

The specific command is: Use Save? *.txt? -ascii? x

X is a variable.

*.txt is the file name, stored in the current working directory, and can be reopened? After opening, the data may be saved exponentially.

Example:

Answer? =);

% read the data with the file number 1 into f, where f is [12? 90] matrix

% Here' %f? "%f" means reading data according to the original data type.

fclose(FID);

% Close file

In addition, some txt files can also be loaded and opened.

Its statement is

f=load('fx.txt)

String operation function

The 1. function eval can be used to execute an expression represented by a string.

2. The function deblank can delete all spaces at the end of the string.

3.findstr function can be used to find short strings in long strings and return the corresponding positions.

4. The function isstr can be used to judge whether the variable is a string.

5.isletter function can be used to judge whether every element in a string is a letter.

6. The function isspace can be used to judge whether a string element is a space character.

7. Functions lower and upper can convert letters in a string into lowercase and uppercase formats.

8. The function strcat can connect multiple strings in turn in the horizontal direction.

9.strvcat function can connect multiple strings vertically.

10.? The function strcmp can be used to compare strings and return 1 or 0.

1 1.? The strcmpi function can be used to compare strings regardless of the case of English letters.

12.? The function strncmp can be used to compare whether the first n characters of a string are the same.

13.? The function strjust can be used to adjust the alignment of the string matrix.

14.? The strmatch function can be used to find lines that match the target string.

15.? The function strrep can realize the function of finding and replacing strings.

16.? The function strtok can find the string before the first space character of the string.

17.? Texlabel function can convert strings into the format of tex software.

18.? Conversion between different binary systems, bin2hex, bin2dec ('string'); Dec2hex (number) = string; In other words, the decimal number is not a string. The other system is a string.

19.? The function bitget can be used to obtain the binary number C=bitget(A, bit), where a is unsigned plastic data.

20.? Function bitset can be used to set the value of a binary number? C=bitset(A,bit)? The value of the specified number is reversed.

C=bitset(A, bit, v) specifies that the number of digits is replaced by v.

The fourth method: (less data is ok)

For example: a=[ 17? 24? 1? 8? 15; 23? 5? 7? 14? 16? ; 4? 6? 13? 20? 22? ; 10? 12? 19? 2 1? 3? ; 1 1? 18? 25? 2? 9? ];

It is a 5×5 matrix.

1724? 1? 8 15

23? 5? 7 14 16

4? 6 132022

10 12 192 1? three

1 1 1825? 2? nine

fid=fopen('Tname.txt ',' wt ')? ;

fprintf(fid,' %8.4f%8.4f%8.4f? %8.4f? %8.4f? \n ',a ')? % output matrix

Fclose(fid)% Close file

Explain the meaning of each item in the fprintf command:

The handle to the fid function, which represents the previously opened file.

%8.4f? %8.3f? %6.2f\n '? The output format is as follows:

1 、%8.4f? Indicates that the output format is floating-point number, occupying 8 digits (including decimal point) and retaining 4 decimal places.

2. What about the other %8.3f? %6.2f means the same as 1.

3.\n means line feed.

4. Give three different output formats before the line break to indicate that three data are output per line (of course, the three formats can be the same, but you have to write three times to output three data per line), that is to say, several data are output per line in the previous line break output format.

————————————————

Copyright statement: This article is the original article of CSDN blogger "qing 10 1hua", following CC? 4.0? BY-SA copyright agreement, please attach the original source link and this statement.

Original link: