Neural Net Fitting - how to use myNeuralNetworkFunction

I am trying to regress my data using Neural Net Fitting among machine learning and deep learning apps. However, an error has occurred and the editor is not running.
After training my data in the Neural Net Fitting app, I imported the code into the editor using the Export Network Function for MATLAB Coder in the Export-model.
As a result, the code was loaded into the editor, and I ran the editor by adding y1 = myNeuralNetworkFunction(input_data) to the first line to get the regression data.
However, instead of the regression data, I only got 4 errors.
The data in the workspace, the code loaded into the editor, and the error contents are attached.
y1 = myNeuralNetworkFunction(input_data)
function [y1] = myNeuralNetworkFunction(x1)
%MYNEURALNETWORKFUNCTION neural network simulation function.
%
% Auto-generated by MATLAB, 14-Jan-2022 06:35:02.
%
% [y1] = myNeuralNetworkFunction(x1) takes these arguments:
% x = 16xQ matrix, input #1
% and returns:
% y = 1xQ matrix, output #1
% where Q is the number of samples.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1.xoffset = [0.07;0.11;1.255;0.002;0.001;0;0;0.07;0.11;1.255;0.002;0.001;0;0;16;-25];
x1_step1.gain = [13.6986301369863;1.6260162601626;1.30293159609121;117.647058823529;142.857142857143;1.92307692307692;666.666666666667;13.6986301369863;1.6260162601626;1.30293159609121;117.647058823529;142.857142857143;1.92307692307692;666.666666666667;0.0357142857142857;0.08];
x1_step1.ymin = -1;
% Layer 1
b1 = [1.7071811558589189417;-1.5928826098618114049;-1.433967024400671697;1.3073516936712077374;-1.3514129890078228069;-1.0572721985661774902;-0.99513133163816236415;0.80291062239881882956;-0.76098700869032487315;-0.66680841094740039843;-0.355781034537263674;-0.44191226736518807172;0.2763091097036264876;-0.16719983577146865783;0.070917927127336702342;0.13090960658806957695;0.30766297862293373599;0.25967552253966008635;0.47971197236859375312;-0.47029781539579329497;0.59390364096792769288;-0.76547691510996451747;0.9166880943317061714;0.98226120175040609883;1.242763121200631371;-1.3143139236256304869;-1.3805211111172657201;-1.3157085620942827742;1.5475667061515538947;1.7346240277685485154];
IW1_1 = [-0.054581403453064350484 0.86898354412120315526 0.22755864375319345694 -0.67569324715718437346 -0.13232084442836478111 -0.70048256578114587168 0.71512241555384248315 -0.18800958345382781656 -0.33960145849841050225 -0.14964845672546531197 0.36005281072240535867 -0.29235170989651032558 -0.32638424171252539141 -0.55162107793069858896 -0.27320232957982759636 -0.56420670080508683597;0.24084005356543491949 0.17365571616714092773 -0.81017985783417911794 0.2869269081884814887 -0.14695508815418623083 0.558655725502549938 0.7682624936219939471 0.5738262227687679351 -0.0027901967219920950115 0.63222425673893656306 -0.068331057561698965719 0.12020886981442442665 -0.095163883300234550222 -0.025877253783376089058 0.47497824275934574789 -0.0053905325203945459941;0.099925014381015739295 0.1163125334610527889 0.44326453441982599513 0.86523560791775444567 0.5444589645750155249 -0.60463062097233633008 -0.13576187542814771581 0.031111176994038008958 -0.096858601853217374256 0.028527557941140917197 -0.16037576717867133014 0.19620475157187144966 0.27248818846281991357 -0.80936551902428122141 -0.41940853539870376343 -0.5977108655851897101;-0.24010037214853538479 -0.64867801087773346858 -0.10618711152294557643 0.81204643931415398939 0.13635229865845452379 0.6742265074688893467 -0.37687213881521747227 -0.2079540360398475507 0.078347625191404077216 0.66061076633885618126 -0.006118308391078704396 0.39101919031475002031 -0.74141279192452247404 0.38050526169467691062 0.18967049466119750845 -0.3081250593246090963;0.82335774955179474865 0.68072485870424470633 -0.1404077710231820264 0.18927492027870218561 0.093894461555709698986 -0.60963087630528822736 -0.60483007743497685382 -0.19404485287188294462 -0.28524084788443204719 -0.72871557855735402676 0.45959066928581637779 0.23693562627930855879 0.038669234681854222635 0.089949361224159612993 -0.62133527991668868751 -0.76513406481397483461;0.51257329053914335582 -0.22034456888162465282 -0.592789825052262076 0.96850248789885251544 -0.091624789879441420615 0.33701807285519003177 -0.15332352625949283165 -0.42361884712080849491 -0.77224806466714401854 -0.00012950548655621136468 0.46349840954599641485 0.062633234098555340408 0.24419545180718826849 0.067751355802583845822 0.24880182072300713325 0.34705789084092009134;0.5735451751794162778 -0.54009124606042491212 0.60499221867812413844 0.13452887605637264823 -0.26702386717727949472 0.023489762089277752694 0.094108474151489318604 -0.45586965488467040553 -0.139011688688038898 0.38277339112658337328 0.11386942518375267608 -0.20472653937433879512 -0.51842538119226766469 0.59032314776060990091 0.30784777468944618528 0.90097838987750333839;-0.42266734806115030532 0.54525035409997446578 -0.48010091176719837947 -0.27110640821134796008 0.20018137943609828899 -0.70911106583319682972 0.51196493906746487479 -0.83259072686759993953 -0.49519540599439432205 -0.45184661663436137546 0.43821723418894975577 0.18424681943979742682 0.55625113778523482821 0.44091326233723582284 -0.46707180952045435074 0.32466969592884831197;0.19635379351894358124 0.58197634707736756177 -0.45731826552783449991 -0.27040404184339866811 0.063168177769450037373 -0.033795867388613093363 -0.69322355472746310934 -0.08314438443063647266 -0.60182200170920929772 -0.24062717376359912813 0.2833941162781418166 -0.59965947211194958744 0.69012284488648723002 0.3925957937630187855 -0.23040992611073018992 0.57337453265484783493;0.491885262938496437 0.95532851951370711951 0.1204071813820875303 0.25496944870412313611 -0.22303706439617893009 -0.34210055142957540575 -0.090243492889327731055 -0.16870127870443044071 0.78126455750850554161 -0.46163091839099557046 -0.5239836241173496667 -0.57079963950523082694 0.38341755051171111379 -0.17646303733219742549 -1.1466332219444468343 -1.39412205527780797;0.68802153939447685538 -0.34483095157561294286 -0.16431696420335140107 0.10800278393380388642 0.033901976576016457088 0.20855525617301415298 -0.22142111351417112508 -0.41673559663405318476 -0.015642653843481221787 -0.32678867447691267722 0.091112370104005829807 0.78187594153786388329 -0.17277086338735334059 -0.28975163136532045005 0.6809038309523098853 1.189630727554221945;0.51083719771658142594 0.48894157251240050188 0.14159243985348146655 -0.67595177698792396903 0.32794842491043441068 0.26529736015191751619 -0.56950511567084038944 -0.24407261313724004648 0.86927298073734571293 -0.12968484573734651022 -0.25910209872954070853 -0.29555308750068653989 -0.39969201036904655755 0.38897447931305006996 0.021224219862454492269 0.059391799753003876594;-0.69076188639631386224 0.16241595661400318185 0.49020755399198046032 0.77788176438673850566 0.30041597750451992654 -0.23590033848176367171 0.45964142709173577694 -0.49302226025250150965 0.18256667044103938591 0.00058335254147499166974 -0.68303778520304647692 0.034645037955578043831 0.43692921378629717699 -0.42155418243161119074 -0.22931727883198729789 -0.33021142745392173534;0.32971274690477136993 -0.64386715147944284521 0.041326193285808346389 -0.3299956069039598483 0.22314150745521160735 -0.18550409532507788901 0.10173331398008732263 0.084850423565668506298 -0.77124669462721773261 -0.5670084282721037372 -0.58752802898551792499 0.76998884433913872272 -0.23094427363731945269 -0.27344887168359222063 -0.3347737586109223451 0.17477499547001904001;-0.7781830101843636438 -0.2309611359296947497 -0.22822636907108515003 -0.17408554103916917821 0.40871608482452903566 -0.65843256292918106443 -0.061329688671781366904 0.38035954027007545797 0.25803172532098289649 0.087232813493602956445 -0.57893177289291919418 -0.56350509070107768217 0.84964666340376870934 -0.37379887432781538914 -0.0026078336916539272133 0.19846968802889228267;-0.1590477505586598006 -0.32939562753798234951 0.012316536684207603225 0.41597679464040493436 -0.053947755284847347113 -0.94466032742664041155 0.70819255715299578302 -0.19007168043066646757 0.87117023679907845679 -0.3812551635233898395 0.48245879007316960774 -0.70888986458438663085 -0.14142922341194347213 -0.21989932281791224611 0.51355606268231279721 0.068412680699952529983;0.24213294915792615836 0.42709027086151496455 0.28946332061881119291 -0.26030746088768186297 -0.21247791613134731081 -0.32728986552225308726 0.22360215866409505203 0.63787963609952091915 0.36524824707809439017 -0.58151227082124534729 -0.080479227776064476974 -0.50042721905773346336 0.12659472628254012094 0.9301878981588195261 -0.23948013332836506906 -0.31588445403816262091;0.80851903186955687008 0.16384914788513402217 0.69796482970048057126 0.37761084191207316962 -0.20395690619578293878 0.43063578593717766196 -0.19292017668005714826 -0.58048220525032412365 0.32066907830536439672 -0.39009704804331613026 0.2494255635239956137 0.69003417330721361633 -0.61374429910280769995 0.24386231306092115423 -0.57340075321899497407 -0.31974496335625440802;0.35546118802667103775 0.49632159536929087995 0.22212370770371531181 0.41681286543672413369 0.26991215057913381381 0.0098312180526899071997 0.45855691175304907903 -0.2989371895834023185 -0.65226353757315269632 -0.61354015892103852536 -0.55358945873353793132 -0.093561698426893963321 -0.71869901069373942626 -0.21130062183189127212 -0.90762750205299391748 0.24129320350116925664;-0.073621261714994501446 0.50352504803395869981 -0.10315519175982305888 0.54970585312758923902 0.41903556254855028884 -0.021220941300309457966 -0.017018201646876684324 -0.71653723740252805996 0.44437031013599342932 0.64611677337082273898 -0.68830113647199298033 -0.29502469795435037891 -0.42811729014270499816 -0.34854483506954042626 0.31637680894409808685 0.46815977170624784032;0.58402458710503013517 -0.032581735101212497274 0.5137663068578083303 0.80557220035760301879 -0.33512091587851766672 0.63980195523113270184 0.067758971498253342536 -0.51004865993791415058 -0.28396310618222508904 0.70575225112200168365 0.097397240875426963069 -0.41998005514783054437 0.52963787100472758951 0.43573156889218644938 -0.020825584603151703345 -0.46598027314827822343;-0.054274770415522304023 -0.10432695169517841594 -0.61239661465880523838 -0.62494864905577307557 0.41972136195777687284 -0.61143333493540541479 0.46409862902950682617 -0.80646199474977564581 -0.21958636787411206504 0.55647411374977973075 -0.44773616016288636521 0.16831340937530342439 0.67820689387031674045 0.73363998610495784192 -0.29929252691495666916 -0.17101840450966065976;0.53694429593777015519 0.16254590633455617832 -0.58762754525895211088 -0.39896752126460266474 0.72490621797337595478 0.55637443373554384962 -0.16662674987297654283 -0.36166002529794616382 0.56117262520839306106 0.27891873994923416236 0.62718771518204741167 -0.2720473836576395299 0.23689189704562016447 0.1860971501117280047 0.42232106109697975516 0.38602906036771866827;0.57338102494398102138 0.44583344098038196757 -0.53865039338027875804 0.45448402180948876961 0.39016611684382868086 -0.52885843643479024667 -0.31202534416218841162 -0.49217072846960208121 0.48038486179126566045 -0.3541971686748849879 0.53264417885588233315 -0.39010961530578003309 0.30323551591965652863 -0.34710679022054147236 -0.10692247558713179056 -0.47643122118376396434;0.64764774786216272595 0.1638082221727193144 -0.64220218350925539763 0.14105488880462960233 0.38941421257733632721 -0.049101055892068069808 0.11764554689239249685 -0.35751393597995845264 -0.15004290931279024024 -0.31261131667263009071 -0.20669669408791790932 -0.22774355181414293603 -0.61804739289372656597 -0.78386320377720564156 -0.11396638552242659148 0.61765991737988124033;-0.1712179685403674434 0.19034468266861898078 -0.17416706029790696153 0.061587276141992303158 -0.46071810367064169878 -0.43682577738684630342 0.53582629647504831372 -0.42392755267920206874 -0.21881973518759242903 -0.43936516823214510907 -0.68772813980079205987 -0.58066525814119440696 0.18613859222870868249 0.54846055795670589639 0.41767122462906541847 0.64395819377919716331;-0.15947080354220030673 -0.43131433656219486661 -0.41305307617816705568 0.18693907575767762519 -0.23907927237144876997 0.10850567745019190635 -0.18282024652023706746 -0.72700023139930058935 0.14643504229561296603 -1.0199671336569084978 0.29653115449523204106 0.17275022866934205967 0.58199773531579890307 0.18750249253496037438 0.2990690425839035993 -0.42153608818659371593;-0.58885627498927017864 -0.021785425676793070127 -0.40318370214366688886 0.52825074619354484007 0.44115380369005108285 -0.62038604493991866828 -0.76918885003830261837 0.01604792569671256719 0.50927809859286166105 -0.16494968367109733021 0.42464077970243596649 -0.47459576425771909935 -0.19135028083751082217 0.50076472344641786982 -0.063382744814221778085 -0.40456820639519397442;0.40238529388977301027 0.260163669363175587 -0.082115224057250565948 -0.074069861519506646763 -0.13304124774711406642 0.30052364696878836048 -0.00817470048249122061 0.49249316068126031132 0.68599518291695860128 0.37879504304647437785 0.86844257102339406096 0.047290759413714120174 0.80793793127327562242 -0.85123612198471620971 0.1997612000938381871 0.011055193572446143924;0.49634762499489909482 0.45942880277454528626 -0.54440106037596325272 -0.37728127934141358901 -0.65922749787682632938 0.44453832833168077654 -0.26150008550522207962 0.55870667868925416588 0.11667609198092651623 0.13426028775703324758 -0.58786374302407506942 0.35279433941291094001 -0.56477254606427051975 0.10952289974518793214 0.60357409757212188151 0.10364475790517904685];
% Layer 2
b2 = -0.38818909062601664184;
LW2_1 = [0.99111569698483092949 0.51510054176559982864 0.64184143208920807488 0.53965579310431666116 -0.60879564945863462455 0.52748492192280571622 -0.1207823441785156604 -0.74626415958110980942 -0.2692181156762409322 0.80072671978151543914 0.19249310363325794482 0.25839779844933963293 0.63197899322275807865 0.37132309082641756781 -0.52480037736118523295 0.28096766963975128295 -0.25446724944748727593 -0.42796576125573071447 -0.39584571488773490078 0.0060908895626070377188 0.73223203859170560293 0.69878153846880897149 -0.41096272717003567987 -0.10051812288225150938 0.14654639135831509789 0.26275302925365251472 -0.99085065222386514705 0.33953334559175052387 -0.54536406257028524625 0.40045363803338734909];
% Output 1
y1_step1.ymin = -1;
y1_step1.gain = 1.19047619047619;
y1_step1.xoffset = 0.74;
% ===== SIMULATION ========
% Dimensions
Q = size(x1,2); % samples
% Input 1
xp1 = mapminmax_apply(x1,x1_step1);
% Layer 1
a1 = tansig_apply(repmat(b1,1,Q) + IW1_1*xp1);
% Layer 2
a2 = repmat(b2,1,Q) + LW2_1*a1;
% Output 1
y1 = mapminmax_reverse(a2,y1_step1);
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end
% Sigmoid Symmetric Transfer Function
function a = tansig_apply(n,~)
a = 2 ./ (1 + exp(-2*n)) - 1;
end
% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end
Error using bsxfun
Non-singleton dimensions of the two input arrays must match each other.
Error in untitled1>mapminmax_apply (line 57)
y = bsxfun(@minus,x,settings.xoffset);
Error in untitled1>myNeuralNetworkFunction (line 41)
xp1 = mapminmax_apply(x1,x1_step1);
Error in untitled1 (line 1)
y1 = myNeuralNetworkFunction(input_data)

댓글 수: 2

I also encountered this problem. Have you solved it now?

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhiram
Abhiram 2025년 6월 10일

0 개 추천

The error is occurring due to a dimension mismatch –“bsxfun(@minus, x, settings.xoffset)”, when you subtract “settings.xoffset” from “x”, their dimensions need to be compatible.
The function expects the input parameter “x1” to be of dimension 16xQ, where Q is the number of samples (columns). If your input is row-major (e.g. 1×16 or Q×16), you’ll get a dimension mismatch. Use transpose of "input_data" to correct the orientation.
Hope this helps!

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 1월 14일

답변:

2025년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by