Hướng dẫn spreadsheet import options matlab - matlab tùy chọn nhập bảng tính

bảng tínhImportOptions

Nhập tùy chọn đối tượng cho bảng tính

Show

Sự mô tả

Đối tượng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 cho phép bạn chỉ định cách nhập dữ liệu bảng MATLAB® từ các tệp bảng tính. Đối tượng chứa các thuộc tính kiểm soát quá trình nhập dữ liệu, bao gồm việc xử lý các lỗi và dữ liệu bị thiếu.

Sự sáng tạo

Bạn có thể tạo đối tượng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 bằng cách sử dụng hàm
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
3 hoặc hàm
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
4 (được mô tả ở đây):

  • Sử dụng

    opts = spreadsheetImportOptions; 
    opts.VariableNames = 'LastName';
    opts.VariableTypes = 'categorical';
    opts.DataRange = 'A2';
    preview('patients.xls',opts)
    3 để phát hiện và điền vào các thuộc tính nhập dựa trên nội dung của bảng tính được chỉ định trong
    opts = spreadsheetImportOptions; 
    opts.VariableNames = 'LastName';
    opts.VariableTypes = 'categorical';
    opts.DataRange = 'A2';
    preview('patients.xls',opts)
    6.

    opts = detectImportOptions(filename);

  • Sử dụng

    opts = spreadsheetImportOptions; 
    opts.VariableNames = 'LastName';
    opts.VariableTypes = 'categorical';
    opts.DataRange = 'A2';
    preview('patients.xls',opts)
    4 để xác định các thuộc tính nhập dựa trên các yêu cầu nhập của bạn.

Cú pháp

Sự mô tả

Đối tượng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 cho phép bạn chỉ định cách nhập dữ liệu bảng MATLAB® từ các tệp bảng tính. Đối tượng chứa các thuộc tính kiểm soát quá trình nhập dữ liệu, bao gồm việc xử lý các lỗi và dữ liệu bị thiếu.

Sự sáng tạo creates a

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 object with one variable.

Đối tượng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 cho phép bạn chỉ định cách nhập dữ liệu bảng MATLAB® từ các tệp bảng tính. Đối tượng chứa các thuộc tính kiểm soát quá trình nhập dữ liệu, bao gồm việc xử lý các lỗi và dữ liệu bị thiếu.

Sự sáng tạo creates the object with the number of variables specified in

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

1.

Đối tượng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 cho phép bạn chỉ định cách nhập dữ liệu bảng MATLAB® từ các tệp bảng tính. Đối tượng chứa các thuộc tính kiểm soát quá trình nhập dữ liệu, bao gồm việc xử lý các lỗi và dữ liệu bị thiếu.

Sự sáng tạo specifies additional properties for

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 object using one or more name-value pair arguments.

Bạn có thể tạo đối tượng opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)1 bằng cách sử dụng hàm opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)3 hoặc hàm opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)4 (được mô tả ở đây):

Sử dụng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
3 để phát hiện và điền vào các thuộc tính nhập dựa trên nội dung của bảng tính được chỉ định trong
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
6.

Sử dụng opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)4 để xác định các thuộc tính nhập dựa trên các yêu cầu nhập của bạn.Number of variables positive scalar integer

Cú pháp

thí dụ

Sử dụng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
3 để phát hiện và điền vào các thuộc tính nhập dựa trên nội dung của bảng tính được chỉ định trong
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
6.

Sử dụng opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)4 để xác định các thuộc tính nhập dựa trên các yêu cầu nhập của bạn.

Cú pháp

thí dụ

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
8 Tạo một đối tượng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 với một biến.

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

0) tạo đối tượng với số lượng biến được chỉ định trong
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

1.
oneVar = readtable('patients.xls',opts);
whos oneVar
1 returns the current (detected) variable names.

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

2) Chỉ định các thuộc tính bổ sung cho đối tượng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 bằng cách sử dụng một hoặc nhiều đối số cặp giá trị tên.
oneVar = readtable('patients.xls',opts);
whos oneVar
2 changes the name of the third variable to
oneVar = readtable('patients.xls',opts);
whos oneVar
3.

