Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Reading Text File As Numbers

Asked by Alvi Syahrin on 11 May 2013

I'm working with MATLAB GUI.

So, I want users to browse their own table from their computer. When they have browsed, the full path will be written on the static text, and the table (that they browse) will be appeared.

The problem is, the file; it reads strings, not numbers.

So, how to read text file data as numbers and not string? What script do I have to write?

Thank you.

1 Comment

per isakson on 11 May 2013

Try

    doc textscan 
Alvi Syahrin

Products

No products are associated with this question.

1 Answer

Answer by Suman Saha on 7 Aug 2013

function SCORE2(action) if nargin<1 action='initialize'; end; if strcmp(action,'initialize') close all;clc; figNumber=figure('Name','S C O R E ','NumberTitle','off','Units','inches','Position',[1 0.5 9 7],'Resize','on','MenuBar','none'); colordef(figNumber,'black') xpos=5.6; ypos=4.6; xw=1.5; yw=0.2;

   %%%-------------------------------------------------
specstrC=sprintf('Made by Suman Saha\n MTech, ECE, KGEC\necesuman06@gamil.com\n Date: 02.08.2013');
specification=uicontrol('Style','text','Units','inches','Position',[7.44 0.02 1.5 0.95],'String',specstrC, ...
       'ForegroundColor',[1 1 1 ],'BackgroundColor',[0.2 0.2 0.2],'FontSize',8);
%%----Initialize button------%%
initialization=uicontrol('Style','push','FontName','Times new roman','FontWeight','bold',...
      'FontSize',12,'HorizontalAlignment','center','Units','inches','String','Initialize',...
      'BackgroundColor',[0.2071    0.6072    0.6299],'Callback','SCORE2(''initialize'')','Position',[xpos 0.6 1.4 0.3]);
%%----THE CLOSE BUTTON-----%
closee=uicontrol('Style','push','Units','inches','Position',[xpos 0.2 1.4 0.3],'String','C L O S E','FontName','monotype corsiva', ...
       'ForegroundColor','black','BackgroundColor','red','FontWeight','bold','FontSize',15,'Callback','close(gcf)');
pr=uicontrol('Style','push','Units','inches','Position',[xpos 1 1.4 0.3],'String','PRINT','Callback','printpreview',...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);
  %%%%%%%==============OPTION DISPLAY====================%%%%%%%%
  uicontrol('Style','Frame','Units','inches','Position',[0.24 0.31 1.12 6.2],'BackgroundColor','red');
   uicontrol('Style','Frame','Units','inches','Position',[0.3 0.38 1 6.1],'BackgroundColor',[0.02 0.02 0.2]);
  uicontrol('Style','edit','Tag','dq','Units','inches','Position',[0.3 0.41 1 6],'String',' ','FontName','times new roman','Max',2, ...
       'ForegroundColor','white','FontWeight','bold','FontSize',8,'BackgroundColor',[0.02 0.02 0.2],'HorizontalAlignment','center');   
    uicontrol('Style','Frame','Units','inches','Position',[2.49 0.31 1.12 6.2],'BackgroundColor','red');
    uicontrol('Style','Frame','Units','inches','Position',[2.55 0.38 1 6.1],'BackgroundColor',[0.12 0.02 0.1]);
  uicontrol('Style','edit','Tag','da','Units','inches','Position',[2.55 0.41 1 6],'String',' ','FontName','times new roman','Max',2, ...
       'ForegroundColor','white','FontWeight','bold','FontSize',8,'BackgroundColor',[0.12 0.02 0.1],'HorizontalAlignment','center');   
