Matlab错误:尺寸不匹配 - 为什么?

时间:2017-01-19 09:37:12

标签: matlab

为什么我的代码不起作用?我想在一个varibale上存储 array_one array_two - >的 output_array !我想读取像output_array(1)和output_array(1)这样的值,但它不起作用。我收到以下错误消息:

错误讯息:

  

订阅的分配维度不匹配。

     

jaenner19(第37行)中的错误output_array(1)=   str2double(strsplit(diagramoptions.Value {的strcmp(diagramoptions.Key,   ' wsectionstart')}));

我的代码:

wholecontent = fileread('test1.txt') 
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens') 

for section = sections 
   switch(strtrim(section{1}{1})) 
       case 'Diagram Options' 
          keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens') 
          diagramoptions = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})   
       case 'Diagram Limits' 
          header = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once')) 
          content = textscan(section{1}{2}, repmat('%f', 1, numel(header)), 'HeaderLines', 2) 
          diagramlimits = table(content{:}, 'VariableNames', header)     
       case 'Input Data' 
          inputdata = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))           
      %*************************************************************************************************
       case 'Diagram Options2' 
          keyvalues2 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens') 
          diagramoptions2 = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})     
       case 'Diagram Limits2' 
          header2 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once')) 
          content2 = textscan(section{1}{2}, repmat('%f', 1, numel(header2)), 'HeaderLines', 2) 
          diagramlimits2 = table(content2{:}, 'VariableNames', header2)     
       case 'Input Data2' 
          inputdata2 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))   
      %*************************************************************************************************   
      otherwise 
          warning('Unknown section: %s', section{1}{1}) 
   end 
end 

output_inputdata_column = inputdata(:,1) 
output_inputdata_coulumn2 = inputdata2(:,1) 

array_one=str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
array_two=str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));

output_array(1) = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));
output_array(2) = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions2.Key, 'wsectionstart')}));

%öffnet die output fenster 
openvar diagramoptions 
openvar diagramlimits 
openvar inputdata 
openvar diagramoptions2 
openvar diagramlimits2 
openvar inputdata2

我的输入:test1.txt

******************* Diagram Options****************
rainflow=1
woehler=0
number_of_plots=4
color=red
linewidth=12
header=Number of cycles
xlabel= RPM
ylabel= Amount
cutoffvalue=53
equivcycles=1e6
equivstress=40
wsectionslope=3 3 3
ordinatelogarithmic=false
wsectionstart=1000 5000000 3000000
wsectionsend=5000000 1000000000 30000000
wsectionlinestyle=cont dashed cont
wsectionstartstress=58.02349610358 58.02349610358 130
******************* Diagram Limits****************
xmin xmax ymin ymax zmin zmax
1   111 1111111 1   1   11
*******************Input Data****************
-220.8  228 50045
-222    201.6   50045

******************* Diagram Options2****************
number_of_plots=4
wsectionstart=100 700000 308800
******************* Diagram Limits2****************
xmin xmax ymin ymax zmin zmax
0   0   100000  1   1   1100000
*******************Input Data2****************
106.62  1
106.62  50045
94.2741 50045

有人能帮助我吗?谢谢你们。

1 个答案:

答案 0 :(得分:0)

您要存储的内容是output_array第一行中的数组。 所以试试:

output_array(1,:) = str2double(strsplit(diagramoptions.Value{strcmp(diagramoptions.Key, 'wsectionstart')}));

,当然还有下一行的output_array(2,:)

PS和我建议你在switch-case结构内的代码行中添加semicolumns。