Delete a cell array column

倾然丶 夕夏残阳落幕 提交于 2019-12-06 07:18:13

问题


Placed simple values into the cell array for testing.

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)}  }

I wanted a result like this:

temp =

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

But I'm getting this:

temp =

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

How can I get this right?

p.s: for anyone working on Cell Arrays, there's a nice technique for appending here.


回答1:


You can reshape or delete the cells themselves using ()-addressing.

model(:,2) = [];



回答2:


You have to transpose the two pieces, and change some parentheses:

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



回答3:


there is a function called fun_removecellrowcols, which removes specific row/columns indicated by the user. This affects the dimensions of the cell, due to the row/cols removal.

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

Regards, José



来源:https://stackoverflow.com/questions/6214721/delete-a-cell-array-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!