2017-01-19 95 views
-1

爲什麼我的代碼不工作?我想存儲array_onearray_two at one varibale - >output_array!我想讀取像output_array(1)和output_array(1)這樣的值,但它不起作用。我收到以下錯誤信息:Matlab錯誤:尺寸不匹配 - 爲什麼?

錯誤消息:

Subscripted assignment dimension mismatch.

Error in jaenner19 (line 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 

有人可以幫我嗎?感謝你們。

回答

0

你想要存儲的是一個數組,在output_array的第一行。 因此,嘗試:

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

下一行

PS當然output_array(2,:)和我建議你在代碼中的switch-case結構內部的線路添加semicolumns。

+0

完美:)它的作品謝謝你 – Lutz