how to load and calculate data from a file?
3 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Matt Tearle
on 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 Comments
More Answers (2)
Andrei Bobrov
on 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);
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!