Đối số đầu vào

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
oneVar = readtable('patients.xls',opts);
whos oneVar
6

mở rộng tất cả — Flag to preserve variable names oneVar = readtable('patients.xls',opts); whos oneVar8 (default) | oneVar = readtable('patients.xls',opts); whos oneVar9

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

1 - Số lượng vô hướng variablespositive

  • Số lượng biến, được chỉ định là số nguyên vô hướng dương.

  • Đặc tính

Thuộc tính biến

Tên biến, được chỉ định là một mảng ô của các vectơ ký tự hoặc mảng chuỗi. Thuộc tính

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

5 chứa các tên sẽ sử dụng khi nhập các biến.
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5

Nếu dữ liệu chứa các biến

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

6, nhưng không có tên biến nào được chỉ định, thì thuộc tính
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

5 chứa
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

8.

Để hỗ trợ các định danh MATLAB không hợp lệ dưới dạng tên biến, chẳng hạn như tên biến có chứa khoảng trắng và ký tự không phải ASCII, đặt giá trị của

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

9 thành
oneVar = readtable('patients.xls',opts);
whos oneVar
0.

Ví dụ:

oneVar = readtable('patients.xls',opts);
whos oneVar
1 Trả về tên biến (phát hiện) hiện tại.
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
6 returns the current variable data types.

Ví dụ:

oneVar = readtable('patients.xls',opts);
whos oneVar
2 Thay đổi tên của biến thứ ba thành
oneVar = readtable('patients.xls',opts);
whos oneVar
3.
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
7 changes the data type of the variable
oneVar = readtable('patients.xls',opts);
whos oneVar
3 to
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9.

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
oneVar = readtable('patients.xls',opts);
whos oneVar
6

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

9 - cờ để bảo tồn tên biến ____38 (mặc định) |
oneVar = readtable('patients.xls',opts);
whos oneVar
9

Cờ để bảo tồn tên biến, được chỉ định là

oneVar = readtable('patients.xls',opts);
whos oneVar
8 hoặc
oneVar = readtable('patients.xls',opts);
whos oneVar
9.

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
8 Tạo một đối tượng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 với một biến.

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

0) tạo đối tượng với số lượng biến được chỉ định trong
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

1.
opts = spreadsheetImportOptions('NumVariables',numVars,...
                                'VariableNames',varNames,...
                                'VariableTypes',varTypes,...
                                'DataRange', dataStartLoc); 
9 selects only two variables,
oneVar = readtable('patients.xls',opts);
whos oneVar
3 and
preview('patients.xls',opts)
1, for the import operation.

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

2) Chỉ định các thuộc tính bổ sung cho đối tượng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1 bằng cách sử dụng một hoặc nhiều đối số cặp giá trị tên.
preview('patients.xls',opts)
2 selects only two variables, the first variable and the fifth variable, for the import operation.

Đối số đầu vào

preview('patients.xls',opts)
3 returns a table containing only the variables specified in the
opts = spreadsheetImportOptions('NumVariables',numVars,...
                                'VariableNames',varNames,...
                                'VariableTypes',varTypes,...
                                'DataRange', dataStartLoc); 
0 property of the
preview('patients.xls',opts)
5 object.

mở rộng tất cả

preview('patients.xls',opts)
6 |
preview('patients.xls',opts)
7 |
preview('patients.xls',opts)
8 |
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
oneVar = readtable('patients.xls',opts);
whos oneVar
6

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

1 - Số lượng vô hướng variablespositive

Tùy chọn biến hỗ trợ các loại dữ liệu này: Số, văn bản,

ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

3,
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

4 hoặc
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

5.

Để truy vấn các tùy chọn hiện tại (hoặc được phát hiện) cho một biến, hãy sử dụng hàm

ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

6.

Để đặt và tùy chỉnh tùy chọn cho một biến, hãy sử dụng hàm

ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

7.

Ví dụ:

ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

8 Trả về một tập hợp các đối tượng
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

