importfile from a gui

1 visualizzazione (ultimi 30 giorni)
Andrea Gil
Andrea Gil il 18 Lug 2011
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

Risposte (2)

Fangjun Jiang
Fangjun Jiang il 19 Lug 2011
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.

Walter Roberson
Walter Roberson il 19 Lug 2011
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()

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by