在MATLAB中删除多维数组中一组索引处的元素? [英] Remove elements at a set of indices in a multidimensional array in MATLAB?

查看:167
本文介绍了在MATLAB中删除多维数组中一组索引处的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含1000个元素(1000x3)的多维数组A.我有另一个向量,该向量具有要从此数组中删除的元素的索引位置.

I have a multidimensional array A with 1000 elements (1000x3). I have another vector with index positions of elements I want to remove from this array.

我尝试使用此A(indices) = []A(indices,:,:) = [],但是问题是结果更改了A的尺寸,所以如果indices有10个元素,我发现A的大小变为2990x1而不是990x3.任何人都可以建议如何删除在A中尺寸不变的A中具有indices的元素仍然是n x 3?

I've tried using this A(indices) = [] or A(indices,:,:) = [], but the problem is that the result changes A's dimension, so if indices has 10 elements, I find A's size become 2990x1 instead of 990x3. Anyone can advise how to remove the elements having the indices in A where A's dimensions won't change will still be n x 3?

推荐答案

您可以使用逻辑索引以过滤矩阵,例如

You can use logical indexing to filter the matrix, for example,

A=rand(1000,3);
A(A(:,1)>0.9)=[];

删除第一列中值大于0.9A行.

which removes the rows of A that have a value greater than 0.9 in the first column.

我不确定您原来的方法为什么不起作用.

I'm not sure why your original approach didn't work though.

这篇关于在MATLAB中删除多维数组中一组索引处的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