I need help with sort out string from Excel File to Matlab
1 view (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Thomas Jensen
on 10 May 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 Comments
Thomas Jensen
on 11 May 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,
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!