learning how to use MATLAB App designer, integrating existing code into GUI

by Rambunctiouslad   Last Updated September 11, 2019 18:01 PM

I found a MATLAB script online, and played with it a bit until I got it to do what I needed it to. Essentially, I have an alphanumeric tag stored in an excel file, and the MATLAB code compares the stored tag to an RFID tag coming on over serial. I am using MATLAB r2017a. there is some random comments in the code, generally that stuff was either prototyping or holdovers from the existing code I wasn't sure I needed.

this is the script:

    delete(instrfind('Port', 'COM3')); 
    tag = serial('COM3'); %check which port is used
    fopen(tag);
    %readData = fscanf(tag); %initialize
    %writeData = uint16(500); % 0x01F4
    %fwrite(tag, writeData, 'uint16') %write data
    BOX = char(zeros(2,14)); 
    i=1;
    c=0;
    TrueValueData = 'C:Location_of_Stored_Tags.xlsx';
    [~,~,TrueValMat] = xlsread(TrueValueData); % Creates matrix filled with the correct values, 
                                               % indexed by box, which is the first row
                                               % all proceeding rows are the master values
    for i=1:9223372036854775807
        if i>10 %first couple reads are filled with unicode nonsense, this skips that stage

         readData = fscanf(tag);
        if length(readData)>12

           BOX(str2num(readData(8)),1:14)= readData(11:24); % these numbers just give us what we want; 
                                                       % tags come in initially with some gobbledy-gook     
        end
    %     
    %      if(length(readData)>10) %if chip has been read
    %          
    %      ReadChips


              if strcmp(TrueValMat{2,1}, BOX(1,:))
                 disp('hurray1')%set(handles.uipanel3, 'Backgroundcolor', 'g');
              else 
                 disp('not hurray1') %set(handles.uipanel3, 'Backgroundcolor', 'r');
              end

                if strcmp(TrueValMat{2,2}, BOX(2,:))
                 disp('hurray2') %set(handles.uipanel2, 'Backgroundcolor', 'g');
                else 
                 disp('not hurray2') %set(handles.uipanel2, 'Backgroundcolor', 'r');
                end
        end

    end
    fclose(tag);
    delete(tag);

I have an arduino code running that sends the script from an RFID reader to the serial port. Parts of the incoming tag that I don't want are cut off, and then compared. In this existing code, when th ecorrect tag is read, 'hurray1' or 'hurray2' is output into the command window. This code works perfectly. I cleaned it up with some help from the people in MATLAB central, But I got a bit lost after the simple stuff. I am very new to MATLAB, so I don't always understand the more technical stuff.

Anyway, I want to use this script in a GUI. Instead of having hurray output into the command window, I want my GUI to display a button that goes red with the incorrect tag, and green with the correct one. those 2 yellow rectangles are button elements, which I'm pretty sure is the wrong ui component to use. To this end, I attempted to build the GUI in app designer, and got nowhere. Any help in with this goal will be much appreciated.

Tags : gui matlab


Related Questions


Updated February 21, 2017 07:01 AM

Updated March 25, 2017 04:01 AM

Updated May 21, 2015 00:00 AM

Updated May 24, 2015 22:00 PM

Updated April 04, 2017 15:01 PM