How to Remedy Matrix Dimensions Error

1 回表示 (過去 30 日間)
Nat Person
Nat Person 2021 年 1 月 13 日
編集済み: Jon 2021 年 1 月 13 日
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 Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by