9, một đối tượng tương ứng với mỗi biến trong dữ liệu.
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

8 returns a collection of
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

9 objects, one corresponding to each variable in the data.

Ví dụ:

T = readtable('patients.xls',opts);
whos T
0 Trả về đối tượng
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

9 cho biến
oneVar = readtable('patients.xls',opts);
whos oneVar
3.
T = readtable('patients.xls',opts);
whos T
0 returns the
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

9 object for the
oneVar = readtable('patients.xls',opts);
whos oneVar
3 variable.

Ví dụ:

T = readtable('patients.xls',opts);
whos T
3 đặt thuộc tính
T = readtable('patients.xls',opts);
whos T
4 cho biến
oneVar = readtable('patients.xls',opts);
whos oneVar
3 thành
T = readtable('patients.xls',opts);
whos T
6.
T = readtable('patients.xls',opts);
whos T
3 sets the
T = readtable('patients.xls',opts);
whos T
4 property for the variable
oneVar = readtable('patients.xls',opts);
whos oneVar
3 to
T = readtable('patients.xls',opts);
whos T
6.

Thuộc tính vị trí

Bảng để đọc từ, được chỉ định là một mảng ký tự trống, vectơ ký tự hoặc vô hướng chuỗi chứa tên trang tính hoặc số nguyên vô hướng dương biểu thị chỉ mục trang tính. Dựa trên giá trị được chỉ định cho thuộc tính

T = readtable('patients.xls',opts);
whos T
7, hàm nhập hoạt động như được mô tả trong bảng.

Sự chỉ rõHành vi
T = readtable('patients.xls',opts);
whos T
8 (mặc định)
Nhập dữ liệu từ tờ đầu tiên.
TênNhập dữ liệu từ tên trang tính phù hợp, bất kể thứ tự của bảng trong tệp bảng tính.
Số nguyênNhập dữ liệu từ trang tính ở vị trí được biểu thị bằng số nguyên, bất kể tên trang tính trong tệp bảng tính.

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9

opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)03 - Vị trí của vector datacharacter | Chuỗi vô hướng | Số nguyên vô hướng tích cực | Mảng số nguyên vô hướng tích cực | Mảng ô của vectơ ký tự | Mảng chuỗi — Location of data character vector | string scalar | positive scalar integer | array of positive scalar integers | cell array of character vector | string array

Vị trí của dữ liệu được nhập, được chỉ định là vectơ ký tự, vô hướng chuỗi, mảng ô của các vectơ ký tự, mảng chuỗi, số nguyên vô hướng dương hoặc ____ ____ 26-BY -____ 105 Mảng số nguyên vô hướng dương. Chỉ định

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
03 bằng một trong các hình thức này.

Theo quy định củaHành vi

T = readtable('patients.xls',opts);
whos T
8 (mặc định)

Nhập dữ liệu từ tờ đầu tiên.

Tên

Nhập dữ liệu từ tên trang tính phù hợp, bất kể thứ tự của bảng trong tệp bảng tính.

Số nguyên

Nhập dữ liệu từ trang tính ở vị trí được biểu thị bằng số nguyên, bất kể tên trang tính trong tệp bảng tính.

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13 or
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
15'

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
03 - Vị trí của vector datacharacter | Chuỗi vô hướng | Số nguyên vô hướng tích cực | Mảng số nguyên vô hướng tích cực | Mảng ô của vectơ ký tự | Mảng chuỗi

Vị trí của dữ liệu được nhập, được chỉ định là vectơ ký tự, vô hướng chuỗi, mảng ô của các vectơ ký tự, mảng chuỗi, số nguyên vô hướng dương hoặc ____ ____ 26-BY -____ 105 Mảng số nguyên vô hướng dương. Chỉ định

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
03 bằng một trong các hình thức này.

Theo quy định của

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
07 hoặc
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
08

Di động bắt đầu hoặc hàng bắt đầu

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
19

Chỉ định ô bắt đầu cho dữ liệu, sử dụng ký hiệu Excel®

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
09. Ví dụ,
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
10 là mã định danh cho ô tại giao điểm của cột
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
11 và hàng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12.

