在Matlab上的二进制数据 [英] Working on Binary Data in Matlab
问题描述
我已加载在MATLAB中的文本文件测试文件。负载的功能现在已经创建了一个变量测试
与值
I have loaded a text file test file in matlab. The load function has now created a variable test
with values
1 2 3 4 5
2 3 NaN NaN NaN
现在我有一个初始化的变量 X = [0 0 0 0 0 0 0 0 0 0 0]
和 Y = [0 0 0 0 0 0 0 0 0 0 0]
。
我想 X
读测试
变量的第一个行和与之对应的读取改变其元素的值数从 0
到 1
。假设它读 1
,就应该改变其元素 X(1)
从 0
到 1
。同样是
应该做同样的WRT第二行测试
。
Now I have a initialized variable X = [0 0 0 0 0 0 0 0 0 0 0]
and Y = [0 0 0 0 0 0 0 0 0 0 0]
.
I want X
to read the first row of test
variable and corresponding to the number it reads change its value of the element from 0
to 1
. Suppose it reads 1
, it should change its element X(1)
from 0
to 1
. Similarly Y
should do the same wrt second row of test
.
任何想法,我应该怎么进行呢?
Any idea how should I proceed?
推荐答案
您可以索引直接进入像这样一个向量:
You can index directly into a vector like so:
x=zeros(1,10);%# your zero vector
a=[1,3,7,8]; %# the index of sports you like
x(a)=1 %# change from 0 to 1
x =
1 0 1 0 0 0 1 1 0 0
这是您的评论去,我觉得这是你想要的。
Going by your comment, I think this is what you want.
这篇关于在Matlab上的二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!