Clear Filters
Clear Filters

Error with ismember in a loop for

2 views (last 30 days)
fede
fede on 11 Apr 2016
Answered: Jan on 11 Apr 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".

Answers (1)

Jan
Jan on 11 Apr 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.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!