Too many output arguments when using "rowfun" function

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

rowfun(@GS_aij,CC,"NumOutputs",0)
Thank you for your equation Walter.
I ran it and received the following message. I had not mentioned that there are "char" columns within the the table. Should it be numeric only.:
Error1.JPG
I have added the "errorhandler" which is avaiable in the "rowfun" as follows and it threw the following message:
func = @GS_aij;
rowfun(func,CC,"NumOutputs",0,"ErrorHandler")
Error using tabular/rowfun (line 170)
Wrong number of arguments.
Is it perhaps because I am accessing a string array?
You need to pass the handle to a function after the "ErrorHandler" option keyword
Hi Walter,
How are you?
Is this what you meant?
func = @GS_aij;
rowfun(func,CC,"NumOutputs",0,"ErrorHandler",GS_aij,"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'})
I think I may have found the bigger issue with my function.
I have 38 inputs and I see think the "rowfun" only accepts 2. See the extract from the help:
Function, specified as a function handle. You can define the function in a file or as an anonymous function. If funccorresponds to more than one function file (that is, if func represents a set of overloaded functions), MATLAB® determines which function to call based on the class of the input arguments.
func can accept no more than size(A,2) inputs. By default, rowfun returns the first output of func. To return more than one output from func, use the 'NumOutputs' or 'OutputVariableNames' name-value pair arguments.
Example: func = @(x,y) x.^2+y.^2; takes two inputs and finds the sum of the squares.
Is there any other way doing what I want to do?
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.
The documentation is telling you that you need one input parameter for each column of the input.
After ErrorHandler keyword you need a function handle to the function that handles errors.
Hi David,
Thanks for your input.
Is this what you are suggesting replaces the "case"?
Thanks. Gary
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
Thank you for this function.
I implemented the functions accessing the table as follows:
GS_aij_CC.m script (see attached)
% Apply the function, |GS_aij|, to the rows of the table, |CC|.
func = @GS_aij;
func_e = @GS_aij_error_handler;
rowfun(func,CC,"NumOutputs",0,"ErrorHandler",func_e);
GS_aij.m function
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.
if HDI == 1
aij_new(16)="*set,HD,"+HD1+"!Sets the variable for the number of 1st drilled hole depth increment.";
elseif HDI == 2
aij_new(16)="*set,HD,"+HD2+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 3
aij_new(16)="*set,HD,"+HD3+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 4
aij_new(16)="*set,HD,"+HD4+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 5
aij_new(16)="*set,HD,"+HD5+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 6
aij_new(16)="*set,HD,"+HD6+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 7
aij_new(16)="*set,HD,"+HD7+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 8
aij_new(16)="*set,HD,"+HD8+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 9
aij_new(16)="*set,HD,"+HD9+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 10
aij_new(16)="*set,HD,"+HD10+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 11
aij_new(16)="*set,HD,"+HD11+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 12
aij_new(16)="*set,HD,"+HD12+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 13
aij_new(16)="*set,HD,"+HD13+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 14
aij_new(16)="*set,HD,"+HD14+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 15
aij_new(16)="*set,HD,"+HD15+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 16
aij_new(16)="*set,HD,"+HD16+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 17
aij_new(16)="*set,HD,"+HD17+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 18
aij_new(16)="*set,HD,"+HD18+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 19
aij_new(16)="*set,HD,"+HD19+"!Sets the variable for the number of 2nd drilled hole depth increment.";
elseif HDI == 20
aij_new(16)="*set,HD,"+HD20+"!Sets the variable for the number of 2nd drilled hole depth increment.";
end
% Element type
aij_new(18)="et,1,"+ET+",,np!Definition of the element type (linear solid272 or the quadratic solid273) and the number of nodal planes.";
% Modulus of elasticity (MPa)
aij_new(20)="mp,ex,1,"+E+"!Enter the modulus of elasticity, in MPa.";
% Poisson's Ratio
aij_new(21)="mp,prxy,1,"+v+"!Enter the poisson's ratio.";
% Outer Radius
if ismember(RO,'RO_NA')
aij_new(65)="!d,all,,,,,,,,,,,";
elseif ismember(RO,'RO_UX')
aij_new(65)="d,all,,,,,,ux,,,,,";
elseif ismember(RO,'RO_UY')
aij_new(65)="d,all,,,,,,,uy,,,,";
elseif ismember(RO,'RO_UXY')
aij_new(65)="d,all,,,,,,ux,uy,,,,";
end
% Base
if ismember(BASE,'Base_UYZ')
aij_new(68)="d,all,,,,,,,uy,uz,,,";
elseif ismember(BASE,'Base_UXYZ')
aij_new(68)="d,all,,,,,,ux,uy,uz,,,";
end
% Convergence tolerance
aij_new(74)="eqslv,jcg,"+CT;
% Stress depth increments in microns.
if SDI == 1
aij_new(77)="nsel,r,loc,z,1.5,-"+HD1+"-1.5";
elseif SDI == 2
aij_new(77)="nsel,r,loc,z,-"+HD1+"+2.5,-"+HD2+"-2.5";
elseif SDI == 3
aij_new(77)="nsel,r,loc,z,-"+HD2+"+2.5,-"+HD3+"-2.5";
elseif SDI == 4
aij_new(77)="nsel,r,loc,z,-"+HD3+"+2.5,-"+HD4+"-2.5";
elseif SDI == 5
aij_new(77)="nsel,r,loc,z,-"+HD4+"+2.5,-"+HD5+"-2.5";
elseif SDI == 6
aij_new(77)="nsel,r,loc,z,-"+HD5+"+2.5,-"+HD6+"-2.5";
elseif SDI == 7
aij_new(77)="nsel,r,loc,z,-"+HD6+"+2.5,-"+HD7+"-2.5";
elseif SDI == 8
aij_new(77)="nsel,r,loc,z,-"+HD7+"+2.5,-"+HD8+"-2.5";
elseif SDI == 9
aij_new(77)="nsel,r,loc,z,-"+HD8+"+2.5,-"+HD9+"-2.5";
elseif SDI == 10
aij_new(77)="nsel,r,loc,z,-"+HD9+"+2.5,-"+HD10+"-2.5";
elseif SDI == 11
aij_new(77)="nsel,r,loc,z,-"+HD10+"+2.5,-"+HD11+"-2.5";
elseif SDI == 12
aij_new(77)="nsel,r,loc,z,-"+HD11+"+2.5,-"+HD12+"-2.5";
elseif SDI == 13
aij_new(77)="nsel,r,loc,z,-"+HD12+"+2.5,-"+HD13+"-2.5";
elseif SDI == 14
aij_new(77)="nsel,r,loc,z,-"+HD13+"+2.5,-"+HD14+"-2.5";
elseif SDI == 15
aij_new(77)="nsel,r,loc,z,-"+HD14+"+2.5,-"+HD15+"-2.5";
elseif SDI == 16
aij_new(77)="nsel,r,loc,z,-"+HD15+"+2.5,-"+HD16+"-2.5";
elseif SDI == 17
aij_new(77)="nsel,r,loc,z,-"+HD16+"+2.5,-"+HD17+"-2.5";
elseif SDI == 18
aij_new(77)="nsel,r,loc,z,-"+HD17+"+2.5,-"+HD18+"-2.5";
elseif SDI == 19
aij_new(77)="nsel,r,loc,z,-"+HD18+"+2.5,-"+HD19+"-2.5";
elseif SDI == 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
Your GS_aij_error_handler.m function
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
The warning message is as follows:
Warning messages.png
I am unsure what I am doing wrong. I have replaced the "switch" structures with "if...elseif" structures.
Was that a mistake?
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.
My bad! Once I corrected a statement that used to be commented out, then everything was working.
Thank you to everyone for the help.
Thank you Guillaume.
I really appreciate the feedback and insight.
And thank you for the answer below. Thank you for the suggested alternative design. Beautifully streamlined and efficient.

Sign in to comment.

 Accepted Answer

Glad the problem is resolved, however I would strongly recommend to refactor the code. I like rowfun, varfun, etc. but for you I think it's the wrong function to use and it greatly complicates your code. Passing that amount of variables to a function, particularly numbered variables is a problem.
Instead, I would suggest a completely different design. Most of your code follows the same pattern, build a string consisting of 3 parts: two literal parts and a part in between taken from a table variable. Said variable can be static or numbered. The whole lot is added to a given index of a variable. Rather than implementing all that description in code, abstract it into a cell array or table:
%mods: a table describing the modifications to be done. Consists of 5 variables:
% index: which index of aij to write to
% prefix: literal string prefix
% suffix: literal string suffix
% varname: name of variable containing text to insert between prefix and suffix. May need a number appended
% dynsource: if not empty, add value of variable dynsource to varname
mods = cell2table(...
{3, "/filname,", "fa", ",0!Changes the jobname for the analysis.", [];
5, "*set,HD_D,", "D", "!Sets the variable for the (strain gauge mean diameter) for the gauge, in microns.", [];
6, "*set,HD_GL,", "GL", "!Sets the variable for the (strain gauge grid length) for the gauge, in microns.", [];
7, "*set,HD_D0,", "dh", "!Sets the variable for the drilled hole diameter, in microns.", []; ...some lines omitted
16, "*set,HD,", "HD", "!Sets the variable for the number of 1st drilled hole depth increment.", "HDI";
18, "et,1,", "ET", ",,np!Definition of the element type (linear solid272 or the quadratic solid273) and the number of nodal planes.", []}, ...more lines omitted
'VariableNames', {'index', 'prefix', 'suffix', 'varname', 'dynsource'});
I'm assuming the variable names that you've defined in your function are the same as the actual variable names of your table.
I would then use a plain loop instead of rowfun:
filemat=load('aij_bij.mat');
for CCrow = 1:height(CC)
aij = filemat.aij
%now loop over the rows of mods
for mrow = 1:height(mods)
sourcevar = mods.varname(mrow);
if ~isempty(mods.dynsource(mrow))
sourcevar = sprintf('%s%d', sourcevar, CC.{CCrow, mods.dynsource(row)});
end
aij(mods.index(mrow)) = mods.prefix(mrow) + CC.{CCrow, sourcevar} + mods.suffix(mrow);
end
end
%...
That's already most of your code shortened to a few lines. It's also easier to edit if you want to modify the text format, etc. The mods table could even be read from a text or excel file.
You can either have a separate table for the SDI values or add two optional variables to the mods table.

More Answers (0)

Categories

Find more on Condensed Matter & Materials Physics in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 11 Jan 2020

Commented:

on 14 Jan 2020

Community Treasure Hunt

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

Start Hunting!