Effacer les filtres
Effacer les filtres

how to load and calculate data from a file?

6 vues (au cours des 30 derniers jours)
P
P le 16 Avr 2011
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?

Réponse acceptée

Matt Tearle
Matt Tearle le 16 Avr 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 commentaires
P
P le 16 Avr 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 le 16 Avr 2011
Did you try Matt's solution at all?

Connectez-vous pour commenter.

Plus de réponses (2)

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

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by