【问题标题】:Delete a cell array column删除元胞数组列
【发布时间】:2011-09-07 01:38:05
【问题描述】:

将简单值放入元胞数组中进行测试。

model{1,1}=1;model{1,2}=2;model{1,3}=3;
model{2,1}=4;model{2,2}=5;model{2,3}=6;
i=2;//I want to remove the second column

temp={  model{:,1:i-1} model{:,i+1:size(model,2)}  }

我想要这样的结果:

温度 =

[1]    [3]    
[4]    [6]

但我明白了:

温度 =

[1]    [4]    [3]    [6]

我怎样才能做到这一点?

p.s:对于任何从事 Cell Arrays 工作的人,有一个很好的附加 here 的技术。

【问题讨论】:

    标签: matlab cell-array


    【解决方案1】:

    你必须转置这两部分,并改变一些括号:

    temp= [{ model{:,1:i-1}}' {model{:,i+1:size(model,2)}}']
    

    【讨论】:

    • 如果您在要删除的列之前或之后有多个列,则此方法不起作用
    【解决方案2】:

    您可以使用 () 寻址来重塑或删除单元格本身。

    model(:,2) = [];
    

    【讨论】:

    • 这太酷了!!!!我喜欢将 MATLAB 设计得如此优雅的天才!
    • 那将是 Matlab 的原作者 Cleve Moler 博士。 :) en.wikipedia.org/wiki/Cleve_Moler
    【解决方案3】:

    有一个名为 fun_removecellrowcols 的函数,用于删除用户指定的特定行/列。由于行/列移除,这会影响单元格的尺寸。

    http://www.mathworks.com/matlabcentral/fileexchange/46196-fun-removecellrowcols

    问候, 何塞

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      • 2016-10-26
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多