I need help with sort out string from Excel File to Matlab
Afficher commentaires plus anciens
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);
Réponses (1)
Thomas Jensen
le 10 Mai 2021
0 votes
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 commentaires
To Tran Luan
le 11 Mai 2021
Modifié(e) : To Tran Luan
le 11 Mai 2021
Thomas Jensen
le 11 Mai 2021
Hi Tran, Could you be more specific? Is the error still being raised? If you want to have a non-empty value for the variable "destination", you need to assign a value inside the for statement. In the script you provided, destination is never assigned inside the for statement. Maybe the if statement is not right. Shouldn't it be "destination=Email;"? Best regards,
To Tran Luan
le 11 Mai 2021
Thomas Jensen
le 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,
Catégories
En savoir plus sur Data Import from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
