Too many output arguments when using "rowfun" function
Show older comments
I am trying to run through through table to generate a number of dat files for running in a FEA software.
I have created a function (very cumbersome, I am sure as I am a newbie programmer) to generate the data files. The function runs successfully one by one, but I was hoping to use the "rowfun" function to generate as many dat files as I need.
All associated files are attached.
The function below is called with:
% Apply the function, |GS_aij|, to the rows of the table, |CC|.
rowfun(GS_aij,CC,"NumOutputs",0)
I then receive the error message. "Too many output arguments".
What am I doing wrong? Any assistance or guidance would be appreciated.
The called function is as follows:
function GS_aij(fa,D,GL,dh,T,OR,ES,RL_ES,NP,P,HDI,SDI,...
HD1,HD2,HD3,HD4,HD5,HD6,HD7,HD8,HD9,HD10,HD11,HD12,HD13,...
HD14,HD15,HD16,HD17,HD18,HD19,HD20,ET,E,v,BASE,RO,CT)
% GS_aij The generation of *.dat files for Ansys Mechanical APDL.
% The generation of *.dat files for Ansys Mechanical APDL. The most
% critical variables have been selected as part of a Design of
% Experiments, to optimise the aij calibration coefficients.
filemat=load('aij_bij.mat');
aij_new=filemat.aij;
Updating the "aij" calibration matrix with the new inputs.
aij_new(3)="/filname,"+fa+",0!Changes the jobname for the analysis.";
aij_new(5)="*set,HD_D,"+D+"!Sets the variable for the (strain gauge mean diameter) for the gauge, in microns.";
aij_new(6)="*set,HD_GL,"+GL+"!Sets the variable for the (strain gauge grid length) for the gauge, in microns.";
aij_new(7)="*set,HD_D0,"+dh+"!Sets the variable for the drilled hole diameter, in microns.";
aij_new(8)="*set,sample_th,"+T+"!Sets the variable for the (work piece thickness) for the gauge, in microns.";
aij_new(9)="*set,sample_radia,"+OR+"!Sets the variable for the (work piece outer radius) for the gauge, in microns.";
aij_new(10)="*set,es,"+ES+"!Sets the variable for the finite element size (microns). Recommended size should not be larger than smallest hole depth increment.";
aij_new(11)="*set,rl_es,"+RL_ES+"!Sets the variable for the element size. Maximum element size should be equal to the smallest hole depth increment.";
aij_new(12)="*set,sample_stress,"+P+"!Sets the variable for the pressure, on the inner radius of drilled hole.";
aij_new(13)="*set,n,"+HDI+"!Sets the variable for the number of drilled hole depth increments.";
aij_new(14)="*set,p,"+SDI+"!Sets the variable for the number of stress depth increments.";
aij_new(15)="*set,np,"+NP+"!Sets the variable for the number of nodal planes for general axisymmetric analysis.";
% Drilled depth increments, from the surface in microns.
switch HDI
case '1'
aij_new(16)="*set,HD,"+HD1+"!Sets the variable for the number of 1st drilled hole depth increment.";
case '2'
aij_new(16)="*set,HD,"+HD2+"!Sets the variable for the number of 2nd drilled hole depth increment.";
case '3'
aij_new(16)="*set,HD,"+HD3+"!Sets the variable for the number of 3rd drilled hole depth increment.";
case '4'
aij_new(16)="*set,HD,"+HD4+"!Sets the variable for the number of 4th drilled hole depth increment.";
case '5'
aij_new(16)="*set,HD,"+HD5+"!Sets the variable for the number of 5th drilled hole depth increment.";
case '6'
aij_new(16)="*set,HD,"+HD6+"!Sets the variable for the number of 6th drilled hole depth increment.";
case '7'
aij_new(16)="*set,HD,"+HD7+"!Sets the variable for the number of 7th drilled hole depth increment.";
case '8'
aij_new(16)="*set,HD,"+HD8+"!Sets the variable for the number of 8th drilled hole depth increment.";
case '9'
aij_new(16)="*set,HD,"+HD9+"!Sets the variable for the number of 9th drilled hole depth increment.";
case '10'
aij_new(16)="*set,HD,"+HD10+"!Sets the variable for the number of 10th drilled hole depth increment.";
case '11'
aij_new(16)="*set,HD,"+HD11+"!Sets the variable for the number of 11th drilled hole depth increment.";
case '12'
aij_new(16)="*set,HD,"+HD12+"!Sets the variable for the number of 12th drilled hole depth increment.";
case '13'
aij_new(16)="*set,HD,"+HD13+"!Sets the variable for the number of 13th drilled hole depth increment.";
case '14'
aij_new(16)="*set,HD,"+HD14+"!Sets the variable for the number of 14th drilled hole depth increment.";
case '15'
aij_new(16)="*set,HD,"+HD15+"!Sets the variable for the number of 15th drilled hole depth increment.";
case '16'
aij_new(16)="*set,HD,"+HD16+"!Sets the variable for the number of 16th drilled hole depth increment.";
case '17'
aij_new(16)="*set,HD,"+HD17+"!Sets the variable for the number of 17th drilled hole depth increment.";
case '18'
aij_new(16)="*set,HD,"+HD18+"!Sets the variable for the number of 18th drilled hole depth increment.";
case '19'
aij_new(16)="*set,HD,"+HD19+"!Sets the variable for the number of 19th drilled hole depth increment.";
case '20'
aij_new(16)="*set,HD,"+HD20+"!Sets the variable for the number of 20th drilled hole depth increment.";
end
aij_new(18)="et,1,"+ET+",,np!Definition of the element type (linear solid272 or the quadratic solid273) and the number of nodal planes.";
aij_new(20)="mp,ex,1,"+E+"!Enter the modulus of elasticity, in MPa.";
aij_new(21)="mp,prxy,1,"+v+"!Enter the poisson's ratio.";
% Outer Radius
switch RO
case 'RO_NA'
aij_new(65)="!d,all,,,,,,,,,,,";
case 'RO_UX'
aij_new(65)="d,all,,,,,,ux,,,,,";
case 'RO_UY'
aij_new(65)="d,all,,,,,,,uy,,,,";
case 'RO_UXY'
aij_new(65)="d,all,,,,,,ux,uy,,,,";
end
% Base
switch BASE
case 'Base_UYZ'
aij_new(68)="d,all,,,,,,,uy,uz,,,";
case 'Base_UXYZ'
aij_new(68)="d,all,,,,,,ux,uy,uz,,,";
end
aij_new(74)="eqslv,jcg,"+CT;
% Stress depth increments in microns.
switch SDI
case '1'
aij_new(77)="nsel,r,loc,z,1.5,-"+HD1+"-1.5";
case '2'
aij_new(77)="nsel,r,loc,z,-"+HD1+"+2.5,-"+HD2+"-2.5";
case '3'
aij_new(77)="nsel,r,loc,z,-"+HD2+"+2.5,-"+HD3+"-2.5";
case '4'
aij_new(77)="nsel,r,loc,z,-"+HD3+"+2.5,-"+HD4+"-2.5";
case '5'
aij_new(77)="nsel,r,loc,z,-"+HD4+"+2.5,-"+HD5+"-2.5";
case '6'
aij_new(77)="nsel,r,loc,z,-"+HD5+"+2.5,-"+HD6+"-2.5";
case '7'
aij_new(77)="nsel,r,loc,z,-"+HD6+"+2.5,-"+HD7+"-2.5";
case '8'
aij_new(77)="nsel,r,loc,z,-"+HD7+"+2.5,-"+HD8+"-2.5";
case '9'
aij_new(77)="nsel,r,loc,z,-"+HD8+"+2.5,-"+HD9+"-2.5";
case '10'
aij_new(77)="nsel,r,loc,z,-"+HD9+"+2.5,-"+HD10+"-2.5";
case '11'
aij_new(77)="nsel,r,loc,z,-"+HD10+"+2.5,-"+HD11+"-2.5";
case '12'
aij_new(77)="nsel,r,loc,z,-"+HD11+"+2.5,-"+HD12+"-2.5";
case '13'
aij_new(77)="nsel,r,loc,z,-"+HD12+"+2.5,-"+HD13+"-2.5";
case '14'
aij_new(77)="nsel,r,loc,z,-"+HD13+"+2.5,-"+HD14+"-2.5";
case '15'
aij_new(77)="nsel,r,loc,z,-"+HD14+"+2.5,-"+HD15+"-2.5";
case '16'
aij_new(77)="nsel,r,loc,z,-"+HD15+"+2.5,-"+HD16+"-2.5";
case '17'
aij_new(77)="nsel,r,loc,z,-"+HD16+"+2.5,-"+HD17+"-2.5";
case '18'
aij_new(77)="nsel,r,loc,z,-"+HD17+"+2.5,-"+HD18+"-2.5";
case '19'
aij_new(77)="nsel,r,loc,z,-"+HD18+"+2.5,-"+HD19+"-2.5";
case '20'
aij_new(77)="nsel,r,loc,z,-"+HD19+"+2.5,-"+HD20+"-2.5";
end
aij_new(99)="*cfopen,"+fa+"_n_%n%_p_%p%_es_%es%_rl_es_%rl_es%_np_%np%_sr_%sample_radia%_st_%sample_th%,txt";
% Creation of the *.dat file.
filenamedat=fa+".dat";
fileID=fopen(filenamedat,'w'); % Open and name an empty text
% file.
fprintf(fileID,'%s\n',aij_new); % Write data to the text file.
fclose(fileID); % Close the text file.
clear % Clear the workspace.
clc % Clear command window.
end
15 Comments
Walter Roberson
on 11 Jan 2020
rowfun(@GS_aij,CC,"NumOutputs",0)
GS76
on 12 Jan 2020
GS76
on 12 Jan 2020
Walter Roberson
on 12 Jan 2020
You need to pass the handle to a function after the "ErrorHandler" option keyword
GS76
on 12 Jan 2020
GS76
on 12 Jan 2020
David Goodmanson
on 12 Jan 2020
Edited: David Goodmanson
on 12 Jan 2020
Hi Gary, regardless of the details, one problem is all of the dynamically named variables such as HD1, HD2, etc. Assuming there is nothing going on behind the scenes to prevent it, much better would be a string array variable named with an index, HD(k). Then the entire HDI swithc case structure, which takes 42 lines, could be something like
aij_new(16)="*set,HD,"+HD(HDI)+"!Sets the variable for the number of "+HDI+"th drilled hole depth increment.";
and you could do something similar for the other switch case structure as well.
Walter Roberson
on 12 Jan 2020
The documentation is telling you that you need one input parameter for each column of the input.
Walter Roberson
on 12 Jan 2020
After ErrorHandler keyword you need a function handle to the function that handles errors.
GS76
on 12 Jan 2020
Walter Roberson
on 12 Jan 2020
func = @GS_aij;
rowfun(func,CC,"NumOutputs",0,"ErrorHandler",@GS_aij_error_handler,"InputVariables",{'fa' 'D' 'GL' 'dh' 'T' 'OR' 'ES' 'ES_RL'...
'NP' 'P' 'HDI' 'SDI' 'HD1' 'HD2' 'HD3' 'HD4' 'HD5' 'HD6' 'HD7' 'HD8' 'HD9' 'HD10' 'HD11' 'HD12'...
'HD13' 'HD14' 'HD15' 'HD16' 'HD17' 'HD18' 'HD19' 'HD20' 'ET' 'E' 'v' 'BASE' 'RO' 'CT'})
with
function GS_aij_error_handler(S, varargin)
warning(S.identifier, S.message);
fprintf('Problem occurred on input line #%d\n', S.index);
fprintf('Variable values were:\n');
celldisp(varargin);
end
GS76
on 13 Jan 2020
Guillaume
on 13 Jan 2020
Numbered variables are always a bad idea. How many lines of code, each a potential source of bug do you have just to cope with these numbered HDx variables? What if tomorrow, you want to change the formatting of the text (eg. add a space after the commas)? You then have to edit all these lines of code. Using indexing as suggested by David, all this can be collapsed into just one line.
However, with regards to your immediate problem, it's fairly clear from the error message. Somewhere you have a call to a function Creation. Indeed, towards the end of your code you have the lines:
aij_new(99)="*cfopen,"+fa+"_n_%n%_p_%p%_es_%es%_rl_es_%rl_es%_np_%np%_sr_%sample_radia%_st_%sample_th%,txt";
Creation of the *.dat file.
filenamedat=fa+".dat";
The Creation line is probably meant to be a comment.
GS76
on 13 Jan 2020
GS76
on 13 Jan 2020
Accepted Answer
More Answers (0)
Categories
Find more on Condensed Matter & Materials Physics 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!
