How to Resolve Subscript Indices Error in f2matlab Conversion?

  • Context: MATLAB 
  • Thread starter Thread starter cre_96
  • Start date Start date
Click For Summary
SUMMARY

The forum discussion addresses the "Subscript indices must either be real positive integers or logicals" error encountered when using the f2matlab tool to convert Fortran 90 (.f90) source code into MATLAB code. The error arises because MATLAB does not support zero-based indexing, which is common in Fortran. To resolve this issue, users should adjust their Fortran code to use one-based indexing, ensuring that loop variables start from 1 instead of 0. This adjustment will allow f2matlab to function correctly without generating subscript index errors.

PREREQUISITES
  • Understanding of Fortran 90 programming
  • Familiarity with MATLAB syntax and indexing
  • Knowledge of the f2matlab conversion tool
  • Basic debugging skills in MATLAB
NEXT STEPS
  • Review MATLAB's indexing rules and conventions
  • Learn how to use f2matlab effectively for code conversion
  • Explore techniques for debugging MATLAB errors
  • Investigate best practices for transitioning from Fortran to MATLAB
USEFUL FOR

This discussion is beneficial for software developers, particularly those transitioning code from Fortran to MATLAB, as well as educators teaching programming concepts in both languages.

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 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
10K