我是Matlab的新手,我正在努力创建一些矩阵 . 我需要编写一个读取文本文件的循环,然后将每组整数分配给具有特定数字的变量,例如行的# . 之后它将执行一些计算,然后最终在矩阵1xn中连接数组,但我遇到的是读取文件然后将其分配给动态变量然后递增计数器的过程 . 我认为我有伪代码的正确逻辑,但我正在努力与MATLAB中的实际语法能够做到这一点 .

有点混合的伪代码和我设法编写的实际代码:

content= fopen('text file.txt');

for i=1:size(content,1) *%loop to read till the end of the matrix* 

    variable_part(i) = fgetl(fid); *%read row and create the integer value in the dynamic variable.*

    for i=1 *% loop through the matrix that contains all the created dynamic variables one by one and perform these.* 
         for i=1:size(variable_part(i),1)
             a= variable_part(i)(i,:);
                variable_part(i,1)= mean(a);
                variable_part(i,2)= min(a);
                variable_part(i,3)= max(a);
                variable_part(i,4)= std(a);
                variable_part(i,5)= var(a);
                variable_part(i,6)= max(a)-min(a);
          end;
     end;
end;

因此,例如结果将如下:

content = (27*1) matrix.

%First loop 
for i=1:size(content,1) *%loop to read till the end of the matrix* 
variable_part1 = 4835:5551; *%first variable created and was assigned with the value of the first row. 
%Second Loop 
      for i=1 %in the matrix that contain all the variables created in the first loop 
%Third loop
 for i=1:size(variable_part1,1)
                 a= variable_part1(1,:);
                    variable_part(1,1)= mean(a);
                    variable_part(1,2)= min(a);
                    variable_part(1,3)= max(a);
                    variable_part(1,4)= std(a);
                    variable_part(1,5)= var(a);
                    variable_part(1,6)= max(a)-min(a);
              end;
         end;
    end;

我知道第三个循环的结果正在工作并产生我想要的但我的问题是在Read文本文件和前两个嵌套循环中 .

我很感激帮助 .