[ pre script error control from excel sheet]
Mostrar comentarios más antiguos
Hi,
I'm struggling with a problem, here's the context, the problem and the way we are investingating.
Context : We are working in a research center and we are analyzing data obtained thru scans (comparison between dimensionnal sensors like interferometers and optics rules). as we are dealing with hundread of scans and thousands of data, we have created some scripts to make an automated treatment. in order to simplify the tracking of the data, the progress and so on, we are using an excel sheet (see attached) that compiles : the variables, comments on progress, dates etc...
before starting the script, we want to check if the variables in he excel sheet have the good format. (integer, text etc...)
We are using Matlab R2019b and we have access to any work package if necessary.
problem:
when you read the excel sheet in matlab, everything is text. if you use something like string2num to transform a text in number, if there is an error, the script stop and send you a message not very clear about the exact place of the error.
example: we have the line : " Ns 51:53" .
Ns is an abreviation for "Numero scan" (scan number) 51:53 means that we have 3 full scan numeroted from 51 to 53.
we use the function to separate the « Ns », « 51 » and « 53 ». in this case if I use string2num, everything will be fine but if instead of « 53 » I have « 5b » (mistake made by the operator when filling the excell form), the string2num will not work and the script will stop.
Investigations :
I tried with « assert » and « isa » function that is interesting and can open a dialog box with the exact error but before being able to use the « assert » or « isa » function are controling the the data is a certain type and before controling the type, i must convert the text data from excell in ... number.
Another investigation : converting the data by using the ascii code characters.
Like this :
mystring='51:53'
L=length(mystring)
parity = mod(L,2)
separ = (L+parity)/2
Ascii = double(mystring)
Ascii(separ)=48 % the ':' is converted into any numerical ascii character
ifand(Ascii<58,Ascii>47) % test all ascii values. If it’s numerical , it’s comprised between 48 and.
"Ok!"
else
"Erreur!"
I'm sure there is a better way to proceed but I can't find it.
Any help will be appreciated :)
Best regards,
Cédric
Respuestas (0)
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!