MATLAB Answers

Code to read files from ansys fluent and perform calculations

26 views (last 30 days)
Victor Albert
Victor Albert on 28 Jul 2020
Commented: Victor Albert on 26 Aug 2020
hello expert,
Am new to matlab. please i need help on how to generate a code that would claculate this equation.
D = C x P ^a x t^b
the vaues of a, b, c are constants with values c =3.62e-7; a =2.416; b = 0.785
the values of P and t are in a .txt file output in columns as attached. t represent time and p represent stress.
please your guidance will help alot
best regards,

  29 Comments

Victor Albert
Victor Albert on 5 Aug 2020
i am still having issues with this plot. can i seperate the files and resend
Rik
Rik on 26 Aug 2020
Why did you delete all your comments on your other question?
Just in case you try that same thing here, I'll make a complete copy of this thread on the Wayback Machine.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 28 Jul 2020
Edited: KSSV on 28 Jul 2020
Read about textscan.
fid = fopen('Myfile.txt','r') ;
S = textscan(fid,'%f %f\n','HeaderLines',4) ;
S = S{1} ;
fclose(fid) ;
S should be a n*2 matrix. Read baout textscan if the code is not working properly.

  6 Comments

Show 3 older comments
Victor Albert
Victor Albert on 28 Jul 2020
okay, i have tried it but the next line here is the feedback.
Victor Albert
Victor Albert on 28 Jul 2020
sir KSSV,
please does the above code takes the place of the below long piece of code. as earlier reported.
fidi = fopen('file3.xy,'rt');
st = fseek(fidi, 1, 'bof'); % Position File After First Line
k1 = 1; % Counter
while (st == 0) && (~feof(fidi)) % Test For End Of File Or Unsuccessful ‘fseek’ File Position
prtcl{k1} = textscan(fidi, '%f%f', 'Delimiter','\t', 'HeaderLines',4, 'CollectOutput',1);
st = fseek(fidi, 50, 'cof'); % Position File Pointer To Next Line After Stop
k1 = k1 + 1;
end
dpb
dpb on 28 Jul 2020
There's no point at all in using textscan on such a simple file format... importdata does it all on its own as shown above; readmatrix would also do it w/ just 'NumHeaderlines' as additional argument.
Your attempts at positioning a file with fseek are totally misguided -- fseek moves by BYTES not records; the file is not fixed-length records so you can't count characters reliably anyway and is probably tab delimited (altho I didn't open it to check; there's no need nor sense in pursuing that depth).
If you were adamant on using textscan, as KSSV says, "READ THE DOCUMENTATION!" and just fix the typo.
There's no point in giving advice/guidance if not going to pay any attention to it... :(

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!