Sử dụng ô bắt đầu, chức năng nhập tự động phát hiện phạm vi của dữ liệu, bằng cách bắt đầu nhập tại ô bắt đầu và kết thúc ở hàng trống hoặc phạm vi chân trang cuối cùng.

Ngoài ra, chỉ định hàng đầu tiên chứa dữ liệu bằng chỉ số hàng vô hướng dương.

Sử dụng chỉ mục hàng được chỉ định, hàm nhập tự động phát hiện phạm vi của dữ liệu bằng cách đọc từ hàng đầu tiên được chỉ định đến cuối dữ liệu hoặc phạm vi chân trang.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13 hoặc
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
22

Phạm vi hình chữ nhật

Chỉ định phạm vi chính xác để đọc bằng mẫu phạm vi hình chữ nhật, trong đó

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
16 và
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
17 là hai góc đối diện xác định khu vực cần đọc.

Hàm nhập chỉ đọc dữ liệu có trong phạm vi được chỉ định. Bất kỳ trường trống nào trong phạm vi được chỉ định đều được nhập dưới dạng ô bị thiếu.

Số lượng cột phải khớp với số được chỉ định trong thuộc tính

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
18.
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
24

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
25

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
19

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
20 'hoặc
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
21'multiple row ranges to read with an
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

6-by-
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
05 array containing
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

6 different row ranges.

Phạm vi hàng hoặc phạm vi cột

  • Chỉ định phạm vi bằng cách xác định các hàng đầu và kết thúc bằng các số hàng Excel.

  • Sử dụng phạm vi hàng được chỉ định, hàm nhập tự động phát hiện phạm vi cột bằng cách đọc từ cột không trống đầu tiên đến cuối dữ liệu và tạo một biến trên mỗi cột.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
22

Ngoài ra, chỉ định phạm vi bằng cách xác định các cột bắt đầu và kết thúc bằng cách sử dụng các chữ cái hoặc số cột Excel.

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
30

T = readtable('patients.xls',opts);
whos T
8

Sử dụng phạm vi cột được chỉ định, hàm nhập tự động phát hiện phạm vi hàng bằng cách đọc từ hàng không trống đầu tiên đến cuối dữ liệu hoặc phạm vi chân trang.

Số lượng cột trong phạm vi được chỉ định phải khớp với số được chỉ định trong thuộc tính

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
18.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
24
T = readtable('patients.xls',opts);
whos T
8

Phạm vi nhiều hàng

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
oneVar = readtable('patients.xls',opts);
whos oneVar
6 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9

Chỉ định nhiều phạm vi hàng để đọc với một mảng ____ ____ 26-by -____ 105 chứa ans=8×1 table LastName ________ Smith Johnson Williams Jones Brown Davis Miller Wilson 6 Phạm vi hàng khác nhau. — Location of row names character vector | string scalar | positive scalar integer | T = readtable('patients.xls',opts); whos T8 empty character array

Một mảng hợp lệ gồm nhiều phạm vi hàng phải:

Theo quy định củaHành vi

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
07

Chỉ định ô bắt đầu cho dữ liệu, sử dụng ký hiệu Excel

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
09. Ví dụ,
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
10 là mã định danh cho ô tại giao điểm của cột
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
11 và hàng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12.

Hàm nhập xác định tên cho từng biến trong dữ liệu.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
15'

Phạm vi hình chữ nhật

Chỉ định phạm vi chính xác để đọc bằng mẫu phạm vi hình chữ nhật, trong đó

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
16 và
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
17 là hai góc đối diện xác định khu vực cần đọc.

Số lượng hàng có trong

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
39 phải khớp với số lượng hàng dữ liệu và phạm vi được biểu thị bằng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
39 phải chỉ trải rộng một cột.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
53
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
53

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
20'

Phạm vi hàng

Chỉ định phạm vi bằng cách xác định các hàng bắt đầu và kết thúc bằng các số hàng Excel.

Tên hàng phải ở trong một cột duy nhất.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
55
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
55

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
08

