How to import data into guide which uses a function I have created

Hello is there a way to import excel data into a simple GUIDE i have created? I understand workspace data can only be accessed on a script but not a function, hence is there a way to import data in a gui and then pass the data into a function i have created to use the data? Thanks!

 Réponse acceptée

KSSV
KSSV le 13 Mar 2018
1. The workspace can be accessed by a function, provided you input the variable name of the data as a input to the function.
2. You can input the name of excel file with path to your gui and then read the file inside the gui function.

3 commentaires

Thanks! I've tried the second method buy i received this error here.
Error in Sample3>popupmenu1_Callback (line 99)
raw.handles=raw;
And this is my code for the popupmenu
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
items = get(hObject,'String');
index_selected = get(hObject,'Value');
item_selected = items{index_selected};
display(item_selected);
handles.index_selected = index_selected;
raw = xlsread('EQTDatabase.xlsx','B6:C9')
raw.handles=raw;
guidata(hObject, handles)
Can i know whats the problem?
Why this line?
raw.handles=raw;
Excel file is read and data is loaded into variable raW already.
Oh i see ok i have deleted that line already. But the gui is still not using the 'raw' variable and i dont get why. I have written my function in the push button code below.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
storedvals = handles.storedvals;
index_selected = handles.index_selected;
print = 'None';
x = 0;
y = 0;
tableData = get(handles.uitable1, 'data');
storedvals(cellfun('isempty', storedvals)) = {0};
M=cell2mat(storedvals);
r=index_selected;
if M(1)~=0
t=1;
x=M(1);
p=1;
flag = eqtcompare3(r, t, p, x, y, raw);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by