How to compare these two strings?

Hi everyone
I am trying to compare two strings but I am getting an error. I am new to Matlab so most likley I made a rookie error. Is someone able to help me?
I have an array of symbols and an array of data. The symbol list is called UnderlyingSymbols and data array is called CIV. I need to filter CIV based on a symbol because I am going to be using this as part of a for loop. For each symbol in UnderlyingSymbols, find the corresponding records in CIV. Both CIV and UnderlyingSymbols has a field called Symbol. I am not sure how to fix the error I am getting. How do I fix it?
Code:
% LOAD TABLES FROM SQL SERVER
CIV = sqlread(ConnectionString,'CompositeImpliedVolatility');
% CREATE ARRAY OF SYMBOLS
UnderlyingSymbols = unique(CIV(:,1));
FilteredCIV = CIV(CIV.SYMBOL == UnderlyingSymbols(1,1),:);
Error:
Error using ==
This operation is not defined between 'table' and 'cell'. The input that is not a table or timetable must
be a numeric or logical array.
Error in ForecastModel (line 51)
FilteredCIV = CIV(CIV.SYMBOL == UnderlyingSymbols(1,1),:);
Output from UnderlyingSymbols:
SYMBOL
_______
{'SPX'}
Output from CIV:
SYMBOL TRADE_DATE
_______ ___________
{'SPX'} 03-Jun-2014
{'SPX'} 11-Jun-2014
Thank you

2 comentarios

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 18 de Feb. de 2024
Pl, share ConnectionString data. So community people can simulate your exercise.
Image Analyst
Image Analyst el 18 de Feb. de 2024
Can you attach CIV in a .mat file so we can try the rest of your code, that is ONLY if the code by @VBBV (below) didn't work?

Iniciar sesión para comentar.

 Respuesta aceptada

VBBV
VBBV el 18 de Feb. de 2024
Editada: VBBV el 18 de Feb. de 2024
try using strcmp function
FilteredCIV = CIV(strcmp(CIV.SYMBOL,UnderlyingSymbols.SYMBOL(1)),:); % try using strcmp

3 comentarios

VBBV
VBBV el 18 de Feb. de 2024
Editada: VBBV el 18 de Feb. de 2024
SYMBOL = {'SPX','SPX','SPY'}.';
TRADE_DATE = {' 03-Jun-2014','11-Jun-2014','14-Jun-2014'}.'
TRADE_DATE = 3x1 cell array
{' 03-Jun-2014'} {'11-Jun-2014' } {'14-Jun-2014' }
CIV = table(SYMBOL,TRADE_DATE)
CIV = 3x2 table
SYMBOL TRADE_DATE _______ ________________ {'SPX'} {' 03-Jun-2014'} {'SPX'} {'11-Jun-2014' } {'SPY'} {'14-Jun-2014' }
UnderlyingSymbols = table(SYMBOL)
UnderlyingSymbols = 3x1 table
SYMBOL _______ {'SPX'} {'SPX'} {'SPY'}
FilteredCIV = CIV(strcmp(CIV.SYMBOL,UnderlyingSymbols.SYMBOL(1)),:) % try using strcmp
FilteredCIV = 2x2 table
SYMBOL TRADE_DATE _______ ________________ {'SPX'} {' 03-Jun-2014'} {'SPX'} {'11-Jun-2014' }
VBBV
VBBV el 18 de Feb. de 2024
If there is a field in UnderlyingSymbols then acceess the field content using its name
Manny
Manny el 19 de Feb. de 2024
thank you so much. the strcmp works!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Types en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Feb. de 2024

Comentada:

el 19 de Feb. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by