matlab中 怎么将向量特定的数变为1

matlab \u4e00\u5217\u5411\u91cf\uff0c\u9664\u4e86\u5176\u4e2d\u67d0\u4e00\u6570\u503c\u5176\u4ed6\u6570\u503c\u5168\u90e8\u6539\u4e3a0

\u7b80\u5355\u3002
\u6bd4\u5982\u8fd9\u4e2a\u5411\u91cf\u53eba\uff0c\u6709100\u4e2a\u6570\uff0c\u4f60\u627e\u5230\u4e86\u8fd9\u4e2a\u6570\u503c\u7684\u4f4d\u7f6e\u4e86\u5427\uff0c\u6bd4\u5982\u7b2c 10\u4e2a\uff0c\u7136\u540e\u628a\u5176\u4ed6\u6570\u53d8\u4e3a0\uff0c\u90a3\u5c31\u662f
a(1:9)=0;
a(11:100)=0;

\u90a3\u8fd8\u4e0d\u7b80\u5355\uff1f
\u81ea\u5df1\u8bbe\u8ba1\u4e00\u4e2a\u4e8c\u8fdb\u5236\u52a0\u6cd5\u5457
clc
clear
x=[0 1 0 0 1 0 0 1];

[m,n]=size(x);
if x==1
disp("error");
else
x(n)=x(n)+1;
for i=n:-1:1
if x(i)>1
x(i-1)=x(i-1)+1;
x(i)=0;
end
end
end
x
\u6211\u8fd9\u91cc\u6ca1\u6709matlab\u73af\u5883\u3002
\u4f60\u81ea\u5df1\u8bd5\u8bd5

>> a=[1 2 3];
>> b=[5 2 3 1 4];
>> [c,ia,ib]=intersect(a,b) %求两个向量的交集
c =
1 2 3
ia =
1 2 3 %交集在a中的地址
ib =
4 2 3 %交集在b中的地址
>> b(ib)=0 %b向量中和a相同的赋值为0
b =
5 0 0 0 4
>>

扩展阅读:matlab生成全1向量 ... matlab中连续列向量 ... matlab向量变成矩阵 ... matlab 求特征向量 源码 ... matlab怎么将向量正交化 ... matlab怎么输出向量 ... matlab plot向量长度 ... matlab中向量点乘运算 ... matlab中向量的模怎么表示 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网