[MATLAB] Experiment 1: The division of matrix data

Experimental steps

1. Understand the role of each part of the MATLAB work window

(1) Command line window
You can enter various commands, functions and expressions here.

(2) Work area
Display the variable name, data structure, number of bytes and data type of all MATLAB variables in the current memory.

(3) Homepage
You can open script files, function files and other files here.

(4) Path line
Display the current file path (default is MATLAB installation path).

2. Assignment of vector, matrix, and array (loop statement)

(See code section)

3. View the contents of vectors and matrices

Click variable

4. Write script, call script, add comment line in script

(See code section)

5. Two divisions of matrix data

a=mat(:,50:end)
b=mat(:,[1:10 20 200:end])
6. Save data
save()

Data recording and processing:

1. Script file code:

clear,clc%清空变量和命令窗口
%load()%加载变量
A=rand(500,1000);%随机生成500*1000的矩阵,样本数量为1000,每个样本的维度为500
for i=1:50 %矩阵进行50次划分
    num1=randperm(1000);%对1到1000的1000个数字进行随机排列    
    A1=A(:,num1(:,1:500));%对1000个样本进行随机划分,随机500个为样本1,剩下的为样本2
    A2=A(:,num1(:,501:end));
    AA1{
    
    1,i}=A1;%AA1为一个数组cell,存放第一个样本
    AA2{
    
    1,i}=A2;%存放第二个样本
end

2. Key understanding

(1) randperm(1000)
randomly arrange 1000 numbers from 1 to 1000.
(2) A(:,num1(:,1:500))
takes all rows of matrix A and num1(:,1:500) columns The data; or understand that each column vector is a sample, and the number of column vectors is the number of samples.
(3) AA1{1,i}=A1
AA1 is an array cell, and each divided sample is sequentially stored in the array cell.

Guess you like

Origin blog.csdn.net/qq_45617555/article/details/108372659