ERROR: Undefined function 'sum' for input arguments of type 'cell'. Kindly help me resolve the error.

ERROR:
Undefined function 'sum' for input arguments of type 'cell'.
Error in PSCCandPSSCoptiWdVss (line 45)
p=sum(arrayfun(@(x) x*wdwd, 1:2*N, 'un', 0));
CODE:
clear all;
close all;
d=1;
f=9*10^6;
w=2*pi*f;
u=4*pi*(10^-7);
N=15
%ro=1.72*(10^-8); %copper
ro=0.0005 % Resistance
dout=0.15
t=0.000035
wd=[0.005 0.006 0.007 0.008]
s=[0.006 0.007 0.008 0.009]
%Saad Mutasgar
[wdwd,ss]=meshgrid(wd,s);
C1=1
C2=2.46
C3=0
C4=0.2
din=dout-(2*N*wdwd)-((2*N-2)*ss)
rout=dout/2
rin=din/2
U=2;
phi=(dout-din)/(dout+din)
davg=0.5*(dout+din)
L0=((C1.*u.*N.*N.*davg)./2).*(log(C2./phi)+(C3.*phi)+(C4.*phi.*phi))
M_cir=((u.*N.*(dout.^2).*N.*(dout.^2).*pi)./(2.*sqrt(((dout.^2)+(d.^2)).^3)))
syms x
p=sum(arrayfun(@(x) x*wdwd, 1:2*N, 'un', 0));
q=sum(arrayfun(@(x) x*ss, 1:((2*N)-1)))

 채택된 답변

KSSV
KSSV 2019년 4월 30일
편집: KSSV 2019년 4월 30일
Use
p = cellfun(@sum,arrayfun(@(x) x*wdwd, 1:2*N, 'un', 0),'un',0) ;
instead:
p=sum(arrayfun(@(x) x*wdwd, 1:2*N, 'un', 0));
As the output is cell...you need to use cellfun like arrayfun.

댓글 수: 3

I tried this. Am getting error in the consecutive line.
CODE:
syms x
p = cellfun(@sum,arrayfun(@(x) x*wdwd, 1:2*N, 'un', 0),'un',0 ) ;
q = cellfun(@sum,arrayfun(@(x) x*ss, 1:((2*N)-1), 'un', 0),'un',0 ) ;
l=(pi/2)*((2*N*din)+p+q)
ERROR:
Error using +
Matrix dimensions must agree.
Error in PSCCandPSSCoptiWdVss (line 52)
l=(pi/2)*((2*N*din)+p+q)
I want p and q values to be array of numbers in matrix format but am not getting it.
That case convert the cells into your desired matrix and add them.

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

추가 답변 (1개)

% remove syms x
p = sum(cell2mat(arrayfun(...))) % same goes for q

댓글 수: 3

I tried this. Am getting error in the consecutive line.
CODE:
syms x
p = sum(cell2mat(arrayfun(@(x) x*wdwd, 1:2*N, 'un', 0)))
q = sum(cell2mat(arrayfun(@(x) x*ss, 1:(2*N)-1, 'un', 0)))
l=(pi/2)*((2*N*din)+p+q)
ERROR:
Error using +
Matrix dimensions must agree.
Error in PSCCandPSSCoptiWdVss (line 52)
l=(pi/2)*((2*N*din)+p+q)
I want p and q values to be array of numbers in matrix format but am not getting it.
Well, it’s pretty obvious, your trying to add 120 elements with 116 elements, so it’s your call now.
bsxfun(@plus,p(:),q)
Also I believe I have answered the question you originally asked. I suggest you to do MATLAB on-ramp course to cover the fundamental basics of MATLAB.
Thank you for your response and suggestion.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2019년 4월 30일

편집:

2019년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by