how to load and calculate data from a file?

6 次查看(过去 30 天)
Hi I really need help.I have this file udk.txt with 21 values. I've loaded the values from it and i need to calculate idk for each value given in the txt. This is my attempt:
*clear all;
Is=1E-9;
k = 1.38*10^(-23);
q = 1.602*10^(-19);
T = 300;
VT = k*T/q;
m = 1.5;
x=load('F:\udk.txt');
for i = 1:21
idk=Is*(exp(x(i)/(m*VT))-1);
end
So, how can I calculate 21 values for idk if in txt file are 21 values for udk?

采纳的回答

Matt Tearle
Matt Tearle 2011-4-16
If x is a vector of 21 values (and all the other values are scalars), then all you need to do is
idk=Is*(exp(x/(m*VT))-1);
(Your loop would also work, but is unnecessary.) So given that you're asking, I'm guessing that this isn't working. So, what's going wrong? Do you get an error message? If so, what? What is the size of x (do >> whos x and report the output)? If x is not 1-by-21 or 21-by-1, then the problem is in the load command. In which case, please show the contents of udk.txt. Reading a text file with load requires that the formatting of the file is very simple.
  2 个评论
P
P 2011-4-16
udk.txt contains:0.000E+00
-1.000E+01
-1.000E+01
-1.000E+01
-1.000E+01
-1.000E+01
-1.000E+01
-1.000E+01
-1.000E+01
-9.999E+00
-9.999E+00
-9.999E+00
5.427E-04
5.499E-04
5.499E-04
5.499E-04
5.499E-04
5.499E-04
5.499E-04
5.499E-04
5.495E-04
And my program only calculate one value for idk, an i want 21 values for each udk. thx a lot for your time and i hope that you can help me

请先登录,再进行评论。

更多回答(2 个)

Andrei Bobrov
Andrei Bobrov 2011-4-16
variant
Is=1E-9;
k = 1.38*10^(-23);
q = 1.602*10^(-19);
T = 300;
VT = k*T/q;
m = 1.5;
x=cell2mat(textscan(fopen('txt_for_P.txt'),'%f'));
idk=Is*(exp(x/(m*VT))-1);

P
P 2011-4-17
Thx a lot guys,my programing skills are low but I promise I'll learn!

类别

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