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
    %readData = fscanf(tag); %initialize
    %writeData = uint16(500); % 0x01F4
    %fwrite(tag, writeData, 'uint16') %write data
    BOX = char(zeros(2,14)); 
    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     
    %      if(length(readData)>10) %if chip has been read
    %      ReadChips

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

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


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.

New contributor
Rambunctiouslad is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Rambunctiouslad is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.