Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个矩阵 ABC,它有 60 行和 120 列。根据另一个矩阵 X ,它是一个 120 条目长的数组,我想填充另一个矩阵,如下所示:
if X(i)=1第 i 列被添加到矩阵 ABC_Copy。 if X(i)=0第 i 列被跳过,循环继续。
if X(i)=1
if X(i)=0
很明显,我会从 1 迭代到 120,这是S表示 120 列的大小ABC。
S
ABC
我们如何在 matlab 中实现这一点,而不需要完全迭代并单独放置每个值?
您可以在 Matlab中使用逻辑数组进行索引:
ABC_Copy = ABC(:, X==1);