Why a code works differently in a command window and in a GUIDE?

3 ビュー (過去 30 日間)
Alexander
Alexander 2013 年 6 月 26 日
Hi!
I'm working with GUIDE and I have this error
Index exceeds matrix dimensions.
Error in ==> RAMAS>carga_cable_Callback at 211
r=r1.*(s./(1000.*VB(jj).*VB(jj)))
I get variables of two uitable that are in different GUIDE, s and VB are in a GUIDE and r1, VB and jj in another GUIDE. Besides I can export all variables to workspace, but when a I execute code from GUIDE occurs error. When I write the operation in command window, I have the result that I need.
I do not understand what happens, since in a m.file this operation should be written as (without a point before the first item):
s=10000
jj=[3;4]
r1=[0.003982; 0.01542]
x1=[0.008006; 0.0173]
VB=[138 13.8 13.8 13.8 4.16]
r=r1*(s./(1000.*VB(jj).*VB(jj)))
  2 件のコメント
Jan
Jan 2013 年 6 月 26 日
編集済み: Jan 2013 年 6 月 26 日
GUIDE is the tool to create GUIs, so I assume you mean "different GUIs".
What does this mean: "Without a point before the first item"? Which item do you mean and what is a "point"?
What is the size of VB([3;4])? Do you try to multiply two [2x1] vectors with each other? This would create another error message.
Alexander
Alexander 2013 年 6 月 27 日
編集済み: Alexander 2013 年 6 月 27 日
Sorry! I had a confusion between GUIDE and GUIs
What I mean is that if you look at the code that is on the top that is part of my gui, you will notice that there is a point after the variable r1 and is not in the code at the bottom as this code is not made in a gui.
It's strange because the code should work in both cases, so one is not done in gui. jj just equals 3, that information is incorrect.

サインインしてコメントする。

採用された回答

Jan
Jan 2013 年 6 月 26 日
編集済み: Jan 2013 年 6 月 26 日
  1. When I execute code from GUIDE occurs error
  2. When I write the operation in command window, I have the result that I need.
This unequivocally means, that either the code called from your GUI differs from the code typed into the command window, or the data differ. Due to the omnipresence of typos, I'm convinced, that such a problem causes the troubles. Please check the code again. Perhaps you've edited the code but did not save it before running?
  4 件のコメント
Alexander
Alexander 2013 年 6 月 28 日
Learned lesson between GUIDE and GUIs, I did case your recommendation, clearly guidata is the correct option to store and save data.
Thank you very much for you help!
Jan
Jan 2013 年 6 月 30 日
@Alexander: You are welcome. Of course you can imagine that I did not speak about the "omnipresence of typos" without proving this in my own code exhaustively before ;-)

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 6 月 26 日
Set a breakpoint on the "r=" line and see what jj is. Evidently jj is greater than 5. This link will help you: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
  1 件のコメント
Alexander
Alexander 2013 年 6 月 27 日
Thank you for your help! I'm working on it

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by