0

I create a code in MATLAB that optimizes an ANSYS study, so i want to check the ANSYS output file and see if the results are acceptable or not.

This code has as imputs parameters that are used by ANSYS to create the model. These parameters change at each iteration, thus at each iteration a different output file is created.

Let's be more specific. Below, there is an example of the output file:

  • line 1 blabla
  • line 2 blabla

  • . . .

  • line 10000 maximum values
  • line 10001 values1 2.31 4.56 5.69 8.64 0.25 9.70
  • .
  • .
  • line 35000 maximum values
  • line 35001 values2 2.25
  • .
  • .
  • line 70000 total values3 2503.4

All i want to do is to see if the first two values in bold are below the limits of the problem (i.e 9.70<15 and 2.25<7). If they are, store the third value in bold in a matrix. If they are not, go to the next iteration.

I'm pretty new to programming and Matlab instructions are a little confusing.

Any ideas would be welcome!

Thanks in advance!

**EDIT:** That's my entire code so far:

    X1=linspace(26,60,3)';
    X2=linspace(104,70,3)';
    R=linspace(3,10,3)';
    vec={X1',X2',R'};
    combs=combvec(vec{:})';

    seqv=zeros(i,1);
    tic

    for i=1:length(combs);
        fid=fopen('C:\Users\vaioss\Desktop\ergasia ymk\test\aa.txt','w+');
        fprintf(fid,'*SET,X1,%7.4f \r\n',combs(i,1));
        fprintf(fid,'*SET,X2,%7.4f \r\n',combs(i,2));
        fprintf(fid,'*SET,R,%7.4f \r\n',combs(i,3));
        fclose(fid);

        fid=fopen('C:\Users\...','r+');
        fclose(fid);

        dos('"C:\Program Files\ANSYS Inc\v150\ANSYS\bin\winx64\ansys150.exe"  -p ...');     

        fid=fopen('C:\Users\...','r');

        for j=1:10152; 
            tline=fgetl(fid); 
        end

        match = textscan(tline, '%s %f %f %f %f %f', '\n')';
        seqv(i) = cell2mat(match(6,1));

        if seqv(i)>67.2887;
            fclose(fid);
            continue
        end


    end
    fclose all;
    toc
dolving
  • 3
  • 2
  • You ought to show what you've attempted so far. – Dang Khoa Jun 24 '14 at 00:26
  • It depends on if the values you want are always at the same line and if the structure of those lines are always the same. If so, hit up `textscan`. – nkjt Jun 24 '14 at 09:15
  • @nkjt I tried with `textscan` but, unfortunately, the desired lines keep changing on every iteration. Is there a way to scan line by line the file searching for the lines that have the desired content? – dolving Jun 25 '14 at 15:52
  • Is there anything at the start of the lines you want that could identify them? e.g. is there actually "values1" or some other text before the numbers you want? – nkjt Jun 25 '14 at 20:53
  • @nkjt Yes, the format of the output is the same as the example i posted above. – dolving Jun 25 '14 at 21:04

1 Answers1

0

If you have an unknown number of lines of varying format before the info you want, probably the easiest way is along these lines

1) Use fgetl to fetch lines one at a time (obviously if you know you can safely skip the first 3000 lines or whatever, do so)

2) Use strfind to check if you've hit the values1 line. If so, parse the line and check if the value is within limits.

Then repeat for values2 and values3 if required, or move onto the next file and repeat. If there's any chance that you have files in the list that don't contain all these strings, then you'll also want some way of handling the case where you hit eof before finding them.

nkjt
  • 7,825
  • 9
  • 22
  • 28