我正在編寫一個代碼來檢查Bipolar-RZ。如果你得到一個0,沒有任何事情發生,但如果有一個,那麼轉換髮生在中間,從正電壓到0,然後從負電壓到0電壓。 所以我接觸到這個的方式是,例如,如果你有b=[0 1 0 1 1 0 1]
。你計算你有多少人。然後你將這些放入for循環並添加它們。然後使用if語句檢查添加後的數字是偶數還是奇數,然後轉換。 問題是我正在使用另一個for循環,for循環(檢查偶數和奇數)進入另一個for循環。使用嵌套for循環並檢查數字是偶數還是奇數
也使用iseven和isodd,我在網上搜索。他們有MATLAB中的代碼。否則,該功能不起作用。這裏是鏈接:http://www.mathworks.com/matlabcentral/fileexchange/35105-isevenisodd
如果有人回覆,我會非常棒。 謝謝
% for ibs, I'm using ibs=[0 1 0 0 1 1 0 0 0 1 1]
function output = lc_bi(ibs,tlc, Rb)
output=1;
numofbits=length(ibs);
% Bipolar RZ coding
if isequal(tlc,'RZ')
%for loop to calculate 1's
y=0;
for k=1:length(ibs)
if ibs(k)==1
y=y+1;
end
end
oness=ones(1,y); %converting it in to list of ones
samptime= 0.001;
endtime= numofbits-samptime;
t=0:samptime:endtime;
cycle= floor(length(t)/(numofbits-1));
j=1;
tran_in_middle= j+cycle/2;
bit=1;
for i=0:samptime:endtime
if (floor(i)+1 ~=bit)
tran_in_middle=j+cycle/2;
bit=bit+1;
end
if (ibs(bit)==1)
if(j< tran_in_middle)
%put the loop her to check if itseven or odd
%using the list of ones here and adding them to check for even and odd
g=0;
for h=1:length(oness)
g=g+1;
if isodd(g)==true
s(j) =Rb;
disp('+')
elseif isodd(g)==false
s(j)=-Rb;
disp('-')
end
end
else
s(j) = 0;
end
end
j=j+1;
end
plot(t,s);
axis([0 numofbits -(Rb+1) (Rb+1)]);
xlabel ('Time');
ylabel ('Voltage');
end
這裏有很多代碼,但沒有指出問題出在哪裏。破解你想要做的事情也很困難。也許你可以爲你的示例輸入提供一個示例輸出? – Dan