MATLAB How to Resolve Subscript Indices Error in f2matlab Conversion?

  • Thread starter Thread starter cre_96
  • Start date Start date
AI Thread Summary
The discussion centers on an error encountered while using the f2matlab tool to convert Fortran 90 source code into MATLAB code. The user receives an error message indicating that subscript indices must be real positive integers or logicals. A key point raised is that MATLAB indexing starts at 1, unlike Fortran, which can use zero-based indexing. To resolve the issue, it is suggested to modify the Fortran code so that the indices for variables like i and j start from 1 instead of 0. This adjustment is necessary for proper conversion and to avoid the subscript error in MATLAB. The conversation highlights the importance of understanding indexing differences between programming languages when performing code conversions.
cre_96
Messages
2
Reaction score
0
Hi!
I've got some trouble with using f2matlab.
I need to convert a f90 source code into MATLAB code.In order to do this i type on MATLAB command window:
>>f2matlab('filename.f90');
but MATLAB displays the following error:

? Subscript indices must either be real positive integers or logicals.

Error in ==> f2matlab at 130
if ~inastring_f(filestr(temp7(temp6(j)):temp7(temp6(i))),temp7(temp6(i))-temp7(temp6(j))+1)

Does anybody know how to fix it?
:cry:
 
Physics news on Phys.org
I would think that your i (or j) goes from 0,1,2,3,...

temp6(0), temp6(1),...

Matlab doesn't reference elements at zero.

Maybe try rewriting the fortran code so that i and j go from 1,2,3,...

temp6(1), temp6(2),... =equal the old temp6(0), temp6(1),...

(I haven't used f2matlab but would have assumed that it reassigned these calls automatically (same if I ever wanted to convert C to Matlab).)
 

Similar threads

Replies
2
Views
3K
Replies
5
Views
2K
Replies
3
Views
3K
Replies
1
Views
8K
Replies
1
Views
2K
Replies
2
Views
10K
Back
Top