I need help with sort out string from Excel File to Matlab
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Thomas Jensen
il 10 Mag 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 Commenti
Thomas Jensen
il 11 Mag 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,
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!