[1维粒子模拟 version3.6]成功调试read input parameters
生活随笔
收集整理的這篇文章主要介紹了
[1维粒子模拟 version3.6]成功调试read input parameters
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?代碼input_param.m
% % read input parameters % function prm = input_param(input_filename)prm = [];try[str1, str2] = textread(input_filename, ...'%s%s','delimiter','=;','commentstyle','matlab')catcherrordlg(sprintf('Can''t open input file: %s',input_filename),'Error')returnendfor l = 1:length(str1)value = eval(char(str2(l)));prmname= char(strread(char(str1(l)),'%s'));switch prmnamecase 'dx'prm.dx = value;case 'dt'prm.dt = value;case 'nx'prm.nx = value;case 'ntime'prm.ntime = value;case 'nplot'prm.nplot = value;case 'cv'prm.cv = value;case 'wc'prm.wc = value;case 'ajamp'prm.ajamp = value;case 'eamp'prm.eamp = value;case 'emax'prm.emax = value;case 'bamp'prm.bamp = value;case 'bmax'prm.bmax = value;case 'iex'prm.iex = value;case 'vmax'prm.vmax = value;case 'nv'prm.nv = value;case 'wj'prm.wj = value;case 'ns'prm.ns = value;case 'np'prm.np = value;case 'wp'prm.wp = value;case 'qm'prm.qm = value;case 'vpa'prm.vpa = value;case 'vpe'prm.vpe = value;case 'vd'prm.vd = value;case 'pch'prm.pch = value;case 'icolor'prm.icolor = value;case 'iparam'prm.iparam = value;case 'diagtype'prm.diagtype = value;case 'angle'prm.angle = value;otherwise%disp(sprintf('Plese check input parameter %s.',prmname))endendreturn;end?運行結果
>> kempo1mainstr1 =26×1 cell 數組{'dx ' }{'dt ' }{'nx ' }{'ntime ' }{'cv ' }{'wc ' }{'angle ' }{'ns ' }{'np ' }{'wp ' }{'qm ' }{'vpa ' }{'vpe ' }{'vd ' }{'pch ' }{'iex ' }{'ajamp ' }{'wj ' }{'nplot ' }{'nv ' }{'icolor ' }{'iparam ' }{'vmax ' }{'emax ' }{'bmax ' }{'diagtype '}str2 =26×1 cell 數組{'1.000000' }{'0.040000' }{'128.000000' }{'512.000000' }{'20.000000' }{'-1.000000' }{'0.000000' }{'2.000000' }{'[4096.000000, 4096.000000, ]' }{'[2.000000, 2.000000, ]' }{'[-1.000000, -1.000000, ]' }{'[1.000000, 1.000000, ]' }{'[0.000000, 0.000000, ]' }{'[-3.000000, 3.000000, ]' }{'[0.000000, 0.000000, ]' }{'2.000000' }{'0.000000' }{'0.000000' }{'256.000000' }{'100.000000' }{'1.000000' }{'1.000000' }{'20.000000' }{'10.000000' }{'0.200000' }{'[1.000000, 4.000000, 5.000000, 12.000000, ]'}prm = 包含以下字段的 struct:np: [4096 4096]>> input_param 輸入參數的數目不足。出錯 input_param (line 12)errordlg(sprintf('Can''t open input file: %s',input_filename),'Error')>> kempo1mainstr1 =26×1 cell 數組{'dx ' }{'dt ' }{'nx ' }{'ntime ' }{'cv ' }{'wc ' }{'angle ' }{'ns ' }{'np ' }{'wp ' }{'qm ' }{'vpa ' }{'vpe ' }{'vd ' }{'pch ' }{'iex ' }{'ajamp ' }{'wj ' }{'nplot ' }{'nv ' }{'icolor ' }{'iparam ' }{'vmax ' }{'emax ' }{'bmax ' }{'diagtype '}str2 =26×1 cell 數組{'1.000000' }{'0.040000' }{'128.000000' }{'512.000000' }{'20.000000' }{'-1.000000' }{'0.000000' }{'2.000000' }{'[4096.000000, 4096.000000, ]' }{'[2.000000, 2.000000, ]' }{'[-1.000000, -1.000000, ]' }{'[1.000000, 1.000000, ]' }{'[0.000000, 0.000000, ]' }{'[-3.000000, 3.000000, ]' }{'[0.000000, 0.000000, ]' }{'2.000000' }{'0.000000' }{'0.000000' }{'256.000000' }{'100.000000' }{'1.000000' }{'1.000000' }{'20.000000' }{'10.000000' }{'0.200000' }{'[1.000000, 4.000000, 5.000000, 12.000000, ]'}prm = 包含以下字段的 struct:np: {'[4096.000000, 4096.000000, ]'}>> input_param 輸入參數的數目不足。出錯 input_param (line 12)errordlg(sprintf('Can''t open input file: %s',input_filename),'Error')>> kempo1mainstr1 =26×1 cell 數組{'dx ' }{'dt ' }{'nx ' }{'ntime ' }{'cv ' }{'wc ' }{'angle ' }{'ns ' }{'np ' }{'wp ' }{'qm ' }{'vpa ' }{'vpe ' }{'vd ' }{'pch ' }{'iex ' }{'ajamp ' }{'wj ' }{'nplot ' }{'nv ' }{'icolor ' }{'iparam ' }{'vmax ' }{'emax ' }{'bmax ' }{'diagtype '}str2 =26×1 cell 數組{'1.000000' }{'0.040000' }{'128.000000' }{'512.000000' }{'20.000000' }{'-1.000000' }{'0.000000' }{'2.000000' }{'[4096.000000, 4096.000000, ]' }{'[2.000000, 2.000000, ]' }{'[-1.000000, -1.000000, ]' }{'[1.000000, 1.000000, ]' }{'[0.000000, 0.000000, ]' }{'[-3.000000, 3.000000, ]' }{'[0.000000, 0.000000, ]' }{'2.000000' }{'0.000000' }{'0.000000' }{'256.000000' }{'100.000000' }{'1.000000' }{'1.000000' }{'20.000000' }{'10.000000' }{'0.200000' }{'[1.000000, 4.000000, 5.000000, 12.000000, ]'}prm = 包含以下字段的 struct:np: '[4096.000000, 4096.000000, ]'>> kempo1mainstr1 =26×1 cell 數組{'dx ' }{'dt ' }{'nx ' }{'ntime ' }{'cv ' }{'wc ' }{'angle ' }{'ns ' }{'np ' }{'wp ' }{'qm ' }{'vpa ' }{'vpe ' }{'vd ' }{'pch ' }{'iex ' }{'ajamp ' }{'wj ' }{'nplot ' }{'nv ' }{'icolor ' }{'iparam ' }{'vmax ' }{'emax ' }{'bmax ' }{'diagtype '}str2 =26×1 cell 數組{'1.000000' }{'0.040000' }{'128.000000' }{'512.000000' }{'20.000000' }{'-1.000000' }{'0.000000' }{'2.000000' }{'[4096.000000, 4096.000000, ]' }{'[2.000000, 2.000000, ]' }{'[-1.000000, -1.000000, ]' }{'[1.000000, 1.000000, ]' }{'[0.000000, 0.000000, ]' }{'[-3.000000, 3.000000, ]' }{'[0.000000, 0.000000, ]' }{'2.000000' }{'0.000000' }{'0.000000' }{'256.000000' }{'100.000000' }{'1.000000' }{'1.000000' }{'20.000000' }{'10.000000' }{'0.200000' }{'[1.000000, 4.000000, 5.000000, 12.000000, ]'}prm = 包含以下字段的 struct:np: [4096 4096]>> '[4096.000000, 4096.000000, ]'ans ='[4096.000000, 4096.000000, ]'>> eval('[4096.000000, 4096.000000, ]')ans =4096 4096>> datastr(now) 未定義函數或變量 'datastr'。是不是想輸入: >> datestr(now)ans ='28-Oct-2021 15:46:05'>>總結
以上是生活随笔為你收集整理的[1维粒子模拟 version3.6]成功调试read input parameters的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第五节:简单又强大的数据类型:any任意
- 下一篇: 不要老去打断程序员的工作