MATLAB reads txt files

Updated on technology 2024-04-07
7 answers
  1. Anonymous users2024-02-07

    The reading is correct, but the display of MATLAB only shows four decimal places, you can see the exact value by copying the data read into the workspace in MATLAB into XLS.

  2. Anonymous users2024-02-06

    c1c2

    c3]textread('','%f%f%f');Read the file as an array record of floating-point numbers;''It is a txt file created by copying and pasting the data you gave directlyThe directory is placed in the same directory as the m-file file.

    subplot(1,2,1);plot(c1,c2);

    subplot(1,2,2);plot(c1,c3);

  3. Anonymous users2024-02-05

    I don't know what the landlord thinks: the file name is fixed. . . File name change... What kind of logic is this.

    Try this and it won't work...

    The landlord's. s=strcat('f:\example',num2str(date),'txt');% If the landlord's file is, the date is 5

    name=textread(s,'%s',1);

  4. Anonymous users2024-02-04

    MATLAB is a method for batch reading txt files in a folder.

    2.Put the text file into the MATLAB work path for easy reading and operation. For example, if my text file is on the desktop, I can change the working path of MATLAB to desktop.

    To do this, click on the current working path after the ellipsis in MATLAB, pop up the option to select a folder, and then select the corresponding path.

    3.Next, we use the importdata function to read the file. For example, if I want to read a text file named data, I can type: data=importdata() in the command window'')。

    4.The results show that the data is a structured array. At this point, we can look at what each part of the structure represents.

    As shown in the figure below, the first array represents the number of text files, and the second and third arrays represent the Chinese characters in the text files. At this point, everyone can reference the appropriate array as needed.

    5.In addition to the above features, you can also use the tex tread function to read. When using this feature, you can use [a,b,c,d]=tex tread ('data') to specify the format of each part of the output.

    txt','2s%。3f%。3f%.

    3f”)。The second quotation mark in the text indicates the format of the output. For example, %2s means that the output format of the first column is an array of cells%. 3f means that the output digit retains three decimal places.

  5. Anonymous users2024-02-03

    For example, there are a series of txt files under e:ew, the file names conform to the naming convention of MATLAB variable names, and there are no files, each file has two columns, separated by spaces, the first column is a string, the second column is a floating-point number, and the floating-point number in the second column is an array and the file name is the variable name.

    file=dir('e:ew\*.txt');

    for n=1:length(file)

    temp=dlmread(['e:ew\',file(n).name],'0,1);

    eval([file(n).name(1:end-4),'temp;']end

  6. Anonymous users2024-02-02

    Use the dir function to get all the subfolders and files under the specified folder and store them in an array of file structs.

    The dir function can be called.

    dir('.Lists all subfolders and files in the current directory.

    dir('g:\matlab') lists all subfolders and files in the specified directory.

    dir('*m') lists the folders and files in the current directory that match the regular expression.

    The result is an array of structs, each of which is a struct of the following form.

    name --filename

    date --modification date

    bytes --number of bytes allocated to the file

    isdir --1 if name is a directory and 0 if not

    datenum --modification date as a matlab serial date number

    They are the file name, modification date, size, directory status, and MATLAB-specific modification date.

    File names can be extracted for reading and saving.

    2.I can't think of a good way to do this, but to use a uniform temporary variable to read the file data, such as tmp, and then use a string variable to save the variable name, such as str='a1'

    To implement a statement like a1=tmp, you can use the following statement:

    str_a1=[str,'=tmp'];

    eval(str_a1);

    In this way, the variable a1 appears in the workspace.

    But the problem is that you don't know that the variable is called a1? Or I can't find a way to address a variable with a string value, so I can only use the opposite process to import the value into a variable whose name is known, such as tmp

    If you are interested, you can ** it.

  7. Anonymous users2024-02-01

    I tried the 1st floor one.

    After reading all the txt documents in a folder, it is possible to generate an array of structures (e.g. called a). The contents of this A are the same as those described on the first floor.

    Unfortunately, I still can't read the data of a txt document. Don't know how?

Related questions
4 answers2024-04-07

using system;

using ; >>>More

7 answers2024-04-07

Check if the file exists.

8 answers2024-04-07

Let's give you a method.,This method is set up.,You can change it to read.,If you can read the configuration, it's no problem, right? >>>More

11 answers2024-04-07

1. As long as it is not a 64-bit Vista system, let him delete the temporary file cookie history in IE, then enter the content tab of IE attributes, click to clear the SSL status, and then click the setting button behind autocomplete, delete the form and password, and then log in to the game. >>>More

9 answers2024-04-07

I think it works, I did it once when I first started working, and I don't remember it very well, but you can try it with the seek function, locate it first, read it later, and I remember when I was doing this, I read the book The C Programmer, which is about 234 pages.