path Leo
path Leo

Reputation: 3

sort out string from Excel File to Matlab

enter image description here

PlateNumber ='30E92115';
[~,UserData] = xlsread('userdata.xlsx','A:B');
Plate = UserData(:,1);
Email = UserData(:,2);
noPlate = numel(Plate);
    for i = 1:noPlate
        destination=[];
        comp = strcmp(Plate,PlateNumber);
        comp = double(comp);
        if  comp == 1
            Email = destination;
        end
    end
disp(destination);

Are there anyway that i can assign the output of Email to the Destination , somehow the comp value show is 1 at the red markered email but the string cannot be attach to the Destination variable

Upvotes: 0

Views: 59

Answers (1)

Ben S
Ben S

Reputation: 168

It is not quite clear what you want to achieve. Do you want "destination" to be the corresponding Email to your Plate? Then try this:

Plate       = UserData(:,1);
Email       = UserData(:,2);
comp        = strcmp(Plate,PlateNumber);
destination = Email{comp};

You should however use the opportunity and read a bit about how these functions work. "strcmp" gives you a logical vector with a one at every position, where the entry of the cell was exactly the same as the char that you where looking for. Therefor you can simply use the output of strcmp to access the correspnding cell entries (in this case, only the first one).

Upvotes: 1

Related Questions