Borrar filtros
Borrar filtros

Error with ismember in a loop for

2 visualizaciones (últimos 30 días)
fede
fede el 11 de Abr. de 2016
Respondida: Jan el 11 de Abr. de 2016
tickers='tickers.txt';
price=hist_stock_data('09032015','09032016',tickers);
prices=zeros(size(price(1, 1).AdjClose,1),size(price,2));
for t=1:size(price,2);
prices(:,t)= price(1, t).AdjClose;
end
for t=1:size(price,2);
nomes{1,t}=price(1, t).Ticker;
end
couple=[nomes(myrow)',nomes(mycol)'];
cl=num2cell(prices);
ff=[nomes;cl];
for ii=1:size(couple,1);
looking_up=couple(ii,:);
[tf, coldix]=ismember(looking_up,ff(ii,:));
prices=ff(:,coldix(tf));
prices=prices(2:end,:);
prices=cell2mat(prices);
x(ii)=prices(:,2);
y(ii)=prices(:,1);
end
give me the following error: "Input A of class cell and input B of class cell must be cell arrays of strings, unless one is a string".

Respuestas (1)

Jan
Jan el 11 de Abr. de 2016
As the error message tells you, ismember operates on cells only, if they are cell strings. In your care the data are not cell strings. You can find out, what they are instead:
dbstop if all error
Then runs the code again. When Matlab stops at the error, type this in the command window:
class(looking_up)
class(looking_up{1})
class(ff)
class(ff{1})
Due to the absence of comments, we cannot guess what you want to achieve.

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!

Translated by