Strange error with use of the function."diff"
1 次查看(过去 30 天)
显示 更早的评论
Good morning. I request your help with a very strange problem that is happening to me. It happens that I have a code (of 664 lines of code) in which there is a very punctual part in which I use the function -diff-. The programming in said worked well and according to my needs, but then I had to add some lines of code before the part that contained the programming with the function -diff- (this part of the code that I had to add helped me to create it a user from the matlab help forum, here the link: https://la.mathworks.com/matlabcentral/answers/468864-how-can-i-show-a-matrix-of-type-cell-in-a-msgbox?s_tid=prof_contriblnk). The lines of code that helped me create the partner worked wonders for what I needed, however the part that I had programmed (the one that contained the -diff- function) had stopped working, showing an error:
467 [FxNT,FyNT]=size(NodosT);
469 Num_nodos = ( NodosT ( 1:FxNT , 2 ) )' ;
470 X = diff(Num_nodos)~=0;
Index exceeds matrix dimensions.
Error in form2>CalcularDin_Callback (line 470)
X = diff(Num_nodos)~=0;
form2>CalcularDin_Callback
hObject handle to CalcularDin (see GCBO)
eventdata reserved - to be defined in a future version of MATLAB
handles structure with handles and user data (see GUIDATA)
I do not know if it is necessary to send you all my code lines before and after the introduction of the code lines.
I enclose all my code lines before and after (in two zip) of the introduction of the code lines. The error occurs on line 614 of the code with the new programming (a zip file named "latest").
The enter to get to that line of code does as follows:
1) In the "form1.fig" the "import" button is given and this file is placed in the excel, then the "Matrix rigides K's" button is given
2) The "form2.fig" is automatically opened where you can fill the fields with this information:
* In the table of 3 rows: -file 1: floor: 3, mass: 30000 -file 2: floor: 2, mass: 20000 -file 3: floor: 1, mass: 10000
* Number of porticos (edit text): 1
* Panel: Fv: 1.9 Fa: 1.3 Aa: 0.25 Av: 0.25 I = 1.
3) Click on the button -calculate-
I hope someone helps me find where the error may be, since it does not seem to be obvious at all. Thank you.
0 个评论
采纳的回答
Stephen23
2019-6-28
编辑:Stephen23
2019-6-28
"...since it does not seem to be obvious at all. "
On multiple lines of form2 you define a variable named diff, like this:
diff = maxLength - length (num2str (Sa_C{count1,count2}));
%^^^ do NOT name a variable DIFF, otherwise you cannot use the DIFF function!
This occurs on lines 371, 432, 503, 579. And then on line 604 you think that you are calling the function diff, but in fact you are just accessing one of those variables.
Change the names of those variables, to something that is not the name of a MATLAB function.
1 个评论
Guillaume
2019-6-28
Note that a big clue that this was the problem is the text of the error message:
X = diff(Num_nodos)~=0;
Index exceeds matrix dimensions.
The only thing that matlab can interpret as indexing on this line is diff(index) and thus matlab thinks that diff is a variable, not a function.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!