Azzera filtri
Azzera filtri

importing .txt file into matlab push button

1 visualizzazione (ultimi 30 giorni)
faiza
faiza il 18 Feb 2015
Commentato: faiza il 18 Feb 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)

Risposta accettata

Jos
Jos il 18 Feb 2015
Hi Faiza,
change
handles.fileData = fscanf(fileID,'%d');
to
temp = fscanf(fileID,'%d',[8 Inf]);
handles.fileData = temp';
That should work

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks 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