0

I am using the above code to generate COMTRADE files for different scenarios in the simulink. but whenever I add a display into the simulation model i get an error saying the following Caused by: Dimensions of arrays being concatenated are not consistent. How to resolve the issue so that i can use the display but at the same time, i want to create the COMTRADE file?

Following is the MATLAB code that i am using

  % Create the .dat file
clc
format short
NS1 = size(tout);                 % to find the number of samples
NS2 = NS1(1,1);
FileName = input('Please enter a file name:', 's');
FN_cfg = [FileName,'.cfg'];
FN_dat = [FileName,'.dat'];
Data =[transpose((1:1:NS2)) tout M];
csvwrite(FN_dat,Data)
unique(tout, 'rows', 'stable');
% Create the .cfg file
Config = {'Simulation',' ' ,'1999' ;
                '12', '12A', '0D'};
fileid = fopen(FN_cfg,'w');
for r = 1:size(Config,1)
     for c = 1:size(Config,2)
         var = eval(('Config{r,c}'));
         
         if size(var,1) == 0
            var = ' ';
         end
        
        if isnumeric(var) == 1
           var = num2str(var);
        end
       fprintf(fileid,var);
       if c ~= size(Config,2)
          fprintf(fileid,(','));
       end
    end
    fprintf(fileid, '\n');
end
fclose(fileid);
AC = {'1','Vr',' ',' ','V','1','0','0','-99999','99998','1','1','P';
      '2','Vy',' ',' ','V','1','0','0','-99999','99998','1','1','P';
      '3','Vb',' ',' ','V','1','0','0','-99999','99998','1','1','P';
      '4','Ir',' ',' ','A','1','0','0','-99999','99998','1','1','P';
      '5','Iy',' ',' ','A','1','0','0','-99999','99998','1','1','P';
      '6','Ib',' ',' ','A','1','0','0','-99999','99998','1','1','P';
      '7','Vr',' ',' ','V','1','0','0','-99999','99998','1','1','S';
      '8','Vy',' ',' ','V','1','0','0','-99999','99998','1','1','S';
      '9','Vb',' ',' ','V','1','0','0','-99999','99998','1','1','S';
     '10','Ir',' ',' ','A','1','0','0','-99999','99998','1','1','S';
     '11','Iy',' ',' ','A','1','0','0','-99999','99998','1','1','S';
     '12','Ib',' ',' ','A','1','0','0','-99999','99998','1','1','S'};
fileid = fopen(FN_cfg,'a');
for r = 1:size(AC,1)
     for c = 1:size(AC,2)
         var = eval(('AC{r,c}'));
         
         if size(var,1) == 0
            var = ' ';
         end
        
        if isnumeric(var) == 1
           var = num2str(var);
        end
       fprintf(fileid,(var));
       if c ~= size(AC,2)
          fprintf(fileid,(','));
       end
    end
    fprintf(fileid, '\n');
end
    fprintf(fileid, '50','\n');
    fprintf(fileid, '\n1');
    fprintf(fileid, '\n20000,');
    fprintf(fileid, '%1d',(NS2));
    fprintf(fileid, '\n%s', (datestr(now)));
    fprintf(fileid, '\n%s', (datestr(now)));
    fprintf(fileid, '\nASCII');
    fprintf(fileid, '\n1');
fclose(fileid);
disp('COMTRADE GENERATED!')
Pro
  • 1
  • Somewhere in your code you're trying to concatenate two (or more) arrays that can not be concatenated. The lengths of the dimensions should match except for the operating dimension. – obchardon Jan 23 '20 at 09:26
  • yes. that's in .data file generation. as a result i am getting the error. how can make the changes in the code in order to avoid the error? – Pro Jan 23 '20 at 09:42
  • Provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your problem. Actually we can not help you. – obchardon Jan 23 '20 at 10:25
  • The error message should tell you the line causing the problem. – Daniel Jan 23 '20 at 14:55
  • That's the problem. Its saying that the error is in .data file code i.e. Create the .dat file clc format short NS1 = size(tout); % to find the number of samples NS2 = NS1(1,1); FileName = input('Please enter a file name:', 's'); FN_cfg = [FileName,'.cfg']; FN_dat = [FileName,'.dat']; Data =[transpose((1:1:NS2)) tout M]; csvwrite(FN_dat,Data) unique(tout, 'rows', 'stable'); where to make the changes? – Pro Jan 24 '20 at 06:03

0 Answers0