CHANGEM(替代值)的优雅量化版本 - MATLAB [英] Elegant vectorized version of CHANGEM (substitute values) - MATLAB

查看:273
本文介绍了CHANGEM(替代值)的优雅量化版本 - MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab的2012b,有一个 changem 功能,可以替代由一组键指定其他值矩阵的元素:
<一href=\"http://www.mathworks.com/help/map/ref/changem.html;jsessionid=7bc502fa8e3b3db2dde50adb52bc\">Substitute值数据数组

In Matlab 2012b, there is a changem function that allows you to substitute elements of a matrix with other values specified by a set of keys: Substitute values in data array

有一种优雅/矢量化的方式做同样的,如果我没有映射工具箱?

Is there an elegant/vectorized way to do the same if I don't have the Mapping toolbox?

推荐答案

是,使用 ismember

A       = magic(3);
oldCode = [ 8  9];
newCode = [12 13];

[a,b] = ismember(A,oldCode);

A(a) = newCode(b(a));

我不知道 changem ,我怀疑上面不会完全覆盖其功能(否则为什么TMW纷纷出台 changem ?),但远,但它确实你问:)

I don't know changem, and I suspect the above will not fully cover its functionality (why else would TMW have introduced changem?), but well, it does what you asked :)

这篇关于CHANGEM(替代值)的优雅量化版本 - MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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