How to Remedy Matrix Dimensions Error

3 visualizzazioni (ultimi 30 giorni)
Nat Person
Nat Person il 13 Gen 2021
Modificato: Jon il 13 Gen 2021
I am testing to see if a program that was written with Matlab 2019a will work on Matlab 2012a and I'm running into an error I don't know how to adress. When I run the program it throws an error saying:
"Error using +
Matrix dimensions must agree.
Error in ProcessFilesTry (line 49)
FM = dir(fullfile(filepath,'Processfiles\*FM')+ number+ '_*.ep'); %Pull out the final measurement file being used"
In reference to this block of code
for i = start:out
num_strfinal = num2str(i, '%02.f'); %cast the number as a string (make the format be 0#)
number = char(num_strfinal);
FM = dir(fullfile(filepath,'Processfiles\*FM')+ number+ '_*.ep'); %Pull out the final measurement file being used
FinalM = getfield(FM, 'name'); %pull out and save the name field
IN = dir(fullfile(filepath,'Processfiles\*InM')+ number + '_*.ep'); %Pull out the initial measurment file being used
InitialM = getfield(IN, 'name'); %pull out and save the name field
Can someone explain what this error means for Matlab 2012a and any pointers on how to remedy it?

Risposta accettata

Jon
Jon il 13 Gen 2021
Modificato: Jon il 13 Gen 2021
I think the + operator for strings was not available in 2012 you should instead concatenate the strings e.g.
FM = [dir(fullfile(filepath,'Processfiles\*FM'),number, '_*.ep')]
note if the dir returns more than one file name, the above will not work and you will need to take additional steps to deal with the individual filenames, for example using a loop

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by