Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab Scilab存储到阵列中[通道编码]_Matlab_Scilab - Fatal编程技术网

Matlab Scilab存储到阵列中[通道编码]

Matlab Scilab存储到阵列中[通道编码],matlab,scilab,Matlab,Scilab,这是我代码的一部分 e=0; c=0; n=10000; for t=zeros(1:n) //state1 x=rand(); if(x<=0.95) then disp(t); c=c+1; elseif(x>0.95) //state2 x=rand(); if(x<=0.99) then disp(t) c=c+1; //state3 elseif(x>0.99) then disp(t=1) e=e+1; arr(e)=t; /

这是我代码的一部分

e=0;
c=0;
n=10000;

for t=zeros(1:n)
//state1
x=rand();
if(x<=0.95) then disp(t);
    c=c+1;
elseif(x>0.95)
//state2
x=rand();
if(x<=0.99) then disp(t)
    c=c+1;
//state3
elseif(x>0.99) then disp(t=1)
    e=e+1;
    arr(e)=t; //store error bits only



end
end
end
disp(c);
disp(e);
for z=1:e //loop the earlier arr(s)
disp(arr(z)) //display all arr of s
end

clear();
但我想要的是这样的东西

arr[1] = 0
.
.
.
arr[250] = 1 
.
.
.
arr[749] = 1 
.
.
.
arr[1234] = 1 
.
.
.
arr[5463] = 1 
.
.
.
arr[6678] = 1 
.
.
.
arr[8890] = 1 
.
.
.
arr[9987] = 1 
.
.
.
arr[10000] = 0     
显示错误位出现在2507491234546667888909987

谢谢你

你所要做的就是:

e = [250 759 1234 5463 6678 8890 9987];
arr = zeros(10000,1);
arr(e) = 1;

e
定义要将
arr
中的值更改为1的位置。您只需使用
e
索引到
arr
,并将相应的位置设置为1。就这样。。。没什么大不了的

但是2507491234546667888909987处的数组只是一个随机位置..下次我再次运行代码时..数组位置可能会有所不同。。。确保这些位置存储在
e
。。。。然后执行上面的代码。您说过您有这些位置,它们存储在
e
。。。。所以使用
e
并索引到
arr
。无论您如何生成位置,请确保它们存储在
e
中。你想让我解释得简单多少?
e = [250 759 1234 5463 6678 8890 9987];
arr = zeros(10000,1);
arr(e) = 1;