MATLAB Answers

Why am I getting "Dimensions of matrices being concatenated are not consistent." after 53 successful reads?

3 views (last 30 days)
Kenneth Lamury
Kenneth Lamury on 13 Jul 2016
Commented: Kenneth Lamury on 15 Jul 2016
I'm puzzled about this error message after 53 successful reads using the same setup. "Spoiler" inputs print out as "2nd Control Surface" inputs. I've made certain that the input (from an old FORTRAN card deck) has separators (',' or ' ' ), but suddenly it stops working. Also, I did not ask to skip any lines of input.
-.0014 -.0008 -.0153 -.0187 -.0063 -.0207 -.012 -.0064 -.0052 -.0046 SPOILER,ALSP
-.0009 .00123 .0014 -.00085-.00438 .0058 .00295 .00297 .0063 .00838 INPUTS,CMSP
.001 0 0 0 0 0 0 0 0 0 2ND CONTROL,ALFLAP
.001 0 0 0 0 0 0 0 0 0 SURFACE,CMFLAP
fmt_num1='%7f%7f%7f%7f%7f%7f%7f%7f%7f%7f'; % 10F7.0
fgetl(fid);
XYc=textscan(fid,fmt_num1,1);
XY=cell2mat(XYc); % line 373
for i=1:L
ALSP(i)=XY(i);
end
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 75)
m{n} = cat(2,c{n,:});
Error in CNSMTX (line 373)
XY=cell2mat(XYc);
  5 Comments

Sign in to comment.

Accepted Answer

dpb
dpb on 14 Jul 2016
Edited: dpb on 14 Jul 2016
It fails after the 53rd record because the format changes...
...
49 8.5713 7.0532 6.9459 6.6719 6.915 6.9 6.9 7.4086 9.703 10.7462 M0
50 .0193 .0248 .0414 .003 .0073 .0198 .031 .0249 .0097 .0081 ALPHA
51 -.06 -.0490 -.0526 -.0564 -.0294 -.0384 -.0315 -.0218 -.0138 -.0115 CM0
52 .0913 .0843 .0814 .0608 -.0858 -.1498 -.1954 -.2034 -.2603 -.3058 DCMDCL7
53 0.0 TMACH=0
54 -.0014 -.0008 -.0153 -.0187 -.0063 -.0207 -.012 -.0064 -.0052 -.0046 SPOILER
55 -.0009 .00123 .0014 -.00085 -.0044 .0058 .00295 .00297 .0063 .00838 INPUTS
56 .000 0 0 0 0 0 0 0 0 0 2ND CONTROL
57 .000 0 0 0 0 0 0 0 0 0 SURFACE
58 .5 0 0 THRPIT°
59 .10 1
60 -.00200 .0665-.00100 .0292
61 -.00340 .0716-.00140 .0292
...
Where I added the line numbers before the records. This includes the header line in the count. Note the group line 49ff is four records of 10 followed by 1 record of one. That's the preceding pattern as well but beginning at record 54 there are the four records but then there's a record of three before the single entry; a different pattern.
After that, the pattern changes again.
Glancing at the m-file, it appears you've done precisely what I recommended most strongly against in trying to literally write the Fortran code in Matlab--instead, spend the time on either Walter's or my suggestions and you'll come out far ahead; I really don't see if you have the existing files why not just use the Fortran with a Matlab wrapper...
Alternatively, if you're adamant on moving the application entirely to Matlab, write it in Matlab from scratch using the features that make Matlab what it is--vectorize the operations and convert the input files into something that can be easily handled with the C i/o routines that are the basis for Matlab's formatted i/o. What you'll end up on the route you're currently embarked upon will be a nightmare going forward for any purpose.
  4 Comments
Kenneth Lamury
Kenneth Lamury on 15 Jul 2016
I'm still not understanding your parsing, but do not fear for I think the attached CNSMTX script file shows my success at reading FORTRAN fixed field formatting (ZLS918_KCR_Test_Dwn.m) and output on the screen and a storage file.
I'm still not relating types of variables, classes, etc. I'm still struggling to remember as many keywords as I can. Rather than playing flying simulator games, learning MATLAB & MathCad are becoming my enjoyments.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!