Effacer les filtres
Effacer les filtres

importing .txt file into matlab push button

1 vue (au cours des 30 derniers jours)
faiza
faiza le 18 Fév 2015
Commenté : faiza le 18 Fév 2015
I am new to matlab. I have a text file of size [66553*8].I am trying to import the file in Matlab gui using push button.But when I do that the size of the file changes to [532424*1].Why is it happening.
I have one push button ,one checkbox.I am trying to import the .txt file using push button and then plotting the data of txt file using my checkbox.This is my relevant code:
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)
[filename, pathname] = uigetfile({'*.txt'},'Open Directory');
if isequal(filename,0) || isequal(pathname,0)
return
end
fileID = fopen(fullfile(pathname, filename));
handles.fileData = fscanf(fileID,'%d');
guidata(hObject, handles);
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
handles.fileData
x=handles.fileData
xa = x(:,3)
plot(xa)

Réponse acceptée

Jos
Jos le 18 Fév 2015
Hi Faiza,
change
handles.fileData = fscanf(fileID,'%d');
to
temp = fscanf(fileID,'%d',[8 Inf]);
handles.fileData = temp';
That should work
  1 commentaire
faiza
faiza le 18 Fév 2015
It works.Thank-you Jos. Appreciate your help

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by