%==========================================================================
uicontrol('Style','text','Units','inches','Position',[xpos-5.5 ypos+2.15 1.5 0.2],'String','Load Actual Answers','FontName','times', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','FontSize',10,'BackgroundColor',[0.2 0.2 0.2],'HorizontalAlignment','center');   
   FF=uicontrol('Style','push','Tag','qus','FontName','monotype corsiva', ...
    'FontSize',14,'HorizontalAlignment','left', ...
    'Units','inches','String','Actual Answer','BackgroundColor',[0.5 0.7 0.5], ...
    'CallBack','SCORE2(''build'')','Position',[xpos-5.45 ypos+1.95 xw-0.2 yw]); 
uicontrol('Style','text','Units','inches','Position',[xpos-3.3 ypos+2.15 1.5 0.2],'String','Load Candidate''s Answers','FontName','times new roman', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','FontSize',10,'BackgroundColor',[0.2 0.2 0.2],'HorizontalAlignment','center');   
  FFa=uicontrol('Style','push','Tag','ans','FontName','monotype corsiva', ...
    'FontSize',14,'HorizontalAlignment','left', ...
    'Units','inches','String','Your Answer','BackgroundColor',[0.5 0.7 0.5], ...
    'CallBack','SCORE2(''build'')','Position',[xpos-3.2 ypos+1.95 xw-0.2 yw]); 
%============================================
uicontrol('Style','Frame','Units','inches','Position',[1.9 0.02 0.03 7],'BackgroundColor','Black');  
uicontrol('Style','Frame','Units','inches','Position',[4.2 0.02 0.03 7],'BackgroundColor','Black');
uicontrol('Style','Frame','Units','inches','Position',[0.02 0.02 0.03 7],'BackgroundColor','Black');  
uicontrol('Style','Frame','Units','inches','Position',[0.050 6.49 4.15 0.03],'BackgroundColor','black');
uicontrol('Style','Frame','Units','inches','Position',[8.95 0.02 0.03 7],'BackgroundColor','Black');
uicontrol('Style','Frame','Units','inches','Position',[0.05 6.96 8.91 0.03],'BackgroundColor','black');
uicontrol('Style','Frame','Units','inches','Position',[0.05 0.02 8.91 0.03],'BackgroundColor','black'); 
%==========================================================================
h1=uicontrol('Style','frame','Units','inches','Position',[xpos-1.36 ypos-0.2 4.7 2.1], ...
        'BackgroundColor',0.8*[0.5 0.8 0.04]);
h=uicontrol('Style','frame','Units','inches','Position',[xpos-1.31 ypos-0.15 4.6 2], ...
        'BackgroundColor',[0.50 0.750 0.050]);
uicontrol('Style','frame','Units','inches','Position',[xpos-1.26 ypos+0.05 4.5 1.6], ...
        'BackgroundColor',[0 0 0.3]);
scstr=sprintf('\nTotal Questions         Not Answered         Wrong Answers');
uicontrol('Style','text','Units','inches','Position',[4.4 5.6 4.4 0.7],'String',scstr, ...
       'ForegroundColor',0.9*[0 1 1],'BackgroundColor',[0 0 0.3],'FontSize',14,...
       'FontName','monotype corsiva','FontWeight','demi','HorizontalAlignment','center');
uicontrol('Style','text','Tag','tq','Units','inches','Position',[4.8 5.6 0.5 0.2],'String',' ', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','monotype corsiva','HorizontalAlignment','center','BackgroundColor',[0 0 0.3],'FontSize',14);
uicontrol('Style','text','Tag','na','Units','inches','Position',[6.3 5.6 0.5 0.2],'String',' ', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','monotype corsiva','HorizontalAlignment','center','BackgroundColor',[0 0 0.3],'FontSize',14);
uicontrol('Style','text','Tag','wr','Units','inches','Position',[7.7 5.6 0.5 0.2],'String',' ', ...
       'ForegroundColor',[1 0 0],'FontWeight','bold','Fontname','monotype corsiva','HorizontalAlignment','center','BackgroundColor',[0 0 0.3],'FontSize',14);
scstr=sprintf('Correct Answers                Score');
uicontrol('Style','text','Units','inches','Position',[4.4 4.6 4.4 0.7],'String',scstr, ...
       'ForegroundColor',[1 0 1],'BackgroundColor',[0 0 0.3],'FontSize',16,...
       'FontName','monotype corsiva','FontWeight','bold','HorizontalAlignment','center');
uicontrol('Style','text','Units','inches','Tag','cr','Position',[5.3 4.8 1 0.2],'String',' ', ...
       'ForegroundColor',[0 1 0],'FontWeight','bold','Fontname','monotype corsiva','HorizontalAlignment','center','BackgroundColor',[0 0 0.3],'FontSize',18);
uicontrol('Style','text','Units','inches','Tag','sc','Position',[7.3 4.8 1 0.2],'String',' ', ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','monotype corsiva','HorizontalAlignment','center','BackgroundColor',[0 0 0.3],'FontSize',18);
%==========================================================================
uicontrol('Style','text','Units','inches','Position',[4.4 6.6 2 0.2],'String','Penalty for Wrong Answers', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','monotype corsiva','HorizontalAlignment','center','BackgroundColor',[0.2 0.2 0.2],'FontSize',12);
wrqus=uicontrol('Style','edit','Units','inches','Tag','wq','Position',[6.4 6.6 0.5 0.2],'String','4','Max',1,'Callback','SCORE2(''build'')', ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','center','BackgroundColor',[0 0 0.3],'FontSize',10);
%==========================================================================  
uicontrol('Style','text','Units','inches','Position',[4.4 4 1.5 0.2],'String','Candidate''s Name  ', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','times','HorizontalAlignment','left','BackgroundColor',[0.2 0.2 0.2],'FontSize',12);
ca=uicontrol('Style','edit','Units','inches','Tag','ca','Position',[5.9 4 2.9 0.2],'String',' ','Max',1, ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);
uicontrol('Style','text','Units','inches','Position',[4.4 3.7 1.5 0.2],'String','Roll Number ', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','times','HorizontalAlignment','left','BackgroundColor',[0.2 0.2 0.2],'FontSize',12);
roll=uicontrol('Style','edit','Units','inches','Tag','rl','Position',[5.9 3.7 2.9 0.2],'String',' ','Max',1, ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);
uicontrol('Style','text','Units','inches','Position',[4.4 3.4 1.5 0.2],'String','Registration Number ', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','times','HorizontalAlignment','left','BackgroundColor',[0.2 0.2 0.2],'FontSize',12);
rg=uicontrol('Style','edit','Units','inches','Tag','rg','Position',[5.9 3.4 2.9 0.2],'String',' ','Max',1, ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);
uicontrol('Style','text','Units','inches','Position',[4.4 3.1 1.5 0.2],'String','Section Name ', ...
       'ForegroundColor',[1 1 1],'FontWeight','bold','Fontname','times','HorizontalAlignment','left','BackgroundColor',[0.2 0.2 0.2],'FontSize',12);
sb=uicontrol('Style','edit','Units','inches','Tag','sb','Position',[5.9 3.1 2.9 0.2],'String',' ','Max',1, ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);
%==========================================================================
photo=uicontrol('Style','push','Units','inches','Tag','photo','Position',[5.3 2.1 1 0.3],'String','Upload Photo','Callback','SCORE2(''build'')', ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);
sig=uicontrol('Style','push','Units','inches','Tag','sig','Position',[5.3 1.7 1 0.3],'String','Upload sig','Callback','SCORE2(''build'')', ...
       'ForegroundColor',[0 1 1],'FontWeight','bold','Fontname','palatino','HorizontalAlignment','left','BackgroundColor',[0 0 0.3],'FontSize',10);

%========================================================================== set(figNumber,'Visible','on'); %============================================ elseif strcmp(action,'build') if get(findobj(gcf,'Tag','photo'),'Value') axes('Units','inches','Position',[6.7 2.0 1 1],'Visible','on'); axis off; kl=photoup; image(cell2mat(struct2cell(kl))); axis off;clc end if get(findobj(gcf,'Tag','sig'),'Value') axes('Units','inches','Position',[6.6 1.8 1.2 0.2],'Visible','on'); axis off; kl=photoup; image(cell2mat(struct2cell(kl))); axis off; end if get(findobj(gcf,'Tag','qus'),'Value') z=qusser; set(findobj(gcf,'Tag','dq'),'String',upper(z)); elseif get(findobj(gcf,'Tag','ans'),'Value') set(findobj(gcf,'Tag','na'),'String',' '); set(findobj(gcf,'Tag','wr'),'String',' '); set(findobj(gcf,'Tag','cr'),'String',' '); set(findobj(gcf,'Tag','sc'),'String',' '); set(findobj(gcf,'Tag','ca'),'String',' '); set(findobj(gcf,'Tag','rl'),'String',' '); set(findobj(gcf,'Tag','rg'),'String',' '); axes('Units','inches','Position',[6.7 2.0 1 1],'Visible','on'); [im map]=imread('ph.bmp'); image(im);axis off; axes('Units','inches','Position',[6.6 1.8 1.2 0.2],'Visible','on'); [im map]=imread('sig.jpg'); image(im); axis off z11=qusser; set(findobj(gcf,'Tag','da'),'String',upper(z11)); end z=get(findobj(gcf,'Tag','dq'),'String'); z11=get(findobj(gcf,'Tag','da'),'String'); if ischar(z) msgbox( 'Please Load The Actual Answers') end if iscell(z11)&& iscell(z) na=length(z)-length(z11); if (na<0) errordlg(sprintf( ' Wrong Entry.\n\n Number of Candidate''s Answers are more than Actual Number of Questions.')); return end wrqus=get(findobj(gcf,'Tag','wq'),'String'); for i=1:min(length(z),length(z11)) x=upper(cell2mat(z(i))); x=x(find(isstrprop(x, 'alpha'))); x11=upper(cell2mat(z11(i))); x11=x11(find(isstrprop(x11, 'alpha'))); if isempty(x11) na=na+1; end res(i)=strcmp(x11,x); end totalqus=max(size(z,1),size(z11,1)); correct=sum(res); wrong=totalqus-na-correct; negativemark=fix(wrong/str2num(wrqus)); negativemark(wrqus=='0')=0; sc=correct-negativemark; else correct=0; totalqus=0; na=0; wrong=0;sc=0; end set(findobj(gcf,'Tag','tq'),'String',totalqus); set(findobj(gcf,'Tag','na'),'String',na); set(findobj(gcf,'Tag','wr'),'String',wrong); set(findobj(gcf,'Tag','cr'),'String',correct); set(findobj(gcf,'Tag','sc'),'String',sc); end

function z=qusser qus=uiimport('-file'); qus=struct2cell(qus); for i=1:size(qus{1,1},1); z{i}=qus{1,1}{i,1}; end function kl=photoup() kl=uiimport('-file');

1 Comment

Jan Simon on 7 Aug 2013

Posting such an unformatted pile of code is not useful. It is not readable and contains too many details without a relation to the original question.

In other words: The missing formatting of your code makes it impossible for me to check, if there is any relation to the question at all, which was: How to read a file as numbers, not as strings.

So please stop flooding the forum with large unrelated codes. Thanks.

Suman Saha

Contact us