Azzera filtri
Azzera filtri

how to load and calculate data from a file?

6 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Matt Tearle
Matt Tearle il 16 Apr 2011
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 Commenti
P
P il 16 Apr 2011
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
Oleg Komarov
Oleg Komarov il 16 Apr 2011
Did you try Matt's solution at all?

Accedi per commentare.

Più risposte (2)

Andrei Bobrov
Andrei Bobrov il 16 Apr 2011
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 il 17 Apr 2011
Thx a lot guys,my programing skills are low but I promise I'll learn!

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by