How would I go about separating each of the numerical values from this string, and create a named variable from each?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Afternoon,
How would I go about separating each of the numerical values from this string, and create a named variable from each?
Current effort is below:
Str = 'Average 0: ASM=5, DEP=34m, AV=652632.44';
Str(strfind(Str, '=')) = [];
Key1 = 'AMS';
Key2 = 'DEP';
Key3 = 'AV';
Index = strfind(Str, Key1);
Value = sscanf(Str(Index(1) + length(Key1):end), '%g', 1);
Error message when run:
Index exceeds matrix dimensions.
Error in glider_transmitted_data (line 33)
Value = sscanf(Str(Index(1) + length(Key1):end), '%g', 1);
Many thanks,
Alex
0 comentarios
Respuestas (1)
Roger
el 6 de Abr. de 2015
Editada: Roger
el 7 de Abr. de 2015
Str = 'Average 0: ASM=5, DEP=34m, AV=652632.44';
rcell=strsplit(Str,':');s2=rcell{2};rcell2=strsplit(s2,',');
Average0=str2num(rcell{1}(end-1:end));
r3=strsplit(rcell2{1},'=');
ASM=str2num(r3{2});
DEP=strsplit(rcell2{2},'=');
AV=str2num(strsplit(rcell2{3},'='));
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!