Code calculation output checker

3 Ansichten (letzte 30 Tage)
Charles Mitchell-Thurston
Charles Mitchell-Thurston am 30 Mai 2022
So i have written some code which used a console command to do a calculation
The issue is that this console command doesnt work everytime. Running the same thing multiple times does produce different results(the console calculation, not the matlab code itself)
list=dir("RRfiles\");
for k = 1:length(list)
command = sprintf('simpson RRfiles/RR%g.in', k);
status = system(command);
end
Here is the trouble section of my code.
What simpson does is it takes in a set of values contained in the RR(X).in files and outputs a RR(X).fid file.
An example of a working .fid file is
SIMP
NP=128
SW=173333
TYPE=FID
DATA
0.499999941 0
0.466421028 0
0.469344476 0
.
.
.
0.270661094 0
END
And an example of a failed one is
SIMP
NP=128
SW=173333
TYPE=FID
DATA
0.499999941 0
1.#QNAN 1.#QNAN
1.#QNAN 1.#QNAN
.
.
.
.
END
What i need help with is writing a for loop that comes after this one that goes in the directory where i store the .fid files (something like c:\matlab\codelocation\fidfilelocation) and checks them all to see if they have worked on not, and if they havnt then it runs the console command again and then checks again afterwards, repeating this cycle till all of them have worked.
I know it is weird that the code doesnt work the same everytime. My current solution is to simply '!simpson RR(X).in' and check if it worked and repeat untill it does.
  1 Kommentar
Charles Mitchell-Thurston
Charles Mitchell-Thurston am 31 Mai 2022
Mr rough idea so far is something like
zero = 0;
for loop 1:1000
for i = 1:2
text=fileread(['RR', num2str(i), '.fid']);
strfind(text, 'QNAN');
if ans>zero
fprintf 'fail'
command = sprintf('simpson RR%g.in', i);
status = system(command);
else
fprintf 'pass'
end
end
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Charles Mitchell-Thurston
Charles Mitchell-Thurston am 31 Mai 2022
list=length(H);
for k = 1:length(list)
command = sprintf('simpson RRfiles/RR%g.in', k);
status = system(command);
end
zero = 0;
for loop = 1:1000
for i = 1:2
QNAN_text=fileread(['RR', num2str(i), '.fid']);
strfind(QNAN_text, 'QNAN');
if ans>zero
fprintf 'fail'
command = sprintf('simpson RR%g.in', i);
status = system(command);
end
end
end
fprintf 'all passed'
Its not perfect but it works
  4 Kommentare
Walter Roberson
Walter Roberson am 31 Mai 2022
I am concerned about the inconsistencies about using or not using the directory name.
Also fprintf does not emit newline unless you tell it to.
I don't think you should say all passed if you fail i==2 as well.
Charles Mitchell-Thurston
Charles Mitchell-Thurston am 31 Mai 2022
Currently the first part of my code is below. I got rid of the fprintf bit. And fixed the i = 1:2 to what it should be
%%%%take in data%%%%
H = readmatrix('numbers.xlsx');
%%%%create fid files%%%%
list=length(H);
for k = 1:list
command = sprintf('simpson RRfiles/RR%g.in', k);
status = system(command);
end
zero = 0;
for loop = 1:1000
for i = 1:list
QNAN_text=fileread(['RR', num2str(i), '.fid']);
strfind(QNAN_text, 'QNAN');
if ans>zero
command = sprintf('simpson RRfiles/RR%g.in', i);
status = system(command);
end
end
end
fprintf 'all passed'
mkdir Fidfiles
for t = 1:list;
filename = ['RR', num2str(t), '.fid'];
movefile ( filename, 'Fidfiles');
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Software Development Tools finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by