필터 지우기
필터 지우기

Unknown variable with str2num ?

조회 수: 5 (최근 30일)
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY 2019년 4월 24일
답변: KSSV 2019년 4월 24일
%% Sir I am using a matlab code but I got a error here I am showing the main file only and error
function sigmaDloop(sb)
b=str2num(sb);
lmat=[1 20; 21 29; 30 36; 37 42; 43 47; 48 51; 52 55; 56 58; 59 61];
l1=lmat(b,1);
l2=lmat(b,2);
maxNumCompThreads(1);
T=70;
dimpP=20e-9;
dimpA=10e-9;
hbar=1.054571800e-34;
vf=1.1e6;
kB=1.38064852e-23;
nimp=5e14; %nimp= 5 x 10^10 cm^-2.
dspacer=9e-9;
nA=[0:1:20 22:2:100]; %in units of 10^10 cm^-2.
nP=nA;
EF=hbar*vf*sqrt(pi.*nA.*1e14);
TF=EF./kB;
mutildeA=Fmu(T./TF).*EF./(kB.*T);
mutildeP=mutildeA;
sigmadrag=zeros(length(mutildeP),length(mutildeA));
kB=1.38064852e-23;
hbar=1.054571800e-34;
vf=1.1e6;
dspacertilde=kB.*T.*dspacer./(hbar.*vf);
save(['sigmadragvals' num2str(b) '.mat'],'T','nA','nP','mutildeA','mutildeP','sigmadrag','dspacertilde','EF','TF');
for j=l1:l2
for k=1:j
diary(['sigmaDs' num2str(b) '.txt']);
tic
sigmadrag(j,k)=sigmaDtilde2d(dspacertilde,mutildeA(k),mutildeP(j))
toc
save(['sigmadragvals' num2str(b) '.mat'],'T','nA','nP','mutildeA','mutildeP','sigmadrag','dspacertilde','EF','TF','-append');
diary off;
end
end
end
%% and now error as
sigmaDloop
sb =
1
Error using str2num (line 32)
Requires string or character array input.
Error in sigmaDloop (line 7)
b=str2num(sb);
%% please give suggestion of this
  댓글 수: 1
Stephen23
Stephen23 2019년 4월 24일
The input sb is numeric, not a string or a character vector. Thus the error.

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

답변 (1개)

KSSV
KSSV 2019년 4월 24일
Read about str2num. It takes string as input and conerts it to number. If the input is not string it will throw error like in your case.
str2num('2') % no error '2' is string
str2num(2) % error, 2 is number not a string
In your case, your input sb is not a string.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by