Is it possible to construct the code below?

% --- Executes on button press in Calculate.
function Calculate_Callback(~, ~, handles)
% hObject handle to Calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ExPath1 = get(handles.Filename1, 'string');
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath1,'True',63,handles);
ExPath2 = get(handles.Filename2, 'string');
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath2,'True',63,handles)
ExPath3 = get(handles.Filename3, 'string');
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath3,'True',63,handles)
ExPath4 = get(handles.Filename4, 'string');
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath4,'True',63,handles)
ExPath5 = get(handles.Filename5, 'string');
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath5,'True',63,handles)
ExPath6 = get(handles.Filename6, 'string');
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath6,'True',63,handles)
I ask, because when i select various files and press calculate the matlab program does not work. However, when I select one file at a time; the program runs with no problem.

6 commentaires

Iain
Iain le 6 Juin 2013
What is the error you are getting, or what behaviour are you seeing that you should not be?
Error using xlsread (line 129)
XLSREAD unable to open file 'Filename'.
File 'Filename' not found.
Error in GUI2>correctionModelworking1 (line 313)
data = xlsread(file);
Error in GUI2>Calculate_Callback (line 103)
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(ExPath3,'True',63,handles)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in GUI2 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI2('Calculate_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Walter Roberson
Walter Roberson le 6 Juin 2013
Please read the guide to tags and retag this question; see <http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags?
Walter Roberson
Walter Roberson le 6 Juin 2013
When you "select various files", do you mean that you are using uigetfile() with multiselect mode for each of the 6 Filename handles you have, and the String property for each is therefore a cell array of strings?
If not, then how do you select one file at a time when your routine appears to need 6? Is it the case that in that situation the other Filename handles will have empty strings and your correctionModelworking1 routine will detect that and silently do nothing?
Iain
Iain le 6 Juin 2013
That error tells me that you are supplying an invalid filename.
Cordelle
Cordelle le 6 Juin 2013
I can do the calculation with 1 file and get results; i would like the user to be able to select 6 files and simultaneously get six different results with respect to the 6 files the user choose

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 6 Juin 2013
You did not answer my question about the mechanism for selecting multiple files, so I will make a guess that you use uigetfile() with Multiselect On and store the result in handles.Filename1 string property.
% --- Executes on button press in Calculate.
function Calculate_Callback(~, ~, handles)
% hObject handle to Calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
paths = cellstr(get(handles.Filename1, 'string'));
if length(paths) == 1
paths = get([handles.Filename1, handles.Filename2, handles.Filename3, handles.Filename4, handles.Filename5, handles.Filename6], 'string');
end
for K = 1 : length(paths)
[x, x_1, x_2, x_3, x_4, x_5] = correctionModelworking1(paths{K},'True',63,handles);
end

2 commentaires

Cordelle
Cordelle le 6 Juin 2013
I think my problem is that my calculate button will only work if i select all 6 files. I would like the calculate button to work for any number of files i choose to select. For example, say i wanted to just make on calculation I would like to do that without having to select 6 other files, so that i can see the one answer i desire.
Walter Roberson
Walter Roberson le 6 Juin 2013
What is the mechanism you use to select files? What steps would a user go through to select (for example) 2 files ? Are there any particular steps the user would have to go through to indicate that the other 4 are not to be used?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Entering Commands 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