Lookup tables for ICE data mapping
    조회 수: 7 (최근 30일)
  
       이전 댓글 표시
    
I'm modeling the control of ICE injection mass flow in the simulink and have a data set which is given in the Pict.1 and in text file. X1 represents u1 , X2 represents u2 and Y represents the output data (table data). I need to import/generate this data into my simulink model.
since there is no option for slicing in lookup table same as the given data set, I clone each X2 column slice value to its corresponding row in order to have same dimension. Then,I'm importing all datas to workspace and calling them into 2D-Lookup table as shown in the Pict.2
what I get is ; "Error occurred while retrieving data, check the selected block's parameter setting. The number of dimensions in the table data is 1 while the number of dimensions specified in the block is 2. They must match."
Can anybody help me to create such mapping in the simulink?


댓글 수: 1
  Rik
      
      
 2019년 4월 1일
				I barely have any experience with simulink, nor do I have a license for it anymore, so I'm unable to help you.
채택된 답변
  Luna
      
 2019년 3월 29일
        
      편집: Luna
      
 2019년 4월 3일
  
      What do you mean by slicing? Unfortunetely I can't look at the text file but as far as I understand you have a set of data for each engine rpm right? Why don't you create a 2D map for it with binning your data? 
So you will get a matrix and you can use it. (X-Data - engine rpm, Y-Data torque and Z-Data is mass flow) Z is a matrix and your look up table's values must contain this.
2D Lookup table must be a matrix with NxM size. N is number of rpm values, M is number of torque values. For each rpm and torque there should be a mass flow value. 
OK I wrote some code for your problem: 
Please carefully read my comments. As I said before 2D Map is something that you should provide to Simulink an Nx1 vector as X-Data,  Mx1 vector as Y-Data and NxM matrix for Z-Data.
Here you can create a surface fit below code: 
% First you should create engine speeds as follows. For each Engine Speed &
% Torque value pair you should have a corresponding mass flow:
Array = [
1000	37.99	40.021
1000    53.89	42.215
1000	69.84	31.288
1000	85.61	23.101
1000	101.48	16.324
1000	117.37	9.863
1000	133.1	3.985
1000	149.13	1.011
1000	164.74	1.198
1000	171.89	1.877
1250	38.4	41.592
1250	54.22	42.831
1250	70.07	28.767
1250	85.96	23.155
1250	101.71	15.349
1250	117.68	9.255
1250	133.6	5.865
1250	149.56	3.185
1250	165.35	1.327
1250	181.25	0.748
1250	197.1	0.954
1250	213	1.643
1250	221.78	1.494
1500	39.06	51.209
1500	55.11	51.712
1500	70.9	37.636
1500	86.64	28.29
1500	102.56	20.582
1500	118.48	16.481
1500	134.37	12.538
1500	150.26	7.596
1500	166.16	5.224
1500	181.86	3.612
1500	197.81	2.014
1500	213.78	1.12
1500	229.55	0.59
1500	245.6	0.732
1500	261.3	1.132
1500	277.18	1.201
1500	293.17	1.292
1500	308.82	1.207
1500	324.99	1.196
1500	327.08	1.15
1750	40.53	44.075
1750	56.3	38.544
1750	72.29	27.216
1750	88.07	19.197
1750	104.02	13.684
1750	119.85	11.483
1750	135.8	8.885
1750	151.65	7.951
1750	167.51	5.492
1750	183.3	3.555
1750	199.26	3.284
1750	215.02	3.17
1750	231.04	2.808
1750	246.82	1.239
1750	262.81	0.593
1750	278.67	0.632
1750	294.46	0.623
1750	310.39	0.629
1750	326.35	0.628
1750	342.25	0.611
1750	358.1	0.602
1750	373.88	0.614
1750	389.95	0.571
1750	393.08	0.566
2000	42.31	41.252
2000	58.18	35.334
2000	74.09	26.964
2000	89.91	22.084
2000	105.84	18.528
2000	121.68	17.843
2000	137.52	16.29
2000	153.46	15.606
2000	169.39	13.433
2000	185.18	10.441
2000	201.16	7.444
2000	217.02	6.153
2000	232.92	6.462
2000	248.72	3.829
2000	264.57	0.612
2000	280.41	0.583
2000	296.3	0.652
2000	312.08	0.714
2000	328.08	0.72
2000	344.06	0.633
2000	359.84	0.568
2000	375.74	0.54
2000	391.5	0.544
2000	392.33	0.537
2250	44.34	30.37
2250	60.28	29.271
2250	76.15	26.143
2250	92.11	24.353
2250	107.93	21.091
2250	123.92	20.639
2250	139.68	18.97
2250	155.63	19.485
2250	171.56	18.788
2250	187.33	15.256
2250	203.3	12.87
2250	219.13	10.077
2250	234.97	5.91
2250	251.02	1.579
2250	266.89	0.556
2250	282.41	0.544
2250	298.56	0.619
2250	314.34	0.696
2250	330.28	0.629
2250	346.51	0.615
2250	362.13	0.545
2250	377.9	0.521
2250	390.92	0.522
2500	46.83	23.842
2500	63.02	22.133
2500	78.78	20.214
2500	94.65	18.53
2500	110.36	18.284
2500	126.38	18.576
2500	142.34	18.376
2500	158.13	17.96
2500	174.04	17.716
2500	189.8	12.734
2500	205.67	3.909
2500	221.6	2.697
2500	237.56	2.329
2500	253.38	1.429
2500	269.25	0.574
2500	285.14	0.61
2500	300.92	0.647
2500	316.92	0.649
2500	332.78	0.639
2500	348.62	0.65
2500	364.48	0.626
2500	380.37	0.635
2500	390.75	0.634
2500	390.8	0.628
2750	49.86	16.082
2750	65.7	18.974
2750	81.58	18.798
2750	97.4	19.244
2750	113.25	19.278
2750	128.94	18.93
2750	145.12	16.513
2750	160.94	14.929
2750	176.86	13.477
2750	192.73	4.865
2750	208.51	3.177
2750	224.56	2.645
2750	240.33	2.52
2750	256.04	0.563
2750	272.1	0.56
2750	287.85	0.556
2750	303.9	0.635
2750	319.74	0.589
2750	335.54	0.598
2750	351.42	0.604
2750	367.29	0.593
2750	383.16	0.609
2750	391.6	0.548
3000	52.9	1.708
3000	68.78	1.391
3000	84.63	1.195
3000	100.4	1.048
3000	116.33	0.92
3000	132.32	0.846
3000	148.16	0.773
3000	163.92	0.738
3000	179.92	0.712
3000	195.79	0.682
3000	211.67	0.639
3000	227.58	0.593
3000	243.44	0.538
3000	259.25	0.514
3000	275.23	0.484
3000	291.13	0.547
3000	306.97	0.59
3000	322.87	0.591
3000	338.78	0.618
3000	354.65	0.622
3000	370.5	0.597
3000	386.2	0.574
3000	392.04	0.544
3250	56.1	1.555
3250	72.01	1.312
3250	87.89	1.166
3250	103.63	1.01
3250	119.58	0.913
3250	135.57	0.838
3250	151.2	0.755
3250	167.44	0.711
3250	183.07	0.701
3250	198.93	0.65
3250	214.77	0.62
3250	230.78	0.586
3250	246.59	0.544
3250	262.53	0.525
3250	278.47	0.526
3250	294.26	0.547
3250	310.14	0.554
3250	325.9	0.554
3250	341.93	0.563
3250	357.83	0.567
3250	373.75	0.56
3250	383.44	0.555
3500	59.57	1.504
3500	75.25	1.287
3500	91.12	1.119
3500	106.81	0.984
3500	122.95	0.875
3500	138.76	0.805
3500	154.67	0.723
3500	170.48	0.683
3500	186.18	0.662
3500	202.22	0.622
3500	218.19	0.585
3500	234.13	0.564
3500	249.94	0.544
3500	265.88	0.553
3500	281.73	0.605
3500	297.46	0.621
3500	313.47	0.597
3500	329.28	0.594
3500	345.23	0.601
3500	361.11	0.598
3500	364.03	0.603
3750	62.65	1.492
3750	78.6	1.249
3750	94.49	1.081
3750	110.26	0.966
3750	126.16	0.878
3750	142.02	0.817
3750	157.95	0.753
3750	173.9	0.709
3750	189.68	0.681
3750	205.41	0.653
3750	221.47	0.623
3750	237.43	0.598
3750	253.18	0.61
3750	269.13	0.597
3750	285.02	0.61
3750	300.91	0.616
3750	314.27	0.62
3750	332.56	0.625
3750	348.52	0.652
3750	354.73	0.677
4000	66.07	1.456
4000	82.15	1.213
4000	97.56	1.049
4000	113.62	0.931
4000	129.72	0.844
4000	145.38	0.783
4000	161.33	0.757
4000	177.29	0.762
4000	193.26	0.721
4000	209.07	0.685
4000	224.85	0.644
4000	240.85	0.613
4000	256.58	0.608
4000	272.5	0.624
4000	288.41	0.64
4000	304.28	0.656
4000	320.22	0.632
4000	335.95	0.631
4000	340.11	0.612
4500	71.99	1.398
4500	87.97	1.165
4500	103.8	1.012
4500	119.64	0.908
4500	135.37	0.831
4500	151.38	0.752
4500	167.23	0.74
4500	183.19	0.714
4500	199.05	0.745
4500	214.88	0.653
4500	230.77	0.635
4500	246.69	0.598
4500	262.58	0.67
4500	278.45	0.685
4500	294.4	0.718
4500	295	0.717
5000	77.96	1.546
5000	93.72	1.353
5000	109.58	1.232
5000	125.53	1.143
5000	141.33	1.115
5000	157.25	1.088
5000	173.03	1.054
5000	189.02	1.05
5000	204.97	1.011
5000	220.75	0.864
5000	236.72	0.933
5000	252.5	1.033
5000	259.68	0.918
];
% Seperate columns
X2 = Array(:,1); % Engine Speed (rpm)
X1 = Array(:,2); % Torque (Nm)
Y  = Array(:,3); %  mass flow
% You should fit a surface for above data to use in Simulink. 
%2D Lookup Table has X-Axis and Y-Axis and Z-Data (It has to be NxM matrix)
% Surface fit for the data (you can also use curve fittig tool by typing cftool to command window and export your fitted map)
ft = 'lowess';
[fitresult, gof] = fit( [X2, X1], Y, ft, 'Normalize', 'on' ); % fits the surface
SpeedVals = [1000:250:4000 4500 5000]; % Your Engine Speed Values (You can put anything you want here, from now on fitresult will calculate for you the mass flow for each speed-torque pair)
TorqVals = 40:20:400; % Same for SpeedVals
% !!!! You can also use your own X2 and X1 as SpeedVals and TorqueVals. 
% In this case you will have 15x295 size Matrix.
mapData = zeros(numel(SpeedVals),numel(TorqVals));
for i = 1:numel(SpeedVals) 
    for j = 1:numel(TorqVals)        
      mapData(i,j) = fitresult(SpeedVals(i),TorqVals(j));  
    end
end
%% Now your Simulink's 2D Lookup Tables one column is SpeedVals(X2), other Column is TorqVals(X1) and the lookup table data is mapData(Y). 
%% %%%%% DEMO FOR USING YOUR OWN X2 and X1: 
SpeedVals2 =  unique(X2);
TorqVals2  = unique(X1);
mapData2 = zeros(numel(SpeedVals2),numel(TorqVals2));
for i = 1:numel(SpeedVals2) 
    for j = 1:numel(TorqVals2)        
      mapData2(i,j) = fitresult(SpeedVals2(i),TorqVals2(j));  
    end
end
% You can see mapData2 is 15x295. So if you feed that to Simulink 2D lookup by using SpeedVals2 and TorqVals2 there won't matrix dimensions error anymore.
댓글 수: 8
  Luna
      
 2019년 4월 3일
				edit note: I realized a mistake in the code inside the for loop and corrected it. Please check again.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 General Applications에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