Chỉ mục số

Chỉ định cột chứa các tên hàng bằng chỉ mục cột vô hướng dương.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12

T = readtable('patients.xls',opts);
whos T
8

Không xác định hoặc trống rỗng

Chỉ ra rằng không có tên hàng.

Ví dụ:

T = readtable('patients.xls',opts);
whos T
8
T = readtable('patients.xls',opts);
whos T
8

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9

opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)63 - Vị trí của vectơ tên biến đổi biến đổi | Chuỗi vô hướng | Số nguyên vô hướng tích cực | T = readtable('patients.xls',opts); whos T8 Mảng ký tự trống — Location of variable names character vector | string scalar | positive scalar integer | T = readtable('patients.xls',opts); whos T8 empty character array

Vị trí của các tên biến, được chỉ định là vectơ ký tự, vô hướng chuỗi, số nguyên vô hướng dương hoặc mảng ký tự trống. Chỉ định

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
63 là một trong các giá trị trong bảng này.

Theo quy định củaHành vi

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
07

Chỉ định ô bắt đầu cho dữ liệu, sử dụng ký hiệu Excel

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
09. Ví dụ,
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
10 là mã định danh cho ô tại giao điểm của cột
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
11 và hàng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12.

Hàm nhập xác định tên cho từng biến trong dữ liệu.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
15'

Phạm vi hình chữ nhật

Chỉ định phạm vi chính xác để đọc bằng mẫu phạm vi hình chữ nhật, trong đó

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
16 và
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
17 là hai góc đối diện xác định khu vực cần đọc.

Số lượng hàng có trong

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
39 phải khớp với số lượng hàng dữ liệu và phạm vi được biểu thị bằng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
39 phải chỉ trải rộng một cột.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
53
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
76

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
20'

Phạm vi hàng

Chỉ định phạm vi bằng cách xác định các hàng bắt đầu và kết thúc bằng các số hàng Excel.

Tên hàng phải ở trong một cột duy nhất.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
55
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
78

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
08

Chỉ mục số

Chỉ định cột chứa các tên hàng bằng chỉ mục cột vô hướng dương.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12

T = readtable('patients.xls',opts);
whos T
8

Không xác định hoặc trống rỗng

Chỉ ra rằng không có tên hàng.

Ví dụ:

T = readtable('patients.xls',opts);
whos T
8
T = readtable('patients.xls',opts);
whos T
8

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9

opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)63 - Vị trí của vectơ tên biến đổi biến đổi | Chuỗi vô hướng | Số nguyên vô hướng tích cực | T = readtable('patients.xls',opts); whos T8 Mảng ký tự trống — Location of variable descriptions character vector | string scalar | T = readtable('patients.xls',opts); whos T8 empty character array

Vị trí của các tên biến, được chỉ định là vectơ ký tự, vô hướng chuỗi, số nguyên vô hướng dương hoặc mảng ký tự trống. Chỉ định

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
63 là một trong các giá trị trong bảng này.

Theo quy định củaHành vi

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
07

Chỉ định ô bắt đầu cho dữ liệu, sử dụng ký hiệu Excel

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
09. Ví dụ,
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
10 là mã định danh cho ô tại giao điểm của cột
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
11 và hàng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12.

Hàm nhập đọc một tên cho từng biến trong dữ liệu.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
15'

Phạm vi hình chữ nhật

Chỉ định phạm vi chính xác để đọc bằng mẫu phạm vi hình chữ nhật, trong đó

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
16 và
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
17 là hai góc đối diện xác định khu vực cần đọc.

Số lượng hàng có trong

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
39 phải khớp với số lượng hàng dữ liệu và phạm vi được biểu thị bằng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
39 phải chỉ trải rộng một cột.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
53
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
76

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
20'

Phạm vi hàng

Chỉ định phạm vi bằng cách xác định các hàng bắt đầu và kết thúc bằng các số hàng Excel.

Tên hàng phải ở trong một cột duy nhất.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
55
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
78

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
08

Chỉ mục số

