필터 지우기
필터 지우기

how to load and calculate data from a file?

조회 수: 6 (최근 30일)
P
P 2011년 4월 16일
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
Oleg Komarov
Oleg Komarov 2011년 4월 16일
Did you try Matt's solution at all?

댓글을 달려면 로그인하십시오.

추가 답변 (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