How to Remedy Matrix Dimensions Error

3 次查看(过去 30 天)
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?

采纳的回答

Jon
Jon 2021-1-13
编辑:Jon 2021-1-13
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by