Chỉ định cột chứa các tên hàng bằng chỉ mục cột vô hướng dương.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12

T = readtable('patients.xls',opts);
whos T
8

Không xác định hoặc trống rỗng

Chỉ ra rằng không có tên hàng.

Ví dụ:

T = readtable('patients.xls',opts);
whos T
8
T = readtable('patients.xls',opts);
whos T
8

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9

opts = spreadsheetImportOptions; opts.VariableNames = 'LastName'; opts.VariableTypes = 'categorical'; opts.DataRange = 'A2'; preview('patients.xls',opts)63 - Vị trí của vectơ tên biến đổi biến đổi | Chuỗi vô hướng | Số nguyên vô hướng tích cực | T = readtable('patients.xls',opts); whos T8 Mảng ký tự trống — Location of variable units character vector | string scalar | positive scalar integer | T = readtable('patients.xls',opts); whos T8 empty character array

Vị trí của các tên biến, được chỉ định là vectơ ký tự, vô hướng chuỗi, số nguyên vô hướng dương hoặc mảng ký tự trống. Chỉ định

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
63 là một trong các giá trị trong bảng này.

Theo quy định củaHành vi

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
07

Chỉ định ô bắt đầu cho dữ liệu, sử dụng ký hiệu Excel

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
09. Ví dụ,
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
10 là mã định danh cho ô tại giao điểm của cột
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
11 và hàng
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12.

Hàm nhập đọc một tên cho từng biến trong dữ liệu.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
13

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
15'

Phạm vi hình chữ nhật

Chỉ định phạm vi chính xác để đọc bằng mẫu phạm vi hình chữ nhật, trong đó

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
16 và
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
17 là hai góc đối diện xác định khu vực cần đọc.

Số lượng cột phải khớp với số được chỉ định trong thuộc tính

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
18 và phạm vi chỉ phải trải dài một hàng.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
76
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
76

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
20'

Phạm vi hàng

Chỉ định phạm vi bằng cách xác định các hàng bắt đầu và kết thúc bằng các số hàng Excel.

Phải là một hàng duy nhất.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
78
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
78

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
08

Chỉ mục số

Chỉ định hàng chứa các đơn vị dữ liệu bằng chỉ mục hàng vô hướng dương.

Ví dụ:

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
12

T = readtable('patients.xls',opts);
whos T
8

Không xác định hoặc trống rỗng

Chỉ ra rằng không có đơn vị biến.

Ví dụ:

T = readtable('patients.xls',opts);
whos T
8
T = readtable('patients.xls',opts);
whos T
8

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5 |
opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
01 |
numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';
9

Quy tắc thay thế

Quy trình để quản lý dữ liệu bị thiếu, được chỉ định là một trong các giá trị trong bảng này.

Thiếu quy tắcHành vi
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

34

Thay thế dữ liệu bị thiếu bằng nội dung của thuộc tính

T = readtable('patients.xls',opts);
whos T
4.

Thuộc tính

T = readtable('patients.xls',opts);
whos T
4 được chỉ định trong đối tượng
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

9 của biến được nhập. Để biết thêm thông tin về việc truy cập thuộc tính
T = readtable('patients.xls',opts);
whos T
4, xem
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

6.

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

40
Ngừng nhập và hiển thị thông báo lỗi hiển thị bản ghi và trường bị thiếu.
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

41
Bỏ qua các hàng có chứa dữ liệu bị thiếu.
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

42
Bỏ qua các biến có chứa dữ liệu bị thiếu.

Ví dụ:

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

43
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

43

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5

Quy trình để xử lý các lỗi nhập, được chỉ định là một trong các giá trị trong bảng này.

Nhập quy tắc lỗiHành vi
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

34

Thay thế dữ liệu bị thiếu bằng nội dung của thuộc tính

T = readtable('patients.xls',opts);
whos T
4.

Thuộc tính

T = readtable('patients.xls',opts);
whos T
4 được chỉ định trong đối tượng
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

9 của biến được nhập. Để biết thêm thông tin về việc truy cập thuộc tính
T = readtable('patients.xls',opts);
whos T
4, xem
ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

