How to Remedy Matrix Dimensions Error

조회 수: 3 (최근 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 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