Why can't I use a format statement that has alphanumeric, numeric and integer variables?

Here are two formats I want to use. They both come from FORTRAN format statements. The first is 6F7.0,2F3.0,2I3,I2,6A4, while the second is 5A4,A1,7F7.0. Since they are in fixed field lengths and represent a row matrix, why can't I use a format statement that has alphanumeric (char/string), numeric (floating point) and integer (non-floating point) variables?
fmt_num0=[repmat('%7f',1,6),repmat('%3f',1,2),repmat('%3d',1,2),'%2d',repmat('%24c',1,1)];
fmt_num3=[repmat('%21c',1,1),repmat('%7f',1,7)];
MATLAB gives me 'concatenated cell mismatch' or 'exceeded dimensions'.

 Accepted Answer

The lines of code you posted there work fine for me.
The error messages you report are consistent with the possibility that you created a variable named "repmat"

5 Comments

'repmat' was introduced before R2006a according to HELP documentation.
B = repmat(A,n) returns an array containing n copies of A in the row and column dimensions. The size of B is size(A)*n when A is a matrix.
B = repmat(A,r1,...,rN) specifies a list of scalars, r1,..,rN, that describes how copies of A are arranged in each dimension. When A has N dimensions, the size of B is size(A).*[r1...rN]. For example, repmat([1 2; 3 4],2,3) returns a 4-by-6 matrix.
B = repmat(A,r) specifies the repetition scheme with row vector r. For example, repmat(A,[2 3]) returns the same result as repmat(A,2,3).
@Kenneth Lamury: run this command:
which repmat -all
If you have (or added a toolbox that) redefined repmat then you might get an error like that. For this reason you shoudl always avoid using size, length, cell, i, i|j|, pi, etc, etc for variable names. You should always check using which if a name is already defined.
repmat might have been introduced in the very first MATLAB, but that cannot protect you from the possibility that you did
repmat('%7f',1,6) = 42;
which would have created a variable named "repmat" after which "repmat" would refer to the variable rather than the MATLAB routine.
Thank you. Got the following message
built-in (C:\Program Files\MATLAB\R2016a\toolbox\matlab\elmat\repmat)
C:\Program Files\MATLAB\R2016a\toolbox\shared\controllib\engine\@InputOutputModel\repmat.m % InputOutputModel method
C:\Program Files\MATLAB\R2016a\toolbox\symbolic\symbolic\@symfun\repmat.m
Also got '42' instead of a 24c title. Will go back to fscanf, cell2mat & textscan for my reads.
"Will go back to fscanf, cell2mat & textscan for my reads."
Just clean up your environment to eliminate any typos and ensure you don't accidentally alias repmat and all should be fine.
As shown in previous postings in the (seemingly interminable) quest, you're barking up the wrong tree in trying to duplicate Fortran in Matlab--use the facilities in Matlab as they're intended OR has often also been suggested, convert the Fortran you have to a mex file or, if you don't have the source but only an executable, use system to dispatch it and return its output or write a wrapper function that does it.

Sign in to comment.

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!