Code to read files from ansys fluent and perform calculations
Show older comments
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
dpb
on 28 Jul 2020
See doc on importdata, readmatrix, etc., ... plenty of examples for simple text files...
Use the "dot" operators for element-wise arithmetic operations and just write the equation as it stands.
There's also much "Getting Started" doc that illustrates...
Victor Albert
on 28 Jul 2020
"do you mean."
Well, no, not really.
We can't do anything with images and the filename in the image is a .xls file which isn't text, but...that's not the filename you use above, either. We've no klew really, but--using the image as a guess as to what the file contains
fnD=@(t,P) 3.62e-7*P.^2.416.*t.^0.785; % set anonymous function for "D"
data=importdata('file3.xy');
data=data.data; % dereference the struct data field to array
D=fnD(data(:,1),data(:,2));
...
Do whatever w/ the results after...
Doesn't look like you had done any reading on anything I suggested earlier...
PS: If would want somebody to really look at, attach the input data file; as noted, there's nothing anybody can do with an image other than just look at it.
Victor Albert
on 28 Jul 2020
Victor Albert
on 28 Jul 2020
dpb
on 28 Jul 2020
data=importdata('scalarvstime1.txt');
I so rarely use importdata I forgot it returns a struc with the actual numeric data in the field data. So, first have to dereference it to get the actual data array.
>> PT=data.data; % the t,P data array
>> whos PT
Name Size Bytes Class Attributes
PT 4009x2 64144 double
>> PT(1:10,:) % looks like |importdata| found the right start point on its own...
ans =
0 0.2910
0.0000 0.2911
0.0001 0.2953
0.0001 0.2980
0.0002 0.2795
0.0002 0.2663
0.0003 0.2894
0.0004 0.3020
0.0005 0.2810
0.0005 0.2731
>> figure
>> plot(PT(:,1),PT(:,2))

