Return a value from a table
Mostrar comentarios más antiguos
Hello,
I have a table of annual quarters as row names and the dates those quarters began as a variable. I'm trying to create a command where given a quarter (R) I can lookup the quarter start date. I've read the documentation and searched for answers here, but am very lost so I'd appreciate any help!
Quarter = {'Q12019'; 'Q22019'; 'Q32019'; 'Q42019'; 'Q12020'; 'Q22020'; 'Q32020'; 'Q42020'};
QuarterStartDate = ['2019-01-01'; '2019-04-01'; '2019-07-01'; '2019-10-01'; '2020-01-01'; '2020-04-01'; '2020-07-01'; '2020-10-01'];
T = table(QuarterStartDate, 'RowNames', Quarter);
R = 'Q32019';
S = T(Quarter == 'R')
I was able to do something similar earlier that worked, but that was using numbers rather than characters. I tried doing the same thing, but that didn't work.
C = [ .80 ; .85 ; .90 ; .95];
P = [.55 ; .49 ; .44 ; .44];
T = table(C, P);
R = 0.95;
S = T{C == R, 2};
Thanks!
5 comentarios
dpb
el 29 de Nov. de 2019
Help us out by attaching a (smallish) section of the table as .mat file...
Ivan Glinski
el 29 de Nov. de 2019
Walter Roberson
el 30 de Nov. de 2019
S = T(strcmp(T.Quarter,'R').QuarterStartDate;
Ivan Glinski
el 30 de Nov. de 2019
Editada: Ivan Glinski
el 30 de Nov. de 2019
Image Analyst
el 30 de Nov. de 2019
Try T.QuarterStartDate instead of T.Quarter.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical 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!