How to Remedy Matrix Dimensions Error
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Jon
le 13 Jan 2021
Modifié(e) : Jon
le 13 Jan 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!