如何在MATLAB中删除标量结构?

时间:2014-11-24 02:20:00

标签: matlab

我有这个代码可以过滤文件并加载它们来创建这个奇怪的单元格(2D内部的2D?)数组。我最后需要一个包含所有这些数字的向量。有没有办法摆脱这些层并将其压缩,无论是在循环中还是在事后?

slopes = dir('*Slope.m');%find all the files containing the name slope
num = numel(slopes);
file = cell(1,num); %Preallocate
for k = 1:num
    file{k} = slopes(k).name;   %taking name from file and making list
    final{k}=load(file{k}) %loading contents of each file
end 

ans= 
    final = 
    {
      [1,1] =

        scalar structure containing the fields:

          Slope = 
          {
            [1,1] =

              -1.1921
              -1.0496
              -1.5440
              -8.0588
              -1.5505
              -2.0916
              -1.8253
               1.5526
               2.8496

          }

      [1,2] =

        scalar structure containing the fields:

          Slope = 
          {
            [1,1] =

              -1.2797
              -1.0386
              -2.7018
              -2.4564
              -1.5939
              -2.6885
              -1.2366
               2.0501

          }

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我确信这已经被多次回答了,但它只是matlab中常见的一个内容:

flat_final = [final{:}]

为了使答案更加完整,您可以使用horzcatvertcatreshape来微调您的搜索结果。

您的任务的技术术语是展平,因此如果您搜索它,您可能会发现更多代码段。

相关问题