필터 지우기
필터 지우기

Function definitions are not permitted in this context.

조회 수: 2 (최근 30일)
Vu
Vu 2024년 4월 24일
댓글: VBBV 2024년 4월 24일
help me
Function definitions are not permitted in this context.
  댓글 수: 1
VBBV
VBBV 2024년 4월 24일

Note also that your function outputs three arguments , code, xq, sqnr which you need to concatenate [ ] , inside the function

댓글을 달려면 로그인하십시오.

답변 (1개)

VBBV
VBBV 2024년 4월 24일
편집: VBBV 2024년 4월 24일

Rename the file ok.m to uniform_pcm.m and save file. Type the name of function from command window (giving input arguments) and execute.

  댓글 수: 13
Vu
Vu 2024년 4월 24일
i don't know why my code not work
VBBV
VBBV 2024년 4월 24일
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
% put this code in script file & name it as ok.m (valid filename)
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
clc ;
clear all;
T=1/20*pi
t=0:T:1;
x = cos(20*pi*t+pi/2) + 3*sin(10*pi*t) + 5*cos(15*pi*t+pi);
[code,xq] = uniform_pcm(x,64) % call the function inside ok.m
% ----------------------------------
% >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
% name this file separate as uniform_pcm.m but inside the same folder where
% ok.m is located
% >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function [code,xq] = uniform_pcm(x,M)
Nb=log2(M);
Amax =max(abs(x));
delta=2*Amax/(M-1);
Mq=-Amax:delta:Amax;
M1=0:M-1;
xq= zeros (size(x));
xcode = xq;
for k=1:M
ind =find(x > Mq(k) - delta/2 & x<= Mq(k) + delta/2);
xq(ind)= Mq(k);
xcode (ind) = M1(k) ;
end
code = de2bi (xcode, Nb, 'left-msb');
[code,xq.'];
end
% what is sqnr variable ... that is not seen anywhere in your code, yet you
% want it as output ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by