Borrar filtros
Borrar filtros

how to read numeric data in text file and plot a graph in GUI ?

1 visualización (últimos 30 días)
ramesha
ramesha el 15 de Abr. de 2014
Editada: ramesha el 15 de Abr. de 2014
Dear user i have a matlab code and text file for the above question but it shows some error ,please help me.
matlab code is ....
function varargout = pt(varargin)
% PT MATLAB code for pt.fig
% PT, by itself, creates a new PT or raises the existing
% singleton*.
%
% H = PT returns the handle to a new PT or the handle to
% the existing singleton*.
%
% PT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PT.M with the given input arguments.
%
% PT('Property','Value',...) creates a new PT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pt_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pt_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help pt
% Last Modified by GUIDE v2.5 15-Apr-2014 10:50:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pt_OpeningFcn, ...
'gui_OutputFcn', @pt_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before pt is made visible.
function pt_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to pt (see VARARGIN)
% Choose default command line output for pt
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes pt wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pt_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function class_Callback(hObject, eventdata, handles)
% hObject handle to class (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of class as text
% str2double(get(hObject,'String')) returns contents of class as a double
class=get(hObject,'string')
% --- Executes during object creation, after setting all properties.
function class_CreateFcn(hObject, eventdata, handles)
% hObject handle to class (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');0
end
function trial_Callback(hObject, eventdata, handles)
% hObject handle to trial (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of trial as text
% str2double(get(hObject,'String')) returns contents of trial as a double
trial=get(hObject,'string')
% --- Executes during object creation, after setting all properties.
function trial_CreateFcn(hObject, eventdata, handles)
% hObject handle to trial (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
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)
axes(handles.axes1);
cla;
class= get(handles.class,'String')
trial= get(handles.trial,'String')
% class='001'
% trial='01'
filname=sprintf('%st%s.txt',class ,trial);
fid=fopen(filname)
s=textscan(fid,'%d %d %d','headerlines',25)
fclose(fid)
X=s{1}
Y=s{2}
z=s{3}
h=plot(X,-Y,'or','LineWidth',1);
%--------------------------------------------End-------------------------------------------------
Text file name= 005t01.txt. This file in gui class is 005 and trial is 01, It contains below contents.
.VERSION 1.0 1
.HIERARCHY CHARACTER
.COORD X Y T
.SEGMENT CHARACTER
.X_POINTS_PER_INCH 2500
.Y_POINTS_PER_INCH 2500
.POINTS_PER_SECOND 120
.WRITER_ID 1
.AGE 40
.SEX MALE
.HAND R
.SKILL Proficient
.STYLE NORMAL
.COUNTRY IN
.WRITER_INFO
WriterName:SHARANAPPA
WriterTrialNo:1
WriterProfession:FACCULTY
WritingSetup:X
WritingFrequency:Everyday
WritingInProfession:No
WritingFile:dcpath
.PEN_DOWN
3266 752 10266
3256 760 0
3256 760 0
3256 760 0
3256 760 0
3256 760 0
3256 760 0
3256 760 0
3256 760 0
3268 756 0
3268 756 0
3282 739 0
3290 729 0
3301 713 0
3311 696 0
3321 673 0
3328 649 0
3333 621 0
3334 593 0
3332 568 0
3325 542 0
3317 518 0
3303 501 0
3288 485 0
3271 479 0
3251 479 0
3227 488 0
3203 504 0
3176 529 0
3150 564 0
3120 603 0
3096 649 0
3071 700 0
3051 757 0
3036 816 0
3027 878 0
3024 942 0
3028 1005 0
3036 1067 0
3054 1124 0
3078 1178 0
3106 1225 0
3139 1265 0
3174 1296 0
3213 1317 0
3254 1327 0
3298 1329 0
3337 1320 0
3376 1304 0
3412 1278 0
3448 1245 0
3481 1206 0
3509 1162 0
3532 1112 0
3550 1061 0
3566 1010 0
3580 963 0
3590 917 0
3600 876 0
3609 842 0
3619 809 0
3631 783 0
3645 759 0
3661 740 0
3679 726 0
3699 714 0
3719 705 0
3741 703 0
3764 705 0
3787 711 0
3807 726 0
3827 745 0
3845 769 0
3861 799 0
3874 832 0
3888 869 0
3898 910 0
3905 953 0
3914 997 0
3924 1042 0
3934 1085 0
3946 1127 0
3963 1165 0
3981 1197 0
4005 1225 0
4034 1246 0
4067 1260 0
4105 1265 0
4146 1263 0
4189 1253 0
4231 1232 0
4270 1203 0
4308 1167 0
4337 1122 0
4365 1067 0
4385 1005 0
4397 935 0
4406 865 0
4412 795 0
4417 729 0
4419 668 0
4420 614 0
4422 570 0
4423 534 0
4423 513 0
4425 496 0
4426 485 0
4426 485 0
4426 485 0
4426 485 0
4426 485 0
4427 500 0
4423 513 0
4426 524 16844
.PEN_UP
%---------------------------------end------------------------
when execute above code shows Error like this
>> pt
class =
005
trial =
'01'
class =
005
trial =
'01'
Error using sprintf Function is not defined for 'cell' inputs.
Error in pt>pushbutton1_Callback (line 133) filname=sprintf('%st%s.txt',class ,trial);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in pt (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)pt('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by