Borrar filtros
Borrar filtros

Unknown variable with str2num ?

5 visualizaciones (últimos 30 días)
SHARAD KUMAR UPADHYAY
SHARAD KUMAR UPADHYAY el 24 de Abr. de 2019
Respondida: KSSV el 24 de Abr. de 2019
%% 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 comentario
Stephen23
Stephen23 el 24 de Abr. de 2019
The input sb is numeric, not a string or a character vector. Thus the error.

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 24 de Abr. de 2019
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.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by