|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
matlab to octave code errorsHi, I'm trying to run Matlab code in Octave, and i'm getting the following errors:
warning: function name `fem1d2n' does not agree with function file name `C:\Matlab\fem1d.m' error: `N' undefined near line 54 column 10 error: evaluating argument list element number 1 error: evaluating for command near line 52, column 1 error: called from `fem1d:InputData' in file `C:\Matlab\fem1d.m' error: called from `fem1d' in file `C:\Matlab\fem1d.m' here is the .m file i'm trying to run, thank you for your help: fem1d.m -Smed |
|
|
Re: matlab to octave code errorsOn Tue, Jun 9, 2009 at 2:55 AM, smed<spontarelliam@...> wrote:
> > Hi, I'm trying to run Matlab code in Octave, and i'm getting the following > errors: > > warning: function name `fem1d2n' does not agree with function file name > `C:\Matlab\fem1d.m' > > error: `N' undefined near line 54 column 10 > error: evaluating argument list element number 1 > error: evaluating for command near line 52, column 1 > error: called from `fem1d:InputData' in file `C:\Matlab\fem1d.m' > error: called from `fem1d' in file `C:\Matlab\fem1d.m' > > here is the .m file i'm trying to run, thank you for your help: > http://www.nabble.com/file/p23934669/fem1d.m fem1d.m > > -Smed Hi If it works in Matlab, then probably the "deal" function works differently in Octave. You can try to rewrite line 54 in two separate lines (though I didn't test it, as your program requires additional input files): % [N, X(N,:)]=deal(TMP(1),TMP(2:1+NDIM)); N = TMP(1); X(N,:) = TMP(2:1+NDIM); Regards Ivan Sutoris _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsOn Tue, Jun 9, 2009 at 2:55 AM, smed<spontarelliam@...> wrote:
> > Hi, I'm trying to run Matlab code in Octave, and i'm getting the following > errors: > > warning: function name `fem1d2n' does not agree with function file name > `C:\Matlab\fem1d.m' > > error: `N' undefined near line 54 column 10 > error: evaluating argument list element number 1 > error: evaluating for command near line 52, column 1 > error: called from `fem1d:InputData' in file `C:\Matlab\fem1d.m' > error: called from `fem1d' in file `C:\Matlab\fem1d.m' > > here is the .m file i'm trying to run, thank you for your help: > http://www.nabble.com/file/p23934669/fem1d.m fem1d.m > > -Smed > > Could you provide also sample input files so that we can actually try the code? -- RNDr. Jaroslav Hajek computing expert & GNU Octave developer Aeronautical Research and Test Institute (VZLU) Prague, Czech Republic url: www.highegg.matfyz.cz _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsThank you for your response. I tried your suggestion, but i'm still getting errors. warning: function name `fem1d2n' does not agree with function file name `C:\Matlab\fem1d.m' error: invalid matrix index = 1 error: evaluating argument list element number 1 error: evaluating for command near line 79, column 1 error: called from `fem1d:InputData' in file `C:\Matlab\fem1d.m' error: called from `fem1d' in file `C:\Matlab\fem1d.m' FEM1D.INP Here is the input file I'm using, and yes it works in matlab. Thanks again. |
|
|
Re: matlab to octave code errorsOn 9-Jun-2009, smed wrote:
| Ivan Sutoris wrote: | > | > Hi | > | > If it works in Matlab, then probably the "deal" function works | > differently in Octave. You can try to rewrite line 54 in two separate | > lines (though I didn't test it, as your program requires additional | > input files): | > | > % [N, X(N,:)]=deal(TMP(1),TMP(2:1+NDIM)); | > N = TMP(1); | > X(N,:) = TMP(2:1+NDIM); It's not a problem with deal, but with the way multi-assignments are handled. Apparently Matlab is creating the variable N before evaluating the second element in the assignment and Octave is not. This problem should probably be fixed, but as Ivan notes, you can easily work around it yourself by using a temporary variable. | Thank you for your response. I tried your suggestion, but i'm still getting | errors. | | warning: function name `fem1d2n' does not agree with function file name | `C:\Matlab\fem1d.m' | | error: invalid matrix index = 1 | error: evaluating argument list element number 1 | error: evaluating for command near line 79, column 1 | error: called from `fem1d:InputData' in file `C:\Matlab\fem1d.m' | error: called from `fem1d' in file `C:\Matlab\fem1d.m' | | http://www.nabble.com/file/p23941353/FEM1D.INP FEM1D.INP | | Here is the input file I'm using, and yes it works in matlab. Thanks again. OK, this problem seems to be happening here: DUMMY = fgets(LINP) F = zeros(NN,1); for I=1:NL TMP = str2num(fgets(LINP)); [N,tmp]=deal(TMP(1),TMP(2)); F(N) = tmp; end when indexing TMP in the call to deal. If I look at the value of TMP, it is [], because fgets(LINP) is returning "DOF# Load". Are you sure FEM1D.INP is a valid input file for your program? It seems that ND is 1, but there are 4 lines of displacements. Is that correct? jwe _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsFirst, you get a warning because Matlab language is biased towards a
development style where procedures are written one at a time into individual *.m files named after the function defined in the file (i.e. file xyz.m contains function x=xyz(a,b) .... endfunction). You can break this assumption but then Octave and Matlab will have harder time finding the code, and some nice things won't work, like for instance reloading the file if you edit the procedure while running the interpreter. As you can see, this is a warning, so you can ignore it if you prefer. Unfortunately, your code seems to contain errors: specifically, I think that it uses uninitialized variable N. From the context, I would guess that the authors confused I and N: %----- Coordinates ----- DUMMY = fgets(LINP); for I=1:NN TMP = str2num(fgets(LINP)); [N, X(N,:)]=deal(TMP(1),TMP(2:1+NDIM)); end _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsOn 9-Jun-2009, John W. Eaton wrote:
| On 9-Jun-2009, smed wrote: | | | Ivan Sutoris wrote: | | > | | > Hi | | > | | > If it works in Matlab, then probably the "deal" function works | | > differently in Octave. You can try to rewrite line 54 in two separate | | > lines (though I didn't test it, as your program requires additional | | > input files): | | > | | > % [N, X(N,:)]=deal(TMP(1),TMP(2:1+NDIM)); | | > N = TMP(1); | | > X(N,:) = TMP(2:1+NDIM); | | It's not a problem with deal, but with the way multi-assignments are | handled. Apparently Matlab is creating the variable N before | evaluating the second element in the assignment and Octave is not. | This problem should probably be fixed, but as Ivan notes, you can | easily work around it yourself by using a temporary variable. I looked at fixing this problem, but I don't see a simple solution. I'm starting a new thread on the maintainers list about it. jwe _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsI apologize, you were right about the input file having a problem. This is the correct .inp file that works in MatLab, however, it still gives me trouble in octave. After applying your fix to line 54, I now get:
error: invalid vector index = 0 error: evaluating binary operator `-' near line 144, column 16 error: evaluating assignment expression near line 144, column 8 error: evaluating for command near line 140, column 1
-Smed On Tue, Jun 9, 2009 at 14:23, John W. Eaton <jwe@...> wrote:
_______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsOn 9-Jun-2009, Adam Spontarelli wrote:
| I apologize, you were right about the input file having a problem. This is | the correct .inp file that works in MatLab, however, it still gives me | trouble in octave. After applying your fix to line 54, I now get: | | error: invalid vector index = 0 | | error: evaluating binary operator `-' near line 144, column 16 | | error: evaluating assignment expression near line 144, column 8 | | error: evaluating for command near line 140, column 1 There are other places where you need a similar change. Also, some might not be obvious, or detected in the same as the first. For example, once N is defined on line 54, the expression on lines 63 and 64: [N,NOC(N,:), MAT(N,:), AREA(N,:), DT(N,:)] = ... deal(TMP(1),TMP(2:1+NEN), TMP(2+NEN), TMP(3+NEN), TMP(4+NEN)); will probably not do what you expect. In any case, it seems to me that all the uses of deal in your file are somewhat questionable. I see no good reason to write the above with a call to deal. Instead, I would recommend writing this expression as the series of assignments N = TMP(1); NOC(N,:) = TMP(2:1+NEN); MAT(N,:) = TMP(2+NEN); AREA(N,:) = TMP(3+NEN); DT(N,:) = TMP(4+NEN); After I made changes like this, your example worked up to the point of calling the function "bansol", which you did not provide and which is not part of Octave (or Matlab, as far as I can tell). jwe _______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: matlab to octave code errorsSorry I did not include bandsol.m . I obviously did not write this code, it was provided in a textbook that i'm trying to use for a project. I ran the program with your changes and it worked, but the answers came out as "NaN" which is junk. Are you certain that the change you made didn't affect the logic?
Thank you. On Tue, Jun 9, 2009 at 15:01, John W. Eaton <jwe@...> wrote:
_______________________________________________ Help-octave mailing list Help-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/help-octave |
| Free embeddable forum powered by Nabble | Forum Help |