Changing Simulink's inputs through a loop from an m-file
이전 댓글 표시
Hello! I'm trying to run a simulink model from an m-file using a for-loop. The model takes input from an excel file (2 equal columns: one for time and one for 220 variables)through signal builder and I am interested in the output variable in order to evaluate the inputs.
In every loop the data in the excel from which simulink reads changes but I think signal builder takes data only the first time and keeps the same data for all the loops so the final variable stays the same. Is there any command to "update" signalbuilder in every loop?
In order to solve this, I also tried to use: " BLOCK = signalbuilder(PATH, 'CREATE', TIME, DATA, SIGNAMES, GROUPNAMES)" but leads to an error: "Error evaluating expression 't_tot' for 'StopTime' specified in the Configuration Parameters dialog for block diagram 'MODEL': Undefined function or variable 't_tot'.
I had the same problem before and by putting "options=simset('SrcWorkspace','current','DstWorkspace','current'); " was solved. But when I write the PATH here comes again..
My code is:
(First the are writen all the variables that I normally paste in Matlab in order for my model to run)
x=zeros(POPSIZE,NVARS); for i=1:NVARS for mem=1:POPSIZE x(i,mem)=population(mem).gene(i); end end
y=zeros(NVARS,1); filename2='simulinkreadsfromhere.xlsx';
for mem=1:POPSIZE y=population(mem).gene; xlswrite(filename2,y',1,'B1:B220');
TIME=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 14 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 123 124 125 126 127 128 129 130 131 132 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219]';
DATA=y';
PATH=MODEL/Race_track/lap_speed_selector/test;
BLOCK = signalbuilder(PATH, 'CREATE', TIME, DATA, SIGNAMES, GROUPNAMES);
options=simset('SrcWorkspace','current','DstWorkspace','current');
sim('MODEL.slx', [0 50], options);
population(mem).fitness=mean(power);
end
Any suggestions would be welcomed! Thanks in advance!
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!