在matlab中更改dec2bin以获取逻辑向量 [英] change dec2bin in matlab to get a logical vector

查看:180
本文介绍了在matlab中更改dec2bin以获取逻辑向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在Matlab中获取dec2bin变量的快速方法,以使其返回逻辑变量向量.例如,给定数字n=8,输出将为[1,0,0,0]. 我该怎么办?

I'm looking for a quick way to get a variat of dec2bin in Matlab such that it'll return a logical variable vector. For example given a number n=8 the output will be [1,0,0,0]. How can I do that?

推荐答案

最简单的方法是爆炸dec2bin返回的二进制表示形式(已经是一个字符串!):

The simplest way is to simply explode the binary representation returned by dec2bin (which is already a string!):

dec2bin(n) == '1'

对于n = 8,这将返回逻辑向量

For n = 8 this returns a logical vector

1     0     0     0

如果n是数字向量,这也将起作用.

This will also work if n is a vector of numbers.

这篇关于在matlab中更改dec2bin以获取逻辑向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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