is P vs t.
Somethings seems to be amiss with the time vector -- it's not monotonically increasing it appears -- can check on that easily enough--
>> find(diff(PT(:,1))<=0)
ans =
165
330
419
573
830
1145
1305
1471
1642
1811
1976
2137
2604
2770
2931
3093
3250
3421
3599
3793
>>
So, what are we to do about the time? Are there different transients in the file, is the output interwoven by time by some other variable so should sort() on time and rearrange, ...???
We "know nuthink!" to quote Sgt Schultz about what is in the file...
tz=find(PT(:,1)==0); tz=[tz;size(PT,1)]; % get the zero time points in file; augment numel
figure,hold on % prepare to plot traces on new figure
for i=1:2:numel(tz)-1 % every other sequence starting t==0
t1=tz(i); t2=tz(i+1)-1; % look up the time points start, end
hL(i)=plot(PT(t1:t2,1),PT(t1:t2,2)); % and plot P vs t for segment
end
hAx.YScale='log'; % so can separate visually
ylim([0.01 25])
grid on
hLg=legend(compose('Section %d',[1:numel(tz)/2].'),'Location','southeast');
results in

So, there are 20 different traces in the one file, each beginning at t=0.
The above plot is every other one of the 20; 1,3,5,...
What they are we've no klew; only you know what you have in the simulation.
ADDENDUM/ERRATUM:
Actually, as noted below there are 20 different time traces in the file, not 10; the above is every other one; the plot is far too busy to try to show all 20. The legend should have been
hLg=legend(compose('Section %d',[1:2:numel(tz)].'),'Location','southeast');
so the sections are really 1,3,5,...
Victor Albert
on 28 Jul 2020
Victor Albert
on 28 Jul 2020
dpb
on 28 Jul 2020
The above plots ARE what is contained in the file -- the first blue line is all of P vs t on one graph -- it clearly demonstrates the discontinuity in the time trace.
The table below it shows the points in the file at which time is reset to zero; there are 20 of those in the file; I plotted the data P vs t for every other one of those sections in the subsequent figure.
I showed you above how to compute D from the given t,P; that won't be affected by the discontinuity in the time vector but it will ALWAYS have a discontinuity on a time axis if you don't separate out where in the file the time measurement starts over again.
Again, we don't know anything else; all we can do is read the file and show what's in it--what it means (if anything) is beyond our ken or ability to do anything else.
You're not going to get a plot that looks anything at all like your sample from these data, though...just not agonna' happen.
Victor Albert
on 28 Jul 2020
dpb
on 28 Jul 2020
The P, D plot for the top trace (5th time sequence in the file) from above figure looks like;

As exepected D mirrors P but is much lower in magnitude
Victor Albert
on 28 Jul 2020
dpb
on 28 Jul 2020
fnD=@(t,P) 3.62e-7*P.^2.416.*t.^0.785; % set anonymous function for "D"
data=importdata('file3.xy');
PT = data.data;
D=fnD(PT(:,1),PT(:,2));
%plot(PT(:,1),PT(:,2)) % this plots all data as one trace--ignoring the starting over of time inside the file
tz=find(PT(:,1)==0); tz=[tz;size(PT,1)+1];
figure,hold on
for i=1:2:numel(tz)-1 % this only plots every other one starting at 1. 1,3,5,...
t1=tz(i); t2=tz(i+1)-1;
hL(i)=plot(PT(t1:t2,1),PT(t1:t2,2));
end
hAx.YScale='log';
ylim([0.01 25]) % this scaling may only be valid for this subset; don't know max in the whole file
grid on
hLg=legend(compose('Section %d',[1:2:numel(tz)].'),'Location','southeast');
Minimalist cleanup --
- Only plot P for odd sequences of time==0 sequences; D would be same subscripts
- Change the "2" in the step sequence in the for loop to plot all or
- Start with i=2:2: ... to do even sequences
- Scaling will be dependent on which sequences are plotted; this is ok for odd done here.
I have no idea how you would have gotten something looking like the plot you showed above -- there's no way D could be on order of 10^4 with the coefficients you provided of c=3.6E-7 as the multiplier.
For the peak shown at t=0.1 to be 32,500,
> fsolve(@(x) fnD(0.1,x)-32500,75000)
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
7.2196e+04
>>
The P value would have had to have been 72,200. However, the data in the file is
>> max(PT(:,2))
ans =
91.3812
>>
Makes no sense at all. Either your data isn't the same data (or even close) or the correlation isn't what you wrote in initial post or you just erred.
dpb
on 29 Jul 2020
BTW. all the transients on log-log axes looks like

The D variable would mimic those with the noted scale factor. This does show the one with the large peak magnitude of about 90 not in the odd-numbered set before.
Victor Albert
on 29 Jul 2020
dpb
on 29 Jul 2020
It ran here; you see the output attached.
Use debugger to find where there's a problem.
There's no need for cell2mat; no cell arrays are generated.
Victor Albert
on 29 Jul 2020
Victor Albert
on 29 Jul 2020
Victor Albert
on 29 Jul 2020
dpb
on 29 Jul 2020
What's hAx need to be; how to get current axes?
Victor Albert
on 29 Jul 2020
dpb
on 29 Jul 2020
You've got to learn your way around MATLAB to get anywhere...can't rely on somebody else forever for the simplest of debugging.
See above hint about current axes...try
doc current
lookfor current
and see what looks to be related...
Working through the "Getting Started" and "OnRamp" tutorials would pay back time invested multi-times over in speeding up the process.
dpb
on 29 Jul 2020
HINT: is spelled "GCA"
Victor Albert
on 29 Jul 2020
dpb
on 29 Jul 2020
READ THE HINT ABOVE.
Victor Albert
on 5 Aug 2020
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.
Victor Albert
on 26 Aug 2020
Accepted Answer
More Answers (0)
Categories
Find more on Large Files and Big Data 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!