6.

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

40
Ngừng nhập và hiển thị thông báo lỗi hiển thị bản ghi và trường bị thiếu.
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

41
Bỏ qua các hàng có chứa dữ liệu bị thiếu.
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

42
Bỏ qua các biến có chứa dữ liệu bị thiếu.

Ví dụ:

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

43
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

55

Kiểu dữ liệu:

oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5
oneVar = readtable('patients.xls',opts);
whos oneVar
4 |
oneVar = readtable('patients.xls',opts);
whos oneVar
5

Quy trình để xử lý các lỗi nhập, được chỉ định là một trong các giá trị trong bảng này.

Nhập quy tắc lỗi

Thay thế dữ liệu nơi xảy ra lỗi với nội dung của thuộc tính

T = readtable('patients.xls',opts);
whos T
4.

Ngừng nhập và hiển thị thông báo lỗi hiển thị bản ghi và trường gây ra lỗi.

Bỏ qua các hàng nơi xảy ra lỗi.

Bỏ qua các biến nơi xảy ra lỗi.

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

Ví dụ:

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

55

oneVar = readtable('patients.xls',opts);
whos oneVar

  Name          Size            Bytes  Class    Attributes

  oneVar      100x1             12709  table              

Chức năng đối tượng

Ví dụ

sụp đổ tất cả

numVars = 7;
varNames = {'LastName','Gender','Age','Location','Height','Weight','Smoker'} ;
varTypes = {'char','categorical','int32','char','double','double','logical'} ;
dataStartLoc = 'A2';

Xác định các tùy chọn nhập cho biến trong tệp bảng tính

opts = spreadsheetImportOptions('NumVariables',numVars,...
                                'VariableNames',varNames,...
                                'VariableTypes',varTypes,...
                                'DataRange', dataStartLoc); 

Tạo một đối tượng Tùy chọn nhập để đọc một biến từ tệp

ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

58.

preview('patients.xls',opts)

ans=8×7 table
      LastName      Gender    Age              Location               Height    Weight    Smoker
    ____________    ______    ___    _____________________________    ______    ______    ______

    {'Smith'   }    Male      38     {'County General Hospital'  }      71       176      true  
    {'Johnson' }    Male      43     {'VA Hospital'              }      69       163      false 
    {'Williams'}    Female    38     {'St. Mary's Medical Center'}      64       131      false 
    {'Jones'   }    Female    40     {'VA Hospital'              }      67       133      false 
    {'Brown'   }    Female    49     {'County General Hospital'  }      64       119      false 
    {'Davis'   }    Female    46     {'St. Mary's Medical Center'}      68       142      false 
    {'Miller'  }    Female    33     {'VA Hospital'              }      64       142      true  
    {'Wilson'  }    Male      40     {'VA Hospital'              }      68       180      false 

Khởi tạo đối tượng

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
1, chỉ định tên biến, loại biến và ô bắt đầu dữ liệu. Sau đó, sử dụng chức năng
ans=8×1 table
    LastName
    ________

    Smith   
    Johnson 
    Williams
    Jones   
    Brown   
    Davis   
    Miller  
    Wilson  

60 với đối tượng Tùy chọn nhập để xem trước dữ liệu.

T = readtable('patients.xls',opts);
whos T

opts = spreadsheetImportOptions; 
opts.VariableNames = 'LastName';
opts.VariableTypes = 'categorical';
opts.DataRange = 'A2';
preview('patients.xls',opts)
0

Nhập biến từ tệp.

  • Xác định các tùy chọn nhập cho nhiều biến trong tệp bảng tính

    • Tạo một đối tượng Tùy chọn nhập để đọc nhiều biến từ

      ans=8×1 table
          LastName
          ________
      
          Smith   
          Johnson 
          Williams
          Jones   
          Brown   
          Davis   
          Miller  
          Wilson  
      
      
      58.

    • Dựa trên nội dung của tệp của bạn, xác định số lượng biến, tên biến, loại biến và vị trí bắt đầu dữ liệu.