I need help with sort out string from Excel File to Matlab

1 Ansicht (letzte 30 Tage)
To Tran Luan
To Tran Luan am 10 Mai 2021
Kommentiert: Thomas Jensen am 11 Mai 2021
This is the Excel part that i imported to Matlab
UserData =
4×2 cell array
{'30E92115' } {'abc123@gmail.com''}
{'HR26DK83OO'} {'xyz123@gmail.com'' }
{'29E492114' } {'yeetyeet@gmail.com'' }
{'30E591255' } {'travisscott@gmail.com'' }
My Main Code
PlateNumber ='30E92115';
[~,UserData] = xlsread('userdata.xlsx','A:B');
Plate = UserData(:,1);
Email = UserData(:,2);
noPlate = numel(Plate);
for i = 1:noPlate
compare = strcmpi(Plate,PlateNumber);
if compare == 1
Email = destination;
end
end
disp(destination);
So the idea is if the strcmpi() is true, when the PlateNumber value is equal to the email follow by the '30E92115' string in the imported Excel file, the "destination" will receive the email come along with the '30E92115' , but somehow I got this error, PLEASE HELP
Unrecognized function or variable 'destination'.
Error in compare (line 13)
disp(destination);

Antworten (1)

Thomas Jensen
Thomas Jensen am 10 Mai 2021
Hi Tran,
The script is not assigning any value to the variable "destination". That is why the line "Email = destination;" and the line "disp(destination);" can be executed.
As a good practice, always assign a value to the variables set inside a loop or if statement. For example, add a new line before " for i = 1:noPlate" with the content "destination = [];".
Best regards,
  4 Kommentare
To Tran Luan
To Tran Luan am 11 Mai 2021
I tried as your recommendation but the value of destination is still give out as emty
although the value of comp is 1 ,so the value of the second cell suppose to be equal to destination (the red markered email)
Thomas Jensen
Thomas Jensen am 11 Mai 2021
Hi Tran,
Thanks for sending the screenshots.
I did some updates on your script and I think now it is working as you described.
PlateNumber ='30E92115';
[~,UserData] = xlsread('userdata.xlsx','A:B');
Plate = UserData(:,1);
Email = UserData(:,2);
noPlate = numel(Plate);
destination = [];
for i = 1:noPlate
compare = strcmpi(Plate{i},PlateNumber);
if compare == 1
destination = Email{i};
end
end
if isempty(destination)
disp('Email not found.');
else
disp(destination);
end
Best regards,

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by