importfile from a gui
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi! I have a question about Matlab GUI, and I would appreciate it if someone could help me.
I am trying to do the same thing with GUI and without GUI (in a normal m-file) and the result is different. I am exporting data from an excel sheet by means of the tool importfile, that lets me include the vectors from the excel sheet in my workspace so that I can later work with them.
Then, the program asks for the point (the element of the vector) to be used for the calculation (for GUI by means of get and without GUI by means of an input dialog). Whereas I have no problem for the calculation without GUI, I get a mistake by the GUI calculation when the program looks for the element of the vector:
I get vector i and then:
importfile file.xls
Element=Vector1(i)
And I become the mistake : "Undefined function or method 'Vector1' for input arguments of type 'double'"
Any idea?
Thanks!
Andrea
댓글 수: 0
답변 (2개)
Fangjun Jiang
2011년 7월 19일
The error message says it all. Where is your variable "Vector1"? Put a break point at line "Element=Vector1(i)". Check the value of "Vector1" and "i".
Maybe your importfile function is generated from using uiimport. Since it doesn't have return argument, variable "Vector1" is created in the base workspace. That may be the reason that you can do it without GUI but you had error when calling it in your GUI function callback. Below is an excerpt from the document.
If you do not import into a structure array, the generated function creates variables in the base workspace. If you plan to call the generated function from within your own function, your function cannot access these variables. To allow your function to access the data, start the Import Wizard by calling uiimport with an output argument. Call the generated function with an output argument to create a structure array in the workspace of your function.
댓글 수: 0
Walter Roberson
2011년 7월 19일
Is Vector1 somehow defined in your file.xls ? If so then it is being "poofed" in to the workspace of the function, and the JIT has determined ahead of time that it is an external function instead of a variable.
You should consult the documentation for the (third party) importfile() function to see if there is a way to get importfile() to return a structure that you then access the fields of (like load() works). Otherwise, you should initialize Vector1 (to any value) before you do the importfile()
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!