Undefined function 'diag' for input arguments of type 'cell'.

I am trying to run a code given by Felipe Uribe Castillo
%%% function to generate c_ijk with dimension M and order p
%% using symbolic toolbox
function c = c_ijk_sym(M,p)
M=3
p=1
%% Define the number of RVs in sym
x = cell(1,M);
for j = 1:M
x{j} = sym(sprintf('xi_%d',j));
end
%% Generate Hermite pols using the ’Hermite_PC’ function
%% defined in Section 3.4 of this document
[~,Psi,PsiSqNorm,P] = Hermite_PC(M,p)
%% Procedure
dw = @(x) exp(-0.5*x^2)/sqrt(2*pi); %% Gaussian measure
c = cell(M,1)
c{1} = diag(PsiSqNorm); %% c_{0jk}
tic;
for i = 1:M
c{i+1} = sparse(P,P);
for j = 1:P
for k = 1:P
msg = fprintf('C_{%d,%d,%d}',i,j,k);
cijk = x{i}*Psi{j}*Psi{k};
for l = 1:M
cijk = int(cijk*dw(x{l}),x{l},-inf,inf);
if cijk == 0
break;
end
end
c{i+1}(j,k) = double(cijk);
fprintf(repmat('\b',1,msg));
end
end
end
toc;
return;
I am getting the following error:
Undefined function 'diag' for input arguments of type 'cell'.
Error in c_ijk_sym (line 20)
c{1} = diag(PsiSqNorm); %% c_{0jk}
please help.

댓글 수: 1

The error message is pretty clear, isn't it ?
"diag" cannot be applied to a variable of type "cell", and "PsiSqNorm" seems to be of this type.

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

 채택된 답변

Walter Roberson
Walter Roberson 2022년 5월 11일

0 개 추천

https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/53276/versions/1/previews/ssfem_eb_beam/Hermite_PC.m/index.html
The output PsiSqNorm is the fifth output of that function, but your named output with that name is the fourth output of the call.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2022년 5월 11일

답변:

2022년